Author: mareshkau
Date: 2008-02-07 05:01:36 -0500 (Thu, 07 Feb 2008)
New Revision: 6146
Modified:
trunk/common/plugins/org.jboss.tools.common.kb/src/org/jboss/tools/common/kb/KbConnectorFactory.java
Log:
http://jira.jboss.com/jira/browse/JBIDE-1105
Modified:
trunk/common/plugins/org.jboss.tools.common.kb/src/org/jboss/tools/common/kb/KbConnectorFactory.java
===================================================================
---
trunk/common/plugins/org.jboss.tools.common.kb/src/org/jboss/tools/common/kb/KbConnectorFactory.java 2008-02-07
09:59:22 UTC (rev 6145)
+++
trunk/common/plugins/org.jboss.tools.common.kb/src/org/jboss/tools/common/kb/KbConnectorFactory.java 2008-02-07
10:01:36 UTC (rev 6146)
@@ -1,108 +1,114 @@
-/*******************************************************************************
- * Copyright (c) 2007 Exadel, Inc. and Red Hat, Inc.
- * Distributed under license by Red Hat, Inc. All rights reserved.
- * This program is made available under the terms of the
- * Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at
http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Exadel, Inc. and Red Hat, Inc. - initial API and implementation
- ******************************************************************************/
-package org.jboss.tools.common.kb;
-
-import java.util.HashMap;
-
-/**
- * @author eskimo
- */
-public class KbConnectorFactory {
-
- private HashMap<Object,Object> connectorInstances;
-
- private KbConnectorFactory() {
- connectorInstances = new HashMap<Object,Object>();
- }
-
- /**
- *
- * @param type
- * @return
- * @throws ClassNotFoundException
- * @throws InstantiationException
- * @throws IllegalAccessException
- */
- public KbConnector createConnector(KbConnectorType type) throws ClassNotFoundException,
InstantiationException, IllegalAccessException{
- if(type.isSingleton()) {
- Object o = connectorInstances.get(type.toString());
- if(o!=null) {
- return (KbConnector)o;
- }
- }
- Object newInstance = type.getConnectorClass().newInstance();
- connectorInstances.put(type.toString(), newInstance);
- return (KbConnector) newInstance;
- }
-
- /**
- *
- * @param type
- * @param loader
- * @return
- * @throws InstantiationException
- * @throws IllegalAccessException
- * @throws ClassNotFoundException
- */
- public KbConnector createConnector(KbConnectorType type, ClassLoader loader) throws
InstantiationException, IllegalAccessException, ClassNotFoundException {
- if(type.isSingleton()) {
- Object o = connectorInstances.get(type.toString());
- if(o!=null) {
- return (KbConnector)o;
- }
- }
- String className = type.getConnectorClass().getName();
- Class classInstance = Class.forName(className,true,loader);
- Object newInstance = classInstance.newInstance();
- connectorInstances.put(type.toString(), newInstance);
- return (KbConnector) newInstance;
- }
-
- /**
- *
- * @param type
- * @param key
- * @return
- * @throws InstantiationException
- * @throws IllegalAccessException
- * @throws ClassNotFoundException
- */
- public KbConnector createConnector(KbConnectorType type, Object key) throws
InstantiationException, IllegalAccessException, ClassNotFoundException {
- Object realKey = key;
- if(type.isSingleton()) {
- Object o = connectorInstances.get(type.toString());
- if(o!=null) {
- return (KbConnector)o;
- } else {
- realKey = type.toString();
- }
- }
- Object o = connectorInstances.get(realKey);
- if(o!=null) {
- return (KbConnector)o;
- }
- Object newInstance = type.getConnectorClass().newInstance();
- connectorInstances.put(realKey, newInstance);
- return (KbConnector) newInstance;
- }
-
- /**
- *
- * @return
- */
- static public KbConnectorFactory getIntstance() {
- return KbConnectionFactoryHolder.INSTANCE;
- }
-
- static class KbConnectionFactoryHolder {
- static final KbConnectorFactory INSTANCE = new KbConnectorFactory();
- }
+/*******************************************************************************
+ * Copyright (c) 2007 Exadel, Inc. and Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at
http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Exadel, Inc. and Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.common.kb;
+
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * @author eskimo
+ */
+public class KbConnectorFactory {
+
+ private Map<Object,Object> connectorInstances;
+
+ private KbConnectorFactory() {
+ connectorInstances = new HashMap<Object,Object>();
+ }
+
+ /**
+ *
+ * @param type
+ * @return
+ * @throws ClassNotFoundException
+ * @throws InstantiationException
+ * @throws IllegalAccessException
+ */
+ public KbConnector createConnector(KbConnectorType type) throws ClassNotFoundException,
InstantiationException, IllegalAccessException{
+ if(type.isSingleton()) {
+ Object o = connectorInstances.get(type.toString());
+ if(o!=null) {
+ return (KbConnector)o;
+ }
+ }
+ Object newInstance = type.getConnectorClass().newInstance();
+ connectorInstances.put(type.toString(), newInstance);
+ return (KbConnector) newInstance;
+ }
+
+ /**
+ *
+ * @param type
+ * @param loader
+ * @return
+ * @throws InstantiationException
+ * @throws IllegalAccessException
+ * @throws ClassNotFoundException
+ */
+ public KbConnector createConnector(KbConnectorType type, ClassLoader loader) throws
InstantiationException, IllegalAccessException, ClassNotFoundException {
+ if(type.isSingleton()) {
+ Object o = connectorInstances.get(type.toString());
+ if(o!=null) {
+ return (KbConnector)o;
+ }
+ }
+ String className = type.getConnectorClass().getName();
+ Class classInstance = Class.forName(className,true,loader);
+ Object newInstance = classInstance.newInstance();
+ connectorInstances.put(type.toString(), newInstance);
+ return (KbConnector) newInstance;
+ }
+
+ /**
+ *
+ * @param type
+ * @param key
+ * @return
+ * @throws InstantiationException
+ * @throws IllegalAccessException
+ * @throws ClassNotFoundException
+ */
+ public KbConnector createConnector(KbConnectorType type, Object key) throws
InstantiationException, IllegalAccessException, ClassNotFoundException {
+ Object realKey = key;
+ if(type.isSingleton()) {
+ Object o = connectorInstances.get(type.toString());
+ if(o!=null) {
+ return (KbConnector)o;
+ } else {
+ realKey = type.toString();
+ }
+ }
+ Object o = connectorInstances.get(realKey);
+ if(o!=null) {
+ return (KbConnector)o;
+ }
+ Object newInstance = type.getConnectorClass().newInstance();
+ connectorInstances.put(realKey, newInstance);
+ return (KbConnector) newInstance;
+ }
+
+ public void removeConnector(KbConnectorType type, Object key) {
+ Object o = connectorInstances.get(key);
+ if (o != null)
+ connectorInstances.remove(key);
+ }
+ /**
+ *
+ * @return
+ */
+ static public KbConnectorFactory getIntstance() {
+ return KbConnectionFactoryHolder.INSTANCE;
+ }
+
+ static class KbConnectionFactoryHolder {
+ static final KbConnectorFactory INSTANCE = new KbConnectorFactory();
+ }
}
\ No newline at end of file