private AppModule loadApplication(StandardContext standardContext) {
// create the web module
WebModule webModule = createWebModule(standardContext);
// create the app module
AppModule appModule = new AppModule(webModule.getClassLoader(), webModule.getJarLocation());
// add the web module itself
appModule.getWebModules().add(webModule);
// check each url to determine if it is an ejb jar
for (URL url : getUrls(standardContext)) {
try {
Class moduleType = DeploymentLoader.discoverModuleType(url, standardContext.getLoader().getClassLoader(), true);
if (EjbModule.class.isAssignableFrom(moduleType)) {
File file;
if (url.getProtocol().equals("jar")) {
url = new URL(url.getFile().replaceFirst("!.*$", ""));
file = URLs.toFile(url);
} else if (url.getProtocol().equals("file")) {
file = URLs.toFile(url);
} else {
logger.warning("Not loading " + moduleType.getSimpleName() + ". Unknown protocol " + url.getProtocol());
continue;
}
logger.info("Found ejb module " + moduleType.getSimpleName() + " in war " + standardContext.getPath());
// create the ejb module and set its moduleId to the webapp context root name
EjbModule ejbModule = new EjbModule(webModule.getClassLoader(), getEjbModuleId(standardContext),file.getAbsolutePath(), null, null);
// EJB deployment descriptors
try {
ResourceFinder ejbResourceFinder = new ResourceFinder("", standardContext.getLoader().getClassLoader(), file.toURL());
Map<String, URL> descriptors = ejbResourceFinder.getResourcesMap("META-INF/");
ejbModule.getAltDDs().putAll(descriptors);
} catch (IOException e) {
logger.error("Unable to determine descriptors in jar.", e);
}
// add module to app
appModule.getEjbModules().add(ejbModule);
}
} catch (IOException e) {
logger.warning("Unable to determine the module type of " + url.toExternalForm() + ": Exception: " + e.getMessage(), e);
} catch (UnknownModuleTypeException ignore) {
}
}
// Persistence Units via META-INF/persistence.xml
try {
ResourceFinder finder = new ResourceFinder("", standardContext.getLoader().getClassLoader());
List<URL> persistenceUrls = finder.findAll("META-INF/persistence.xml");
appModule.getAltDDs().put("persistence.xml", persistenceUrls);
} catch (IOException e) {
logger.warning("Cannot load persistence-units from 'META-INF/persistence.xml' : " + e.getMessage(), e);
}
return appModule;