public void init(DeploymentInfo di) throws DeploymentException {
try
{
log.info("Init J2EE application: " + di.url);
InputStream in = di.localCl.getResourceAsStream("META-INF/application.xml");
if( in == null )
throw new DeploymentException("No META-INF/application.xml found");
/* Don't require validation of application.xml since an ear may
just contain a jboss sar specified in the jboss-app.xml descriptor.
*/
XmlFileLoader xfl = new XmlFileLoader(false);
Element root = xfl.getDocument(in, "META-INF/application.xml").getDocumentElement();
J2eeApplicationMetaData metaData = new J2eeApplicationMetaData(root);
di.metaData = metaData;
in.close();
// Check for a jboss-app.xml descriptor
in = di.localCl.getResourceAsStream("META-INF/jboss-app.xml");
if( in != null )
{
Element jbossApp = xfl.getDocument(in, "META-INF/jboss-app.xml").getDocumentElement();
in.close();
// Import module/service archives to metadata
metaData.importXml(jbossApp, true);
// Check for a loader-repository for scoping
Element loader = MetaData.getOptionalChild(jbossApp, "loader-repository");
initLoaderRepository(di, loader);
}
// resolve the watch
if (di.url.getProtocol().equals("file"))
{
File file = new File(di.url.getFile());
// If not directory we watch the package
if (!file.isDirectory())
{
di.watch = di.url;
}
// If directory we watch the xml files
else
{
di.watch = new URL(di.url, "META-INF/application.xml");
}
}
else
{
// We watch the top only, no directory support
di.watch = di.url;
}
// Obtain the sub-deployment list
File parentDir = null;
HashMap extractedJars = new HashMap();
if (di.isDirectory)
{
parentDir = new File(di.localUrl.getFile());
}
else
{
/* Extract each entry so that deployment modules can be processed
and any manifest entries referenced by the ear modules are located
in the same unpacked directory structure.
*/
String urlPrefix = "jar:" + di.localUrl + "!/";
JarFile jarFile = new JarFile(di.localUrl.getFile());
// For each entry, test if deployable, if so
// extract it and store the related URL in map
for (Enumeration e = jarFile.entries(); e.hasMoreElements();)
{
JarEntry entry = (JarEntry)e.nextElement();
String name = entry.getName();
try
{
URL url = new URL(urlPrefix + name);
if (isDeployable(name, url))
{
// Obtain a jar url for the nested jar
URL nestedURL = JarUtils.extractNestedJar(url, this.tempDeployDir);
// and store in it in map
extractedJars.put(name, nestedURL);
}
}
catch (MalformedURLException mue)
{
log.warn("Jar entry invalid. Ignoring: " + name, mue);
}
catch (IOException ex)
{
log.warn("Failed to extract nested jar. Ignoring: " + name, ex);
}
}
}
// Create subdeployments for the ear modules
for (Iterator iter = metaData.getModules(); iter.hasNext(); )
{
J2eeModuleMetaData mod = (J2eeModuleMetaData)iter.next();
String fileName = mod.getFileName();
if (fileName != null && (fileName = fileName.trim()).length() > 0)
{
DeploymentInfo sub = null;
if (di.isDirectory)
{
File f = new File(parentDir, fileName);
sub = new DeploymentInfo(f.toURL(), di, getServer());
}
else
{
// The nested jar url was placed into extractedJars above
URL nestedURL = (URL) extractedJars.get(fileName);
if( nestedURL == null )
throw new DeploymentException("Failed to find module file: "+fileName);
sub = new DeploymentInfo(nestedURL, di, getServer());
}
// Set the context-root on web modules
if( mod.isWeb() )
sub.webContext = mod.getWebContext();
log.debug("Deployment Info: " + sub + ", isDirectory: " + sub.isDirectory);
}
}
}
catch (DeploymentException e)
{
throw e;
}
catch (Exception e)
{
throw new DeploymentException("Error in accessing application metadata: ", e);
}
super.init(di);
}
|