URL rarUrl = resouceModules.get(moduleName);
File rarFile = new File(rarUrl.getPath());
Map<String, URL> descriptors = getDescriptors(rarUrl);
Connector connector = null;
if (descriptors.containsKey("ra.xml")){
connector = ReadDescriptors.readConnector(descriptors.get("ra.xml"));
}
ConnectorModule connectorModule = new ConnectorModule(connector, appClassLoader, rarFile.getAbsolutePath(), moduleName);
connectorModule.getAltDDs().putAll(descriptors);
appModule.getResourceModules().add(connectorModule);
} catch (OpenEJBException e) {
logger.error("Unable to load RAR: " + appDir.getAbsolutePath() + ", module: " + moduleName + ". Exception: " + e.getMessage(), e);
}
}
// Web modules
for (String moduleName : webModules.keySet()) {
try {
URL warUrl = webModules.get(moduleName);
File warFile = new File(warUrl.getPath());
// read web.xml file
Map<String, URL> descriptors = getDescriptors(warUrl);
WebApp webApp = null;
if (descriptors.containsKey("web.xml")){
webApp = ReadDescriptors.readWebApp(descriptors.get("web.xml"));
}
// determine war class path
List<URL> webClassPath = new ArrayList<URL>();
File webInfDir = new File(warFile, "WEB-INF");
try {
webClassPath.add(new File(webInfDir, "classes").toURL());
} catch (MalformedURLException e) {
logger.warning("War path bad: " + new File(webInfDir, "classes"), e);
}
File libDir = new File(webInfDir, "lib");
if (libDir.exists()) {
for (File file : libDir.listFiles()) {
if (file.getName().endsWith(".jar") || file.getName().endsWith(".zip")) {
try {
webClassPath.add(file.toURL());
} catch (MalformedURLException e) {
logger.warning("War path bad: " + file, e);
}
}
}
}
// create the class loader
URL[] webUrls = webClassPath.toArray(new URL[]{});
ClassLoader warClassLoader = new TemporaryClassLoader(webUrls, appClassLoader);
// create web module
WebModule webModule = new WebModule(webApp, webContextRoots.get(moduleName), warClassLoader, warFile.getAbsolutePath(), moduleName);
webModule.getAltDDs().putAll(descriptors);
appModule.getWebModules().add(webModule);
} catch (OpenEJBException e) {
logger.error("Unable to load WAR: " + appDir.getAbsolutePath() + ", module: " + moduleName + ". Exception: " + e.getMessage(), e);
}
}
// Persistence Units
addPersistenceUnits(appModule, classLoader, urls);
return appModule;
} catch (OpenEJBException e) {
logger.error("Unable to load EAR: " + jarFile.getAbsolutePath(), e);
throw e;
}
} else if (EjbModule.class.equals(moduleClass)) {
// read the ejb-jar.xml file
Map<String, URL> descriptors = getDescriptors(baseUrl);
EjbJar ejbJar = null;
if (descriptors.containsKey("ejb-jar.xml")){
ejbJar = ReadDescriptors.readEjbJar(descriptors.get("ejb-jar.xml"));
}
// create the EJB Module
EjbModule ejbModule = new EjbModule(classLoader, jarFile.getAbsolutePath(), ejbJar, null);
ejbModule.getAltDDs().putAll(descriptors);
// wrap the EJB Module with an Application Module
AppModule appModule = new AppModule(classLoader, ejbModule.getJarLocation());
appModule.getEjbModules().add(ejbModule);
// Persistence Units
addPersistenceUnits(appModule, classLoader, baseUrl);
return appModule;
} else if (ConnectorModule.class.equals(moduleClass)) {
// unpack the rar file
File rarFile = new File(baseUrl.getPath());
rarFile = unpack(rarFile);
baseUrl = getFileUrl(rarFile);
// read the ra.xml file
Map<String, URL> descriptors = getDescriptors(baseUrl);
Connector connector = null;
if (descriptors.containsKey("ra.xml")){
connector = ReadDescriptors.readConnector(descriptors.get("ra.xml"));
}
// find the nested jar files