1 19 20 package org.netbeans.modules.j2ee.sun.ide.dm; 21 22 import java.io.File ; 23 import java.util.HashMap ; 24 import java.util.Map ; 25 import java.util.ResourceBundle ; 26 27 import javax.enterprise.deploy.spi.DeploymentManager ; 28 import javax.enterprise.deploy.spi.factories.DeploymentFactory ; 29 import javax.enterprise.deploy.spi.exceptions.DeploymentManagerCreationException ; 30 import org.netbeans.modules.j2ee.deployment.devmodules.api.Deployment; 31 import org.netbeans.modules.j2ee.deployment.devmodules.spi.InstanceListener; 32 import org.netbeans.modules.j2ee.deployment.plugins.api.InstanceProperties; 33 34 import org.netbeans.modules.j2ee.sun.api.ServerLocationManager; 35 import org.netbeans.modules.j2ee.sun.api.SunURIManager; 36 37 41 public class SunDeploymentFactory implements Constants, DeploymentFactory , InstanceListener { 42 43 48 private static final String DEFAULTSERVERDEF="[ ]deployer:Sun:AppServer::localhost:4849"; 50 private DeploymentFactory innerDF = null; 54 55 56 58 protected static final ResourceBundle bundle = ResourceBundle.getBundle( 59 "org.netbeans.modules.j2ee.sun.ide.dm.Bundle"); 61 private boolean instanceListenerAdded; 62 63 public SunDeploymentFactory() { 64 instanceListenerAdded = false; 65 } 66 67 static final private Map <String ,DeploymentManager > dms = new HashMap <String ,DeploymentManager >(); 68 69 77 public DeploymentManager getDeploymentManager(String uri, String userName,String password) throws DeploymentManagerCreationException { 78 registerInstanceListener(); 79 80 try { 81 if (DEFAULTSERVERDEF.equals(uri)){ 82 String defaultURI = null; String ServerUrls[] = InstanceProperties.getInstanceList(); 84 for (String elem : ServerUrls) { 85 if(handlesURI(elem)){ 86 if (defaultURI == null){ 87 defaultURI = elem; } 89 File serverLocation = getServerLocationFromURI(elem); 90 if (ServerLocationManager.isGlassFish(serverLocation)){ 91 defaultURI = elem; break; 93 } 94 } 95 } 96 if (defaultURI != null){ 97 uri = defaultURI; 98 } 99 } 100 innerDF = ServerLocationManager.getDeploymentFactory(getServerLocationFromURI(uri)); 101 if (innerDF==null){ 102 throw new DeploymentManagerCreationException (getRealURI(uri)+getServerLocationFromURI( uri)+bundle.getString("MSG_WrongInstallDir")); 103 } 104 synchronized (dms) { 105 DeploymentManager retVal = dms.get(uri); 106 if (null == retVal) { 107 retVal = new SunDeploymentManager(innerDF, getRealURI(uri), userName, password,getServerLocationFromURI( uri)); 108 dms.put(uri,retVal); 109 } 110 return retVal; 111 } 112 } catch (Exception e) { 113 throw new DeploymentManagerCreationException (getRealURI(uri)+getServerLocationFromURI( uri)+bundle.getString("MSG_WrongInstallDir")); 114 } 115 } 116 117 125 public DeploymentManager getDisconnectedDeploymentManager(String uri) throws DeploymentManagerCreationException { 126 try { 127 128 return getDeploymentManager(uri,null,null); 129 } catch (Exception e) { 130 throw new DeploymentManagerCreationException (getRealURI(uri)+getServerLocationFromURI( uri)+bundle.getString("MSG_WrongInstallDir")); 131 } 132 } 133 134 146 public boolean handlesURI(String uri) { 147 if (uri==null){ 148 return false; 149 } 150 if(uri.startsWith("[")){ if (uri.indexOf(SunURIManager.SUNSERVERSURI)!=-1){ 152 return true; 153 } 154 } 155 156 157 return false; 158 } 159 160 public String getDisplayName() { 161 return bundle.getString("FACTORY_DISPLAYNAME"); } 163 164 public String getProductVersion() { 165 if (null != innerDF){ 166 return innerDF.getProductVersion(); 167 } 168 return "1.0"; } 170 171 private static File getServerLocationFromURI(String uri) throws DeploymentManagerCreationException { 172 173 if(uri.startsWith("[")){ String loc = uri.substring(1,uri.indexOf("]")); 175 return new File (loc); 176 } 177 throw new DeploymentManagerCreationException (uri+bundle.getString("MSG_WrongInstallDir")); 178 } 179 180 private static String getRealURI(String uri) throws DeploymentManagerCreationException { 181 if(uri.startsWith("[")){ return uri.substring(uri.indexOf("]")+1,uri.length()); 183 } 184 return uri; } 186 187 private void registerInstanceListener() { 188 synchronized(dms) { 189 if(!instanceListenerAdded) { 190 Deployment.getDefault().addInstanceListener(this); 191 instanceListenerAdded = true; 192 } 193 } 194 } 195 196 public void instanceRemoved(String serverInstanceID) { 198 synchronized (dms) { 199 dms.remove(serverInstanceID); 201 } 202 } 203 204 public void instanceAdded(String serverInstanceID) { 205 } 207 208 public void changeDefaultInstance(String oldServerInstanceID, String newServerInstanceID) { 209 } 211 212 } 213 | Popular Tags |