1 19 20 package org.netbeans.modules.j2ee.oc4j; 21 22 import javax.enterprise.deploy.shared.factories.DeploymentFactoryManager ; 23 import javax.enterprise.deploy.spi.DeploymentManager ; 24 import javax.enterprise.deploy.spi.exceptions.DeploymentManagerCreationException ; 25 import javax.enterprise.deploy.spi.factories.DeploymentFactory ; 26 import org.openide.util.NbBundle; 27 import java.util.HashMap ; 28 import org.netbeans.modules.j2ee.deployment.plugins.api.InstanceProperties; 29 import org.netbeans.modules.j2ee.oc4j.util.OC4JDebug; 30 import org.netbeans.modules.j2ee.oc4j.util.OC4JPluginProperties; 31 import org.openide.ErrorManager; 32 import org.openide.util.NbPreferences; 33 34 38 public class OC4JDeploymentFactory implements DeploymentFactory { 39 40 43 public static final String URI_PREFIX = "deployer:oc4j"; 45 48 public static final String PROP_SERVER_ROOT = "oc4j_server_root"; 50 private static OC4JDeploymentFactory instance; 51 52 private HashMap <String , DeploymentFactory > factories = new HashMap <String , DeploymentFactory >(); 53 private HashMap <String , DeploymentManager > managers = new HashMap <String , DeploymentManager >(); 54 55 60 public static synchronized DeploymentFactory getDefault() { 61 if (instance == null) 62 instance = new OC4JDeploymentFactory(); 63 64 return instance; 65 } 66 67 72 public boolean handlesURI(String uri) { 73 return uri != null && uri.startsWith(URI_PREFIX); 74 } 75 76 84 public DeploymentManager getDeploymentManager(String uri, String uname, String passwd) throws DeploymentManagerCreationException { 85 if (!handlesURI(uri)) 86 throw new DeploymentManagerCreationException ("Invalid URI:" + uri); 88 DeploymentManager manager = managers.get(uri); 89 90 if (null == manager) { 91 manager = new OC4JDeploymentManager(uri); 92 managers.put(uri, manager); 93 } 94 95 return manager; 96 } 97 98 104 public DeploymentManager getDisconnectedDeploymentManager(String uri) throws DeploymentManagerCreationException { 105 return getDeploymentManager(uri, null, null); 106 } 107 108 public DeploymentFactory getOC4JDeploymentFactory(String uri) { 109 if (OC4JDebug.isEnabled()) 110 System.out.println("loadDeploymentFactory"); 111 112 DeploymentFactory factory = factories.get(uri); 113 114 if (null == factory) { 115 InstanceProperties ip = InstanceProperties.getInstanceProperties(uri); 116 117 String serverRoot = null; 118 119 if (null != ip) 120 serverRoot = ip.getProperty(OC4JPluginProperties.PROPERTY_OC4J_HOME); 121 122 if (null == serverRoot) 123 serverRoot = NbPreferences.forModule(OC4JDeploymentFactory.class).get(PROP_SERVER_ROOT, ""); 124 125 if (OC4JDebug.isEnabled()) 126 System.out.println("loadDeplomentFactory: serverRoot=" + serverRoot); 127 128 OC4JClassLoader.getInstance(serverRoot).updateLoader(); 129 130 try { 131 factory = (DeploymentFactory ) OC4JClassLoader.getInstance(serverRoot).loadClass( 132 "oracle.oc4j.admin.deploy.spi.factories.Oc4jDeploymentFactory"). newInstance(); 134 } catch (ClassNotFoundException e) { 135 ErrorManager.getDefault().notify(ErrorManager.ERROR, e); 136 } catch (InstantiationException e) { 137 ErrorManager.getDefault().notify(ErrorManager.ERROR, e); 138 } catch (IllegalAccessException e) { 139 ErrorManager.getDefault().notify(ErrorManager.ERROR, e); 140 } finally { 141 OC4JClassLoader.getInstance(serverRoot).restoreLoader(); 142 } 143 144 factories.put(uri, factory); 145 } 146 147 return factory; 148 } 149 150 154 public String getProductVersion() { 155 return "0.2"; } 157 158 162 public String getDisplayName() { 163 return NbBundle.getMessage(OC4JDeploymentFactory.class, "TXT_DisplayName"); } 165 } | Popular Tags |