1 19 20 23 package org.netbeans.modules.j2ee.sun.ws7.dm; 24 25 import javax.enterprise.deploy.shared.factories.DeploymentFactoryManager ; 26 import javax.enterprise.deploy.spi.DeploymentManager ; 27 import javax.enterprise.deploy.spi.factories.DeploymentFactory ; 28 import javax.enterprise.deploy.spi.exceptions.DeploymentManagerCreationException ; 29 import org.netbeans.modules.j2ee.deployment.plugins.api.InstanceProperties; 30 31 import org.openide.ErrorManager; 32 import org.openide.util.NbBundle; 33 import org.netbeans.modules.j2ee.sun.ws7.WS7LibsClassLoader; 34 import org.netbeans.modules.j2ee.sun.ws7.ui.WS70URIManager; 35 import org.netbeans.modules.j2ee.sun.ws7.ui.WS70ServerUIWizardIterator; 36 import java.io.File ; 37 import java.util.HashMap ; 38 39 public class WS70SunDeploymentFactory implements DeploymentFactory { 40 private DeploymentFactory ws70DF; 41 private static HashMap ws7ClassLoaders; 42 private static HashMap connectedDepManagers; 43 private static final String HTTPS=":https"; 45 public static synchronized Object create(){ 46 try{ 47 DeploymentFactory factory = new WS70SunDeploymentFactory(); 48 DeploymentFactoryManager.getInstance().registerDeploymentFactory (factory); 49 return factory; 50 }catch(Exception ex){ 51 ex.printStackTrace(); 52 } 53 return null; 54 } 55 56 59 public WS70SunDeploymentFactory() { 60 ws7ClassLoaders = new HashMap (); 61 connectedDepManagers = new HashMap (); 62 } 63 64 65 73 public DeploymentManager getDeploymentManager(String uri, String uname, 74 String passwd) 75 throws DeploymentManagerCreationException { 76 77 String location = WS70URIManager.getLocation(uri); 78 79 86 if(location==null){ 87 return new WS70SunDeploymentManager(null, null, uri, uname, passwd); 88 } 89 WS7LibsClassLoader ws7Libloader = (WS7LibsClassLoader)ws7ClassLoaders.get(location); 90 if(ws7Libloader == null){ 91 ws7Libloader = (WS7LibsClassLoader)getWs7ClassLoader(location); 92 ws7ClassLoaders.put(location, ws7Libloader); 93 } 94 if(ws70DF==null){ 95 try{ 96 this.createInnerFactory(ws7Libloader); 97 }catch(Exception ex){ 98 throw new DeploymentManagerCreationException (ex.getMessage()); 99 } 100 } 101 102 ClassLoader origClassLoader=Thread.currentThread().getContextClassLoader(); 103 try{ 104 String ws70url = WS70URIManager.getURIWithoutLocation(uri); 105 InstanceProperties ip = InstanceProperties.getInstanceProperties(uri); 106 String isSSL = ip.getProperty(WS70ServerUIWizardIterator.PROP_SSL_PORT); 107 if(Boolean.parseBoolean(isSSL)){ 108 ws70url=ws70url+HTTPS; 109 } 110 Thread.currentThread().setContextClassLoader(ws7Libloader); 111 DeploymentManager manager = new WS70SunDeploymentManager(ws70DF, ws70DF.getDeploymentManager(ws70url, uname, passwd), 112 uri, uname, passwd); 113 if(connectedDepManagers!=null){ 114 connectedDepManagers.put(uri, manager); 115 } 116 return manager; 117 }catch(Exception e){ 118 e.printStackTrace(); 119 throw new DeploymentManagerCreationException (e.getMessage()); 120 }finally{ 121 Thread.currentThread().setContextClassLoader(origClassLoader); 122 } 123 } 124 125 133 public DeploymentManager getDisconnectedDeploymentManager(String uri) 134 throws DeploymentManagerCreationException { 135 136 String location = WS70URIManager.getLocation(uri); 137 143 if(location==null){ 144 return new WS70SunDeploymentManager(null, null, uri, null, null); 145 } 146 WS7LibsClassLoader ws7Libloader = (WS7LibsClassLoader)ws7ClassLoaders.get(location); 147 if(ws7Libloader == null){ 148 ws7Libloader = (WS7LibsClassLoader)getWs7ClassLoader(location); 149 ws7ClassLoaders.put(location, ws7Libloader); 150 } 151 if(ws70DF==null){ 152 try{ 153 this.createInnerFactory(ws7Libloader); 154 }catch(Exception ex){ 155 throw new DeploymentManagerCreationException (ex.getMessage()); 156 } 157 } 158 159 ClassLoader origClassLoader=Thread.currentThread().getContextClassLoader(); 160 try{ 161 String ws70url = WS70URIManager.getURIWithoutLocation(uri); 162 InstanceProperties ip = InstanceProperties.getInstanceProperties(uri); 163 String isSSL = ip.getProperty(WS70ServerUIWizardIterator.PROP_SSL_PORT); 164 if(Boolean.parseBoolean(isSSL)){ 165 ws70url=ws70url+HTTPS; 166 } 167 Thread.currentThread().setContextClassLoader(ws7Libloader); 168 DeploymentManager manager = new WS70SunDeploymentManager(ws70DF, ws70DF.getDisconnectedDeploymentManager(ws70url), 169 uri, null, null); 170 return manager; 171 }catch(Exception e){ 172 e.printStackTrace(); 173 throw new DeploymentManagerCreationException (e.getMessage()); 174 }finally{ 175 Thread.currentThread().setContextClassLoader(origClassLoader); 176 } 177 } 178 179 191 public boolean handlesURI(String uri) { 192 if (uri == null) { 193 return false; 194 } 195 String location = WS70URIManager.getLocation(uri); 196 if(location==null){ 197 return false; 198 } 199 WS7LibsClassLoader ws7Libloader = (WS7LibsClassLoader)ws7ClassLoaders.get(location); 200 if(ws7Libloader == null){ 201 ws7Libloader = (WS7LibsClassLoader)getWs7ClassLoader(location); 202 ws7ClassLoaders.put(location, ws7Libloader); 203 } 204 if(ws70DF==null){ 205 try{ 206 this.createInnerFactory(ws7Libloader); 207 }catch(Exception ex){ 208 return false; 209 } 210 } 211 ClassLoader origClassLoader=Thread.currentThread().getContextClassLoader(); 212 Thread.currentThread().setContextClassLoader(ws7Libloader); 213 boolean ret = ws70DF.handlesURI(WS70URIManager.getURIWithoutLocation(uri)); 214 Thread.currentThread().setContextClassLoader(origClassLoader); 215 return ret; 216 } 217 218 public String getDisplayName() { 219 return NbBundle.getMessage(WS70SunDeploymentFactory.class, "LBL_WS70SunDeploymentFactory"); 220 } 221 222 public String getProductVersion() { 223 return NbBundle.getMessage(WS70SunDeploymentFactory.class, "LBL_WS70SunDeploymentFactoryVersion"); 224 } 225 private static ClassLoader getWs7ClassLoader(String location){ 226 WS7LibsClassLoader ws7Loader = null; 227 try{ 228 String libsLocation = location+"/lib"; ClassLoader moduleClassLoader = new Dummy().getClass().getClassLoader(); 231 ErrorManager.getDefault().log(ErrorManager.USER, "WS70 moduleclassloader is "+moduleClassLoader.toString()); 232 ws7Loader = new WS7LibsClassLoader(moduleClassLoader); 233 File f = null; 234 235 240 f = new File (libsLocation+"/sun-ws-jsr88-dm.jar"); ws7Loader.addURL(f); 242 f = new File (libsLocation+"/s1as-jsr160-client.jar"); ws7Loader.addURL(f); 244 245 f = new File (libsLocation+"/jmxremote_optional.jar"); ws7Loader.addURL(f); 247 248 253 f = new File (libsLocation+"/webserv-admin-shared.jar"); ws7Loader.addURL(f); 255 256 }catch(Exception ex){ 257 ex.printStackTrace(); 258 } 259 return ws7Loader; 260 } 261 private void createInnerFactory(WS7LibsClassLoader loader) throws Exception { 262 try{ 263 Object factory = loader.loadClass("com.sun.web.admin.deployapi.SunDeploymentFactory").newInstance(); 264 ws70DF = (DeploymentFactory )factory; 265 }catch(Exception ex){ 266 ex.printStackTrace(); 267 throw ex; 268 } 269 } 270 public static WS70SunDeploymentManager getConnectedCachedDeploymentManager(String uri){ 271 WS70SunDeploymentManager dm = (WS70SunDeploymentManager)connectedDepManagers.get(uri); 272 return dm; 273 } 274 public static ClassLoader getLibClassLoader(String location){ 275 return (ClassLoader )ws7ClassLoaders.get(location); 276 } 277 public static class Dummy{ 279 280 } 281 282 } 283 | Popular Tags |