1 23 24 package com.sun.enterprise.instance; 25 26 import javax.enterprise.deploy.shared.ModuleType ; 27 28 import com.sun.appserv.server.util.ASClassLoaderUtil; 29 import com.sun.enterprise.config.ConfigBean; 30 import com.sun.enterprise.config.ConfigContext; 31 import com.sun.enterprise.config.ConfigException; 32 import com.sun.enterprise.config.serverbeans.Applications; 33 import com.sun.enterprise.config.serverbeans.J2eeApplication; 34 import com.sun.enterprise.config.serverbeans.PropertyResolver; 35 import com.sun.enterprise.config.serverbeans.ServerBeansFactory; 36 import com.sun.enterprise.config.serverbeans.ServerTags; 37 import com.sun.enterprise.config.serverbeans.ServerXPathHelper; 38 import com.sun.enterprise.deployment.Application; 39 import com.sun.enterprise.deployment.archivist.ApplicationArchivist; 40 import com.sun.enterprise.deployment.archivist.EjbArchivist; 41 import com.sun.enterprise.deployment.archivist.WebArchivist; 42 import com.sun.enterprise.deployment.backend.DeployableObjectInfo; 43 import com.sun.enterprise.deployment.deploy.shared.FileArchive; 44 import com.sun.enterprise.deployment.RootDeploymentDescriptor; 45 import com.sun.enterprise.deployment.EjbBundleDescriptor; 46 import com.sun.enterprise.deployment.BundleDescriptor; 47 import com.sun.enterprise.deployment.util.ModuleContentLinker; 48 import com.sun.enterprise.deployment.util.ModuleDescriptor; 49 import com.sun.enterprise.loader.EJBClassLoader; 50 import com.sun.enterprise.loader.EJBClassPathUtils; 51 import com.sun.enterprise.loader.InstrumentableClassLoader; 52 import com.sun.enterprise.util.RelativePathResolver; 53 import com.sun.enterprise.util.SystemPropertyConstants; 54 55 import java.io.File ; 56 import java.io.IOException ; 57 import java.net.MalformedURLException ; 58 import java.net.URL ; 59 import java.util.logging.Level ; 60 import java.util.*; 61 62 import com.sun.enterprise.util.io.FileUtils; 63 import org.xml.sax.SAXParseException ; 64 65 68 public class AppsManager extends BaseManager { 69 70 public AppsManager(InstanceEnvironment env) throws ConfigException { 71 super(env, true); 72 } 73 74 public AppsManager(InstanceEnvironment env, boolean useBackupServerXml) 75 throws ConfigException { 76 super(env, useBackupServerXml); 77 78 J2eeApplication[] jArray = ((Applications)configBean).getJ2eeApplication(); 80 if(jArray!=null) { 81 for(int i=0;i<jArray.length;i++) { 82 jArray[i].setConfigContext(configContext); 83 jArray[i].setXPath(ServerXPathHelper.getAppIdXpathExpression(jArray[i].getName())); 84 } 85 } 86 } 88 89 public ModuleType getModuleType() { 90 return ModuleType.EAR; 91 } 92 93 public String getStubLocation(String appId) { 94 95 ApplicationEnvironment env = 96 instanceEnvironment.getApplicationEnvironment(appId); 97 return env.getAppStubPath(); 98 } 99 100 public String getGeneratedXMLLocation(String name){ 101 ApplicationEnvironment env = instanceEnvironment.getApplicationEnvironment(name); 102 return env.getAppGeneratedXMLPath(); 103 } 104 105 public String getJSPLocation(String appId) { 106 107 ApplicationEnvironment env = 108 instanceEnvironment.getApplicationEnvironment(appId); 109 return env.getAppJSPPath(); 110 } 111 112 126 127 130 public J2eeApplication[] getAllApps() { 131 J2eeApplication[] apps = ((Applications)this.configBean).getJ2eeApplication(); 132 if(apps == null) return new J2eeApplication[0]; 133 134 ArrayList list = new ArrayList(); 135 for (int i=0; i<apps.length; i++) { 136 if ( isReferenced(apps[i].getName()) ) { 139 list.add(apps[i]); 140 } 141 } 142 J2eeApplication[] refList = new J2eeApplication[list.size()]; 144 return ( (J2eeApplication[]) list.toArray(refList) ); 145 } 146 147 150 public List listIds() { 151 ArrayList arr = new ArrayList(); 152 J2eeApplication[] apps = ((Applications)this.configBean).getJ2eeApplication(); 153 if(apps == null) return arr; 154 155 for (int i=0;i<apps.length;i++) { 156 String name = apps[i].getName(); 157 if ( isReferenced(name) ) { 160 arr.add(name); 161 } 162 } 163 return arr; 164 } 165 166 public String getLocation(String appId) throws ConfigException { 167 J2eeApplication app = (J2eeApplication) 168 ((Applications)this.configBean).getJ2eeApplicationByName(appId); 169 String resolvedPath = new PropertyResolver(super.configContext, 170 getInstanceEnvironment().getName()). 171 resolve(app.getLocation()); 172 return resolvedPath; 173 174 } 175 176 public boolean isEnabled(String appId) throws ConfigException { 177 return getJ2eeApplication(appId).isEnabled(); 178 } 179 180 186 public boolean isJavaWebStartEnabled(String appId) throws ConfigException { 187 J2eeApplication app = (J2eeApplication) ((Applications)this.configBean).getJ2eeApplicationByName(appId); 188 return app.isJavaWebStartEnabled(); 189 } 190 191 196 public boolean isSystem(String appId) throws ConfigException { 197 J2eeApplication ja = getJ2eeApplication(appId); 198 String resourceType = ja.getObjectType(); 199 if(resourceType.startsWith(SYSTEM_PREFIX)) 200 return true; 201 else 202 return false; 203 } 204 205 210 public boolean isSystemAdmin(String appId) throws ConfigException { 211 J2eeApplication ja = getJ2eeApplication(appId); 212 String resourceType = ja.getObjectType(); 213 if(resourceType.startsWith(SYSTEM_ADMIN_PREFIX)) 214 return true; 215 else 216 return false; 217 } 218 219 protected boolean isRegistered(String appId, ConfigBean bean) { 220 ConfigBean cb = null; 221 try { 222 cb = ((Applications)bean).getJ2eeApplicationByName(appId); 223 } catch(Exception cn) { 224 } 225 226 if(cb != null) return true; 227 return false; 228 } 229 230 235 public void remove(String appId) throws ConfigException { 236 J2eeApplication backJa = (J2eeApplication) 237 ((Applications)configBean).getJ2eeApplicationByName(appId); 238 ((Applications)configBean).removeJ2eeApplication(backJa); 239 } 240 241 247 public void setEnable(String appId, boolean enabled) 248 throws ConfigException { 249 getJ2eeApplication(appId).setEnabled(enabled); 250 } 251 252 258 public void setLocation(String appId, String location) 259 throws ConfigException { 260 getJ2eeApplication(appId).setLocation(location); 261 } 262 263 264 270 public void setOptionalAttributes(String appId, Properties optionalAttributes) 271 throws ConfigException { 272 if(optionalAttributes!=null) { 273 J2eeApplication ja = getJ2eeApplication(appId); 274 Enumeration tags = optionalAttributes.keys(); 275 while(tags.hasMoreElements()) 276 { 277 String tag = (String )tags.nextElement(); 278 String value = optionalAttributes.getProperty(tag); 279 ja.setAttributeValue(tag, value); 280 } 281 } 282 } 283 284 291 public Application getDescriptor( 292 String appID, ClassLoader cl, String loc, boolean validateXML) 293 throws ConfigException { 294 return getRegisteredDescriptor(appID); 295 } 296 297 304 public Application getAppDescriptor(String appID, ClassLoader parentClassLoader) 305 throws ConfigException { 306 307 Application application = getRegisteredDescriptor(appID); 308 if (application != null) { 309 return application; 310 } 311 312 try { 313 ApplicationArchivist archivist = new ApplicationArchivist(); 315 FileArchive appArchive = new FileArchive(); 316 appArchive.open(getLocation(appID)); 317 318 if (!archivist.hasStandardDeploymentDescriptor(appArchive)) { 321 appArchive.open(getGeneratedXMLLocation(appID)); 323 } 324 325 application = Application.createApplication(appArchive,false); 326 application.setRegistrationName(appID); 327 String moduleRoot = getLocation(application.getRegistrationName()); 328 String [] classPaths = (String []) EJBClassPathUtils.getAppClasspath( 329 application, this).toArray(new String [0]); 330 if (_logger.isLoggable(Level.FINE)) { 331 _logger.log(Level.FINE, "[AppsManager] :: appID " + appID + " classpaths " 332 + classPaths + " moduleRoot " + moduleRoot 333 + " parentClassLoader " + parentClassLoader); 334 } 335 ClassLoader cl = EJBClassPathUtils.createEJBClassLoader(classPaths, 336 moduleRoot , appID, parentClassLoader, 337 application.getModuleType()); 338 application.setClassLoader(cl); 339 } catch (Exception confEx) { 340 _logger.log(Level.SEVERE,"loader.error_while_loading_app_desc", confEx); 341 throw new ConfigException(confEx); 342 } 343 344 return getAppDescriptor(application); 345 } 346 347 358 public Application getAppDescriptor(Application application) 359 throws ConfigException { 360 361 if (application == null) { 362 throw new ConfigException("Application object should not be null"); 363 } 364 365 ClassLoader cl = application.getClassLoader(); 366 367 if (cl instanceof InstrumentableClassLoader) { 371 ClassLoader tcl = InstrumentableClassLoader.class.cast(cl).copy(); 372 application.setClassLoader(tcl); 373 for (BundleDescriptor bd : (Collection<BundleDescriptor>) 375 application.getBundleDescriptors()) { 376 bd.setClassLoader(tcl); 377 } 378 } 379 String appId = application.getRegistrationName(); 380 381 try { 383 String appDir = getLocation(appId); 384 FileArchive in = new FileArchive(); 385 if (isSystemAdmin(appId)) { 390 in.open(appDir); 391 } else { 392 String xmlDir = getGeneratedXMLLocation(appId); 393 if (FileUtils.safeIsDirectory(xmlDir)) { 394 in.open(xmlDir); 395 } else { 396 _logger.log(Level.WARNING, "core.no_xmldir", 398 new Object []{xmlDir, appDir}); 399 in.open(appDir); 400 } 401 } 402 403 ApplicationArchivist archivist = new ApplicationArchivist(); 404 archivist.readModulesDescriptors(application, in); 405 archivist.readRuntimeDeploymentDescriptor(in, application); 406 if(!isSystemAdmin(appId) && !isSystem(appId)) { 407 readPersistenceDeploymentDescriptors(appDir, application); 410 } 411 archivist.setDescriptor(application); 412 413 archivist.validate(application.getClassLoader()); 416 417 application.setGeneratedXMLDirectory(getGeneratedXMLLocation(appId)); 418 419 if (!application.getWebServiceDescriptors().isEmpty()) { 420 ModuleContentLinker visitor = new ModuleContentLinker(in); 421 application.visit((com.sun.enterprise.deployment.util.ApplicationVisitor) visitor); 422 } 423 424 application.setClassLoader(cl); 428 for (BundleDescriptor bd : (Collection<BundleDescriptor>) 430 application.getBundleDescriptors()) { 431 bd.setClassLoader(cl); 432 } 433 registerDescriptor(appId, application); 434 435 return application; 436 } catch (ConfigException ce) { 437 throw ce; 438 } catch (Throwable t) { 439 throw new ConfigException( 440 Localizer.getValue(ExceptionType.FAIL_DD_LOAD, appId), t); 441 } 442 } 443 444 public String getDescription(String id) throws ConfigException { 445 return getJ2eeApplication(id).getDescription(); 446 } 447 448 private J2eeApplication getJ2eeApplication(String appId) 449 throws ConfigException { 450 451 J2eeApplication app = (J2eeApplication) 452 ((Applications)this.configBean).getJ2eeApplicationByName(appId); 453 454 if(app == null) 455 throw new ConfigException( 456 Localizer.getValue(ExceptionType.APP_NOT_EXIST)); 457 return app; 458 459 } 460 461 public void setDescription(String id, String desc) throws ConfigException { 462 getJ2eeApplication(id).setDescription(desc); 463 } 464 465 public String getVirtualServersByAppName(String appName) throws ConfigException { 466 return ServerBeansFactory.getVirtualServersByAppName(configContext, appName); 467 } 468 469 472 public Map getRegisteredDescriptors() { 473 474 if (apps==null) { 475 synchronized (AppsManager.class) { 476 if (apps==null) { 477 apps = new HashMap(); 478 } 479 } 480 } 481 return apps; 482 } 483 484 private static Map apps=null; 485 } 486 | Popular Tags |