*/
public Application getAppDescriptor(Application application)
throws ConfigException {
if (application == null) {
throw new ConfigException("Application object should not be null");
}
ClassLoader cl = application.getClassLoader();
// We need to use a temp CL until we are done with validate().
// See https://glassfish.dev.java.net/issues/show_bug.cgi?id=223
// for details.
if (cl instanceof InstrumentableClassLoader) {
ClassLoader tcl = InstrumentableClassLoader.class.cast(cl).copy();
application.setClassLoader(tcl);
// set it in all the bundles as well,
for (BundleDescriptor bd : (Collection<BundleDescriptor>)
application.getBundleDescriptors()) {
bd.setClassLoader(tcl);
}
}
String appId = application.getRegistrationName();
// we need to load this puppy, save it in the cache...
try {
String appDir = getLocation(appId);
FileArchive in = openDDArchive(appId, appDir);
ApplicationArchivist archivist = new ApplicationArchivist();
archivist.setClassLoader(application.getClassLoader());
archivist.readModulesDescriptors(application, in);
archivist.readRuntimeDeploymentDescriptor(in, application);
if(!isSystemAdmin(appId) && !isSystem(appId)) {
// we need to read persistence descriptors separately
// because they are read from appDir as oppsed to xmlDir.
readPersistenceDeploymentDescriptors(appDir, application);
}
archivist.setDescriptor(application);
// use temp CL that is set in the application. For details,
// see https://glassfish.dev.java.net/issues/show_bug.cgi?id=223
archivist.validate(application.getClassLoader());
application.setGeneratedXMLDirectory(getGeneratedXMLLocation(appId));
if (!application.getWebServiceDescriptors().isEmpty()) {
ModuleContentLinker visitor = new ModuleContentLinker(in);
application.visit((com.sun.enterprise.deployment.util.ApplicationVisitor) visitor);
}
// Now that validate() is called, we can set the actual CL.
// See https://glassfish.dev.java.net/issues/show_bug.cgi?id=223
// for details.
application.setClassLoader(cl);
// set it in all the bundles as well,
for (BundleDescriptor bd : (Collection<BundleDescriptor>)
application.getBundleDescriptors()) {
bd.setClassLoader(cl);
}
registerDescriptor(appId, application);
return application;
} catch (ConfigException ce) {
throw ce;
} catch (Throwable t) {
throw new ConfigException(
Localizer.getValue(ExceptionType.FAIL_DD_LOAD, appId), t);
}
}