null);
}
private ApplicationInfo getEarPlan(File planFile, JarFile earFile, ModuleIDBuilder idBuilder) throws DeploymentException {
String specDD;
ApplicationType application = null;
if (earFile != null) {
try {
URL applicationXmlUrl = DeploymentUtil.createJarURL(earFile, "META-INF/application.xml");
specDD = DeploymentUtil.readAll(applicationXmlUrl);
} catch (Exception e) {
//no application.xml, not for us
return null;
}
//we found something called application.xml in the right place, if we can't parse it it's an error
try {
XmlObject xmlObject = XmlBeansUtil.parse(specDD);
application = convertToApplicationSchema(xmlObject).getApplication();
} catch (XmlException e) {
throw new DeploymentException("Could not parse application.xml", e);
}
}
GerApplicationType gerApplication = null;
try {
// load the geronimo-application.xml from either the supplied plan or from the earFile
XmlObject rawPlan;
try {
if (planFile != null) {
rawPlan = XmlBeansUtil.parse(planFile.toURL(), getClass().getClassLoader());
gerApplication = (GerApplicationType) SchemaConversionUtils.fixGeronimoSchema(rawPlan, APPLICATION_QNAME, GerApplicationType.type);
if (gerApplication == null) {
return null;
}
} else {
URL path = DeploymentUtil.createJarURL(earFile, "META-INF/geronimo-application.xml");
rawPlan = XmlBeansUtil.parse(path, getClass().getClassLoader());
gerApplication = (GerApplicationType) SchemaConversionUtils.fixGeronimoSchema(rawPlan, APPLICATION_QNAME, GerApplicationType.type);
}
} catch (IOException e) {
//TODO isn't this an error?
}
// if we got one extract the validate it otherwise create a default one
if (gerApplication == null) {
gerApplication = createDefaultPlan(application, earFile);
}
} catch (XmlException e) {
throw new DeploymentException(e);
}
EnvironmentType environmentType = gerApplication.getEnvironment();
Environment environment = EnvironmentBuilder.buildEnvironment(environmentType, defaultEnvironment);
idBuilder.resolve(environment, earFile == null ? planFile.getName() : new File(earFile.getName()).getName(), "ear");
// Make this EAR's settings the default for child modules
idBuilder.setDefaultGroup(environment.getConfigId().getGroupId());
idBuilder.setDefaultVersion(environment.getConfigId().getVersion());
Artifact artifact = environment.getConfigId();
AbstractName earName = naming.createRootName(artifact, artifact.toString(), NameFactory.J2EE_APPLICATION);
// get the modules either the application plan or for a stand alone module from the specific deployer
// todo change module so you can extract the real module path back out.. then we can eliminate
// the moduleLocations and have addModules return the modules
Set moduleLocations = new HashSet();
LinkedHashSet modules = new LinkedHashSet();
try {
addModules(earFile, application, gerApplication, moduleLocations, modules, environment, earName, idBuilder);
} catch (Throwable e) {
// close all the modules
for (Iterator iterator = modules.iterator(); iterator.hasNext();) {
Module module = (Module) iterator.next();
module.close();
}
if (e instanceof DeploymentException) {
throw (DeploymentException) e;
} else if (e instanceof RuntimeException) {
throw (RuntimeException) e;
} else if (e instanceof Error) {
throw (Error) e;
}
throw new DeploymentException(e);
}
return new ApplicationInfo(ConfigurationModuleType.EAR,
environment,
earName,
application,
gerApplication,
modules,
moduleLocations,
application == null ? null : application.toString());
}