return test;
}
public DeploymentContext buildConfiguration(boolean inPlaceDeployment, Artifact configId, Object plan, JarFile earFile, Collection configurationStores, ArtifactResolver artifactResolver, ConfigurationStore targetConfigurationStore) throws IOException, DeploymentException {
assert plan != null;
ApplicationInfo applicationInfo = (ApplicationInfo) plan;
EARContext earContext = null;
ConfigurationModuleType applicationType = applicationInfo.getType();
applicationInfo.getEnvironment().setConfigId(configId);
File configurationDir;
try {
configurationDir = targetConfigurationStore.createNewConfigurationDir(configId);
} catch (ConfigurationAlreadyExistsException e) {
throw new DeploymentException(e);
}
ConfigurationManager configurationManager = this.configurationManager;
if (configurationManager == null) {
configurationManager = new SimpleConfigurationManager(configurationStores, artifactResolver, repositories);
}
try {
// Create the output ear context
earContext = new EARContext(configurationDir,
inPlaceDeployment ? DeploymentUtil.toFile(earFile) : null,
applicationInfo.getEnvironment(),
applicationType,
naming,
configurationManager,
repositories,
serverName,
applicationInfo.getBaseName(),
transactionContextManagerObjectName,
connectionTrackerObjectName,
transactionalTimerObjectName,
nonTransactionalTimerObjectName,
corbaGBeanObjectName,
new RefContext(getEjbReferenceBuilder(), getResourceReferenceBuilder(), getServiceReferenceBuilder()));
// Copy over all files that are _NOT_ modules (e.g. META-INF and APP-INF files)
Set moduleLocations = applicationInfo.getModuleLocations();
if (ConfigurationModuleType.EAR == applicationType && earFile != null) {
for (Enumeration e = earFile.entries(); e.hasMoreElements();) {
ZipEntry entry = (ZipEntry) e.nextElement();
String entryName = entry.getName();
boolean addEntry = true;
for (Iterator iter = moduleLocations.iterator(); iter.hasNext();) {
String location = (String) iter.next();
if (entryName.startsWith(location)) {
addEntry = false;
break;
}
}
if (addEntry) {
earContext.addFile(URI.create(entry.getName()), earFile, entry);
}
}
}
GerApplicationType geronimoApplication = (GerApplicationType) applicationInfo.getVendorDD();
// each module installs it's files into the output context.. this is different for each module type
LinkedHashSet modules = applicationInfo.getModules();
for (Iterator iterator = modules.iterator(); iterator.hasNext();) {
Module module = (Module) iterator.next();
getBuilder(module).installModule(earFile, earContext, module, configurationStores, targetConfigurationStore, repositories);
}
earContext.flush();
// give each module a chance to populate the earContext now that a classloader is available
ClassLoader cl = earContext.getClassLoader();
for (Iterator iterator = modules.iterator(); iterator.hasNext();) {
Module module = (Module) iterator.next();
getBuilder(module).initContext(earContext, module, cl);
}
// add gbeans declared in the geronimo-application.xml
if (geronimoApplication != null) {
GbeanType[] gbeans = geronimoApplication.getGbeanArray();
ServiceConfigBuilder.addGBeans(gbeans, cl, earContext.getModuleName(), earContext);
}
// Create the J2EEApplication managed object
if (ConfigurationModuleType.EAR == applicationType) {
GBeanData gbeanData = new GBeanData(earContext.getModuleName(), J2EEApplicationImpl.GBEAN_INFO);
try {
String originalSpecDD = applicationInfo.getOriginalSpecDD();
if (originalSpecDD == null) {
originalSpecDD = "Synthetic EAR";
}
gbeanData.setAttribute("deploymentDescriptor", originalSpecDD);
} catch (Exception e) {
throw new DeploymentException("Error initializing J2EEApplication managed object");
}
gbeanData.setReferencePatterns("Server", new ReferencePatterns(new AbstractNameQuery(J2EEServer.class.getName())));
Map thisApp = Collections.singletonMap(NameFactory.J2EE_APPLICATION, earContext.getModuleName().getNameProperty(NameFactory.J2EE_NAME));
LinkedHashSet resourcePatterns = new LinkedHashSet();
resourcePatterns.add(new AbstractNameQuery(null, filter(thisApp, NameFactory.J2EE_TYPE, NameFactory.JAVA_MAIL_RESOURCE), J2EEResource.class.getName()));
resourcePatterns.add(new AbstractNameQuery(null, filter(thisApp, NameFactory.J2EE_TYPE, NameFactory.JCA_CONNECTION_FACTORY), J2EEResource.class.getName()));
resourcePatterns.add(new AbstractNameQuery(null, filter(thisApp, NameFactory.J2EE_TYPE, NameFactory.JDBC_RESOURCE), J2EEResource.class.getName()));
resourcePatterns.add(new AbstractNameQuery(null, filter(thisApp, NameFactory.J2EE_TYPE, NameFactory.JDBC_DRIVER), J2EEResource.class.getName()));
resourcePatterns.add(new AbstractNameQuery(null, filter(thisApp, NameFactory.J2EE_TYPE, NameFactory.JMS_RESOURCE), J2EEResource.class.getName()));
resourcePatterns.add(new AbstractNameQuery(null, filter(thisApp, NameFactory.J2EE_TYPE, NameFactory.JNDI_RESOURCE), J2EEResource.class.getName()));
resourcePatterns.add(new AbstractNameQuery(null, filter(thisApp, NameFactory.J2EE_TYPE, NameFactory.JTA_RESOURCE), J2EEResource.class.getName()));
resourcePatterns.add(new AbstractNameQuery(null, filter(thisApp, NameFactory.J2EE_TYPE, NameFactory.RMI_IIOP_RESOURCE), J2EEResource.class.getName()));
resourcePatterns.add(new AbstractNameQuery(null, filter(thisApp, NameFactory.J2EE_TYPE, NameFactory.URL_RESOURCE), J2EEResource.class.getName()));
gbeanData.setReferencePatterns("Resources", resourcePatterns);
gbeanData.setReferencePatterns("AppClientModules", new ReferencePatterns(new AbstractNameQuery(null, thisApp, org.apache.geronimo.management.AppClientModule.class.getName())));
gbeanData.setReferencePatterns("EJBModules", new ReferencePatterns(new AbstractNameQuery(null, thisApp, org.apache.geronimo.management.EJBModule.class.getName())));
gbeanData.setReferencePatterns("ResourceAdapterModules", new ReferencePatterns(new AbstractNameQuery(null, thisApp, org.apache.geronimo.management.geronimo.ResourceAdapterModule.class.getName())));
gbeanData.setReferencePatterns("WebModules", new ReferencePatterns(new AbstractNameQuery(null, thisApp, org.apache.geronimo.management.geronimo.WebModule.class.getName())));
earContext.addGBean(gbeanData);
}
//look for application plan security config
if (geronimoApplication != null && geronimoApplication.isSetSecurity()) {
SecurityConfiguration securityConfiguration = SecurityBuilder.buildSecurityConfiguration(geronimoApplication.getSecurity(), cl);
earContext.setSecurityConfiguration(securityConfiguration);
}
//add the JACC gbean if there is a principal-role mapping
if (earContext.getSecurityConfiguration() != null) {
GBeanData roleMapperData = SecurityBuilder.configureRoleMapper(naming, earContext.getModuleName(), earContext.getSecurityConfiguration());
earContext.addGBean(roleMapperData);
GBeanData jaccBeanData = SecurityBuilder.configureApplicationPolicyManager(naming, earContext.getModuleName(), earContext.getContextIDToPermissionsMap(), earContext.getSecurityConfiguration());
jaccBeanData.setReferencePattern("PrincipalRoleMapper", roleMapperData.getAbstractName());
earContext.addGBean(jaccBeanData);
earContext.setJaccManagerName(jaccBeanData.getAbstractName());
}
// each module can now add it's GBeans
for (Iterator iterator = modules.iterator(); iterator.hasNext();) {
Module module = (Module) iterator.next();
getBuilder(module).addGBeans(earContext, module, cl, repositories);
}
// it's the caller's responsibility to close the context...
return earContext;
} catch (GBeanAlreadyExistsException e) {
cleanupContext(earContext, configurationDir);
throw new DeploymentException(e);
} catch (IOException e) {
cleanupContext(earContext, configurationDir);
throw e;
} catch (DeploymentException e) {
cleanupContext(earContext, configurationDir);
throw e;
} catch(RuntimeException e) {
cleanupContext(earContext, configurationDir);
throw e;
} catch(Error e) {
cleanupContext(earContext, configurationDir);
throw e;
} finally {
Set modules = applicationInfo.getModules();
for (Iterator iterator = modules.iterator(); iterator.hasNext();) {
Module module = (Module) iterator.next();
module.close();
}
}