1 23 24 package com.sun.enterprise.instance; 25 26 import javax.enterprise.deploy.shared.ModuleType ; 27 28 import com.sun.enterprise.config.ConfigBean; 29 import com.sun.enterprise.config.ConfigContext; 30 import com.sun.enterprise.config.ConfigException; 31 import com.sun.enterprise.config.serverbeans.*; 32 import com.sun.enterprise.deployment.Application; 33 import com.sun.enterprise.deployment.archivist.ApplicationArchivist; 34 import com.sun.enterprise.deployment.archivist.EjbArchivist; 35 import com.sun.enterprise.deployment.backend.DeployableObjectInfo; 36 import com.sun.enterprise.deployment.backend.DeployableObjectType; 37 import com.sun.enterprise.deployment.deploy.shared.FileArchive; 38 import com.sun.enterprise.deployment.Descriptor; 39 import com.sun.enterprise.deployment.RootDeploymentDescriptor; 40 import com.sun.enterprise.deployment.BundleDescriptor; 41 import com.sun.enterprise.deployment.util.ModuleContentLinker; 42 import com.sun.enterprise.deployment.util.ModuleDescriptor; 43 import com.sun.enterprise.loader.EJBClassLoader; 44 import com.sun.enterprise.loader.EJBClassPathUtils; 45 import com.sun.enterprise.loader.InstrumentableClassLoader; 46 47 import java.io.File ; 48 import java.io.IOException ; 49 import java.net.MalformedURLException ; 50 import java.net.URL ; 51 import java.util.logging.Level ; 52 import java.util.*; 53 54 import com.sun.enterprise.util.RelativePathResolver; 58 import com.sun.enterprise.util.SystemPropertyConstants; 59 60 import com.sun.enterprise.util.io.FileUtils; 61 62 public class EjbModulesManager extends ModulesManager{ 63 64 public EjbModulesManager(InstanceEnvironment env) throws ConfigException { 65 super(env, true); 66 } 67 68 public EjbModulesManager(InstanceEnvironment env, 69 boolean useBackupServerXml) throws ConfigException { 70 super(env, useBackupServerXml); 71 EjbModule[] jArray = ((Applications)configBean).getEjbModule(); 73 if(jArray!=null) { 74 for(int i=0;i<jArray.length;i++) { 75 jArray[i].setConfigContext(configContext); 76 jArray[i].setXPath(ServerXPathHelper.getEjbModuleIdXpathExpression(jArray[i].getName())); 77 } 78 } 79 } 81 82 85 public ModuleType getModuleType() { 86 return ModuleType.EJB; 87 } 88 89 92 public EjbModule[] listEjbModules() { 93 EjbModule[] mods = ((Applications)this.configBean).getEjbModule(); 94 if(mods == null) return new EjbModule[0]; 95 96 ArrayList list = new ArrayList(); 97 for (int i=0; i<mods.length; i++) { 98 if ( isReferenced(mods[i].getName()) ) { 101 list.add(mods[i]); 102 } 103 } 104 EjbModule[] refList = new EjbModule[list.size()]; 106 return ( (EjbModule[]) list.toArray(refList) ); 107 } 108 109 112 public List listIds() { 113 ArrayList arr = new ArrayList(); 114 EjbModule[] mods = ((Applications)this.configBean).getEjbModule(); 115 if(mods == null) return arr; 116 117 for (int i=0;i<mods.length;i++) { 118 String name = mods[i].getName(); 119 if ( isReferenced(name) ) { 122 arr.add(name); 123 } 124 } 125 return arr; 126 } 127 128 private EjbModule getEjbModule(String modId) throws ConfigException { 129 EjbModule mod = (EjbModule) 130 ((Applications)this.configBean).getEjbModuleByName(modId); 131 132 if(mod == null) 133 throw new ConfigException(Localizer.getValue(ExceptionType.NO_SUCH_EJB_MOD)); 134 135 return mod; 136 137 } 138 139 public void remove(String modID) throws ConfigException { 140 removeEjbModule(modID); 141 } 142 143 private void removeEjbModule(String modId) throws ConfigException { 144 EjbModule backEm = (EjbModule) 145 ((Applications)configBean).getEjbModuleByName(modId); 146 ((Applications)configBean).removeEjbModule(backEm); 147 } 148 149 protected boolean isRegistered(String appId, ConfigBean bean) { 150 ConfigBean cb = null; 151 try { 152 cb = ((Applications)bean).getEjbModuleByName(appId); 153 } catch(Exception cn) { 154 } 155 156 if(cb != null) return true; 157 return false; 158 } 159 160 public boolean isShared(String modId) throws ConfigException{ 161 return false; } 164 165 public boolean isEnabled(String modId) throws ConfigException{ 166 return getEjbModule(modId).isEnabled(); 167 } 168 169 174 public boolean isSystem(String modId) throws ConfigException{ 175 EjbModule em = getEjbModule(modId); 176 String resourceType = em.getObjectType(); 177 if(resourceType.startsWith(SYSTEM_PREFIX)) 178 return true; 179 else 180 return false; 181 } 182 183 188 public boolean isSystemAdmin(String modId) throws ConfigException{ 189 EjbModule em = getEjbModule(modId); 190 String resourceType = em.getObjectType(); 191 if(resourceType.startsWith(SYSTEM_ADMIN_PREFIX)) 192 return true; 193 else 194 return false; 195 } 196 197 public void setShared(String modId, boolean shared) throws ConfigException{ 198 } 201 202 public void setEnable(String modId, boolean enable) throws ConfigException{ 203 getEjbModule(modId).setEnabled(enable); 204 } 205 206 212 public void setOptionalAttributes(String modId, Properties optionalAttributes) 213 throws ConfigException { 214 if(optionalAttributes!=null) { 215 EjbModule em = getEjbModule(modId); 216 Enumeration tags = optionalAttributes.keys(); 217 while(tags.hasMoreElements()) 218 { 219 String tag = (String )tags.nextElement(); 220 String value = optionalAttributes.getProperty(tag); 221 em.setAttributeValue(tag, value); 222 } 223 } 224 } 225 226 public String getLocation(String name) throws ConfigException { 227 EjbModule ejbModule = (EjbModule) 228 ((Applications)this.configBean).getEjbModuleByName(name); 229 String location = ejbModule.getLocation(); 230 return resolvePath(location); 231 } 232 233 239 240 public void setLocation(String modId, String location) throws ConfigException{ 241 getEjbModule(modId).setLocation(location); 242 } 243 244 public String getStubLocation(String name) { 245 ModuleEnvironment menv = instanceEnvironment.getModuleEnvironment(name, 246 DeployableObjectType.EJB); 247 return menv.getModuleStubPath(); 248 } 249 250 public String getGeneratedXMLLocation(String name){ 251 ModuleEnvironment menv = instanceEnvironment.getModuleEnvironment(name, 252 DeployableObjectType.EJB); 253 return menv.getModuleGeneratedXMLPath(); 254 } 255 256 public String getDescription(String modId) throws ConfigException { 257 return getEjbModule(modId).getDescription(); 258 } 259 260 public void setDescription(String modId, String desc) 261 throws ConfigException { 262 getEjbModule(modId).setDescription(desc); 263 } 264 265 270 public Application getDescriptor( 271 String moduleID, ClassLoader parentClassLoader) 272 throws ConfigException { 273 274 ClassLoader cl = new EJBClassLoader(parentClassLoader); 275 String [] classPaths = (String []) EJBClassPathUtils.getModuleClasspath( 276 moduleID, null, this).toArray(new String [0]); 277 278 if (classPaths != null) { 279 int classPathSize = classPaths.length; 280 for (int i=0; i<classPathSize; i++) { 281 try { 282 ((EJBClassLoader) cl).appendURL(new File (classPaths[i])); 283 } catch (IOException ioe) { 284 _logger.log(Level.WARNING, "Cannot convert path to URL: " + classPaths[i]); 286 } 287 } 288 } 289 290 return getDescriptor(moduleID, cl, false); 291 } 292 293 304 public Application getDescriptor(String modId, ClassLoader cl, 305 String loc, boolean validateXML) throws ConfigException { 306 307 return getDescriptor(modId, cl, validateXML); 308 } 309 310 324 public Application getDescriptor(String modId, ClassLoader cl, 325 boolean validateXml) throws ConfigException { 326 327 Application application = getRegisteredDescriptor(modId); 328 if (application!=null) { 329 application.setClassLoader(cl); 330 return application; 331 } 332 try { 333 String moduleDir = getLocation(modId); 334 EjbArchivist ejbArchivist = new EjbArchivist(); 335 ejbArchivist.setXMLValidation(validateXml); 336 337 ClassLoader tcl = (cl instanceof InstrumentableClassLoader) ? 340 InstrumentableClassLoader.class.cast(cl).copy() : cl; 341 ejbArchivist.setClassLoader(tcl); 342 343 FileArchive archive = new FileArchive(); 344 if (isSystemAdmin(modId)) { 349 archive.open(moduleDir); 350 } else { 351 String xmlDir = getGeneratedXMLLocation(modId); 352 if (FileUtils.safeIsDirectory(xmlDir)) { 353 archive.open(xmlDir); 354 } else { 355 _logger.log(Level.WARNING, "core.no_xmldir", 357 new Object []{xmlDir, moduleDir}); 358 archive.open(moduleDir); 359 } 360 } 361 application = ApplicationArchivist.openArchive(modId, ejbArchivist, archive, true); 362 363 application.setClassLoader(tcl); 366 for (BundleDescriptor bd : (Collection<BundleDescriptor>) 368 application.getBundleDescriptors()) { 369 bd.setClassLoader(tcl); 370 } 371 if(!isSystemAdmin(modId) && !isSystem(modId)) { 372 readPersistenceDeploymentDescriptors(moduleDir, application); 375 } 376 application.setGeneratedXMLDirectory(getGeneratedXMLLocation(modId)); 377 378 if (!application.getWebServiceDescriptors().isEmpty()) { 379 ModuleContentLinker visitor = new ModuleContentLinker(archive); 380 application.visit((com.sun.enterprise.deployment.util.ApplicationVisitor) visitor); 381 } 382 383 application.setClassLoader(cl); 385 for (BundleDescriptor bd : (Collection<BundleDescriptor>) 387 application.getBundleDescriptors()) { 388 bd.setClassLoader(cl); 389 } 390 registerDescriptor(modId, application); 391 392 return application; 393 } catch (ConfigException ce) { 394 throw ce; 395 } catch (IOException ioe) { 396 throw new ConfigException(Localizer.getValue( 397 ExceptionType.IO_ERROR_LOADING_DD, modId), ioe); 398 } catch (Throwable t) { 399 throw new ConfigException(Localizer.getValue( 400 ExceptionType.FAIL_DD_LOAD, modId), t); 401 } 402 } 403 } 404 | Popular Tags |