* metadata
*/
public static Application processJavaEEMetaData(File moduleRootDirectory,
File moduleScratchDirectory, ClassLoader moduleClassLoader,
boolean isDeploy) throws IOException, SAXParseException {
FileArchive archive = new FileArchive();
try {
if (isDeploy) {
// If this is deployment scenario, we should process JavaEE
// annotations and all deployment descriptors should be loaded
// from module root directory
archive.open(moduleRootDirectory.getAbsolutePath());
Archivist moduleArchivist =
ArchivistFactory.getArchivistForArchive(archive);
moduleArchivist.setAnnotationProcessingRequested(true);
moduleArchivist.setClassLoader(moduleClassLoader);
return ApplicationArchivist.openArchive(moduleArchivist,
archive, true);
} else {
// If this is server start up scenario, we do not need to
// process JavaEE annotations again. The application
// deployment descriptors will be loaded from
// moduleScratchDirectory and persistence descriptors from
// moduleRootDirectory
archive.open(moduleScratchDirectory.getAbsolutePath());
Archivist moduleArchivist =
ArchivistFactory.getArchivistForArchive(archive);
ClassLoader tcl = (moduleClassLoader instanceof InstrumentableClassLoader) ? InstrumentableClassLoader.class.cast(moduleClassLoader).copy() : moduleClassLoader;
moduleArchivist.setClassLoader(tcl);
Application application = ApplicationArchivist.openArchive(
moduleArchivist, archive, true);
application.setClassLoader(tcl);
for (BundleDescriptor bd : (Collection <BundleDescriptor>)
application.getBundleDescriptors()) {
bd.setClassLoader(tcl);
}
// we need to read persistence descriptors separately
// because they are read from appDir as oppsed to xmlDir.
FileArchive archive2 = new FileArchive();
try {
archive2.open(moduleRootDirectory.getAbsolutePath());
ApplicationArchivist.readPersistenceDeploymentDescriptorsRecursively(archive2, application);
} finally {
archive2.close();
}
return application;
}
} finally {
archive.close();