1 19 20 21 package org.netbeans.modules.j2ee.deployment.impl; 22 23 import java.io.OutputStream ; 24 import javax.enterprise.deploy.shared.factories.DeploymentFactoryManager ; 25 import javax.enterprise.deploy.spi.factories.DeploymentFactory ; 26 import javax.enterprise.deploy.spi.exceptions.DeploymentManagerCreationException ; 27 import javax.enterprise.deploy.spi.*; 28 import org.netbeans.modules.j2ee.deployment.common.api.ValidationException; 29 import org.netbeans.modules.j2ee.deployment.impl.gen.nbd.*; 30 import org.netbeans.modules.j2ee.deployment.plugins.api.*; 31 import org.netbeans.modules.j2ee.deployment.impl.ui.RegistryNodeProvider; 32 import org.openide.filesystems.*; 33 import org.openide.loaders.*; 34 import org.openide.util.Lookup; 35 import org.openide.cookies.InstanceCookie; 36 import org.openide.nodes.Node; 37 import org.openide.ErrorManager; 38 import org.openide.util.NbBundle; 39 import java.util.*; 40 import org.netbeans.modules.j2ee.deployment.devmodules.api.J2eeModule; 41 import javax.enterprise.deploy.shared.ModuleType ; 42 43 44 public class Server implements Node.Cookie { 45 46 static public final String ATTR_needsFindServerUI = "needsFindServerUI"; 47 48 final NetbeansDeployment dep; 49 final Class factoryCls; 50 DeploymentFactory factory = null; 51 DeploymentManager manager = null; 52 RegistryNodeProvider nodeProvider = null; 53 final String name; 54 Map configMap; 55 Map customMap; 56 Lookup lkp; 57 boolean needsFindServerUI = false; 58 59 public Server(FileObject fo) throws Exception { 60 initDeploymentConfigurationFileList(fo); 62 name = fo.getName(); 63 FileObject descriptor = fo.getFileObject("Descriptor"); 64 if(descriptor == null) { 65 String msg = NbBundle.getMessage(Server.class, "MSG_InvalidServerPlugin", name); 66 throw new IllegalStateException (msg); 67 } 68 needsFindServerUI = getBooleanValue(descriptor.getAttribute(ATTR_needsFindServerUI), false); 69 70 dep = NetbeansDeployment.createGraph(descriptor.getInputStream()); 71 72 lkp = new FolderLookup (DataFolder.findContainer (fo)).getLookup (); 73 factory = (DeploymentFactory ) lkp.lookup (DeploymentFactory .class); 74 if (factory != null) { 75 factoryCls = factory.getClass (); 76 } else { 77 FileObject factoryinstance = fo.getFileObject("Factory.instance"); 78 if(factoryinstance == null) { 79 String msg = NbBundle.getMessage(Server.class, "MSG_NoFactoryInstanceClass", name); 80 ErrorManager.getDefault().log(ErrorManager.ERROR, msg); 81 factoryCls = null; 82 return; 83 } 84 DataObject dobj = DataObject.find(factoryinstance); 85 InstanceCookie cookie = (InstanceCookie) dobj.getCookie(InstanceCookie.class); 86 if(cookie == null) { 87 String msg = NbBundle.getMessage(Server.class, "MSG_FactoryFailed", name, cookie); 88 ErrorManager.getDefault().log(ErrorManager.ERROR, msg); 89 factoryCls = null; 90 return; 91 } 92 factoryCls = cookie.instanceClass(); 93 94 97 try { 98 factory = (DeploymentFactory ) cookie.instanceCreate(); 99 } catch (Exception e) { 100 ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, e); 101 } 102 } 103 } 105 106 107 private DeploymentFactory getFactory() { 108 if (factory == null) { 109 DeploymentFactoryManager dfm = DeploymentFactoryManager.getInstance(); 110 try { 115 Thread.sleep(5000); 117 } catch (Exception e) {} 118 DeploymentFactory [] factories = DeploymentFactoryManager.getInstance().getDeploymentFactories(); 121 for(int i = 0; i < factories.length; i++) { 122 if(factoryCls.isInstance(factories[i])) { 124 factory = factories[i]; 125 break; 126 } 127 } 128 } 129 if(factory == null) { 130 throw new IllegalStateException (); 132 } 133 return factory; 134 } 135 136 public DeploymentManager getDisconnectedDeploymentManager() throws DeploymentManagerCreationException { 137 if(manager == null) { 138 manager = getDisconnectedDeploymentManager(dep.getDisconnectedString()); 139 } 140 return manager; 141 } 142 143 public DeploymentManager getDisconnectedDeploymentManager(String uri) throws DeploymentManagerCreationException { 144 return getFactory().getDisconnectedDeploymentManager(uri); 145 } 146 147 public boolean handlesUri(String uri) { 148 try { 149 return getFactory().handlesURI(uri); 150 } catch (Exception e) { 151 ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, e); 152 return false; 153 } 154 } 155 156 public DeploymentManager getDeploymentManager(String uri, String username, String password) throws DeploymentManagerCreationException { 157 return getFactory().getDeploymentManager(uri,username, password); 158 } 159 160 public String getDisplayName() { 161 return getFactory().getDisplayName(); 162 } 163 164 public String getShortName() { 165 return name; 166 } 167 168 public String getIconBase() { 169 return dep.getIcon(); 170 } 171 172 public boolean canDeployEars() { 173 return dep.getContainerLimitation() == null || dep.getContainerLimitation().isEarDeploy(); 174 } 175 176 public boolean canDeployWars() { 177 return dep.getContainerLimitation() == null || dep.getContainerLimitation().isWarDeploy(); 178 } 179 180 public boolean canDeployEjbJars() { 181 return dep.getContainerLimitation() == null || dep.getContainerLimitation().isEjbjarDeploy(); 182 } 183 184 public ConfigBeanDescriptor getConfigBeanDescriptor(String className) { 185 if(configMap == null) { 186 ConfigBean[] beans = dep.getConfigBean(); 187 configMap = new HashMap(); 188 for(int i = 0; i < beans.length; i++) 189 configMap.put(beans[i].getClassName(),new ConfigBeanDescriptor(beans[i])); 190 } 191 return (ConfigBeanDescriptor) configMap.get(className); 192 } 193 194 public String getHelpId(String beanClass) { 196 ConfigBean[] beans = dep.getConfigBean(); 197 for(int i = 0; i < beans.length; i++) { 198 if(beans[i].getClassName().equals(beanClass)) 199 return beans[i].getHelpid(); 200 } 201 return null; 202 } 203 204 public RegistryNodeProvider getNodeProvider() { 205 if (nodeProvider != null) 206 return nodeProvider; 207 208 RegistryNodeFactory nodeFact = (RegistryNodeFactory) lkp.lookup(RegistryNodeFactory.class); 209 if (nodeFact == null) { 210 String msg = NbBundle.getMessage(Server.class, "MSG_NoInstance", name, RegistryNodeFactory.class); 211 ErrorManager.getDefault().log(ErrorManager.INFORMATIONAL, msg); 212 } 213 nodeProvider = new RegistryNodeProvider(nodeFact); return nodeProvider; 215 } 216 217 public RegistryNodeFactory getRegistryNodeFactory() { 218 return (RegistryNodeFactory) lkp.lookup(RegistryNodeFactory.class); 219 } 220 221 222 public OptionalDeploymentManagerFactory getOptionalFactory () { 223 OptionalDeploymentManagerFactory o = (OptionalDeploymentManagerFactory) lkp.lookup (OptionalDeploymentManagerFactory.class); 224 return o; 225 } 226 227 228 public J2eePlatformFactory getJ2eePlatformFactory () { 229 J2eePlatformFactory o = (J2eePlatformFactory) lkp.lookup (J2eePlatformFactory.class); 230 return o; 231 } 232 233 239 245 public ConfigurationSupport getConfigurationSupport() { 246 ConfigurationSupport cs = (ConfigurationSupport) lkp.lookup (ConfigurationSupport.class); 247 return cs; 248 } 249 250 public VerifierSupport getVerifierSupport() { 251 VerifierSupport vs = (VerifierSupport) lkp.lookup (VerifierSupport.class); 252 return vs; 253 } 254 255 public boolean canVerify(Object moduleType) { 256 VerifierSupport vs = getVerifierSupport(); 257 return vs != null && vs.supportsModuleType(moduleType); 258 } 259 260 public void verify(FileObject target, OutputStream logger) throws ValidationException { 261 getVerifierSupport().verify(target, logger); 262 } 263 264 public ServerInstance[] getInstances() { 265 Collection ret = new ArrayList(); 266 for (Iterator i=ServerRegistry.getInstance().getInstances().iterator(); i.hasNext();) { 267 ServerInstance inst = (ServerInstance) i.next(); 268 if (name.equals(inst.getServer().getShortName())) 269 ret.add(inst); 270 } 271 return (ServerInstance[]) ret.toArray(new ServerInstance[ret.size()]); 272 } 273 274 public WebContextRoot getWebContextRoot() { 275 return dep.getWebContextRoot(); 276 } 277 278 public DeploymentFactory getDeploymentFactory() { 279 return factory; 280 } 281 282 static public boolean getBooleanValue(Object v, boolean dvalue) { 283 if (v instanceof Boolean ) 284 return ((Boolean )v).booleanValue(); 285 if (v instanceof String ) 286 return Boolean.valueOf((String ) v).booleanValue(); 287 return dvalue; 288 } 289 290 public boolean needsFindServerUI() { 291 return needsFindServerUI; 292 } 293 294 public String toString () { 295 return getShortName (); 296 } 297 298 public boolean supportsModuleType(ModuleType type) { 299 if (J2eeModule.WAR.equals(type)) { 300 return this.canDeployWars(); 301 } else if (J2eeModule.EJB.equals(type)) { 302 return this.canDeployEjbJars(); 303 } else if (J2eeModule.EAR.equals(type)) { 304 return this.canDeployEars(); 305 } else { 306 return true; 308 } 309 } 310 311 public static final String LAYER_DEPLOYMENT_FILE_NAMES = "DeploymentFileNames"; private Map deployConfigDescriptorMap; 313 private void initDeploymentConfigurationFileList(FileObject fo) { 314 deployConfigDescriptorMap = new HashMap(); 315 FileObject deplFNames = fo.getFileObject(LAYER_DEPLOYMENT_FILE_NAMES); 316 if (deplFNames != null) { 317 FileObject mTypes [] = deplFNames.getChildren(); 318 for (int j=0; j < mTypes.length; j++) { 319 String mTypeName = mTypes [j].getName().toUpperCase(); 320 FileObject allNames [] = mTypes [j].getChildren(); 321 if (allNames == null || allNames.length == 0) 322 continue; 323 ArrayList filepaths = new ArrayList(); 324 for (int i = 0; i < allNames.length; i++) { 325 if (allNames[i] == null) 326 continue; 327 String fname = allNames [i].getNameExt(); 328 filepaths.add(fname.replace('\\', '/')); } 330 deployConfigDescriptorMap.put(mTypeName, filepaths.toArray(new String [filepaths.size()])); 331 } 332 } 333 } 334 335 public String [] getDeploymentPlanFiles(Object type) { 336 return (String []) deployConfigDescriptorMap.get(type.toString().toUpperCase()); 337 } 338 } 339 | Popular Tags |