public void initContext(EARContext earContext, Module clientModule, ClassLoader cl) {
}
public void addGBeans(EARContext earContext, Module module, ClassLoader earClassLoader, Collection repositories) throws DeploymentException {
AppClientModule appClientModule = (AppClientModule) module;
ApplicationClientType appClient = (ApplicationClientType) appClientModule.getSpecDD();
GerApplicationClientType geronimoAppClient = (GerApplicationClientType) appClientModule.getVendorDD();
// get the app client main class
JarFile moduleFile = module.getModuleFile();
String mainClasss;
// String classPath = null;
try {
Manifest manifest = moduleFile.getManifest();
if (manifest == null) {
throw new DeploymentException("App client module jar does not contain a manifest: " + moduleFile.getName());
}
mainClasss = manifest.getMainAttributes().getValue(Attributes.Name.MAIN_CLASS);
if (mainClasss == null) {
throw new DeploymentException("App client module jar does not have Main-Class defined in the manifest: " + moduleFile.getName());
}
String classPath = manifest.getMainAttributes().getValue(Attributes.Name.CLASS_PATH);
if (module.isStandAlone() && classPath != null) {
throw new DeploymentException("Manifest class path entry is not allowed in a standalone jar (J2EE 1.4 Section 8.2)");
}
} catch (IOException e) {
throw new DeploymentException("Could not get manifest from app client module: " + moduleFile.getName());
}
// generate the object name for the app client
AbstractName appClientModuleName = appClientModule.getModuleName();
// create a gbean for the app client module and add it to the ear
Map componentContext;
GBeanData appClientModuleGBeanData = new GBeanData(appClientModuleName, J2EEAppClientModuleImpl.GBEAN_INFO);
try {
appClientModuleGBeanData.setReferencePatterns("J2EEServer", Collections.singleton(earContext.getServerName()));
if (!module.isStandAlone()) {
appClientModuleGBeanData.setReferencePatterns("J2EEApplication", Collections.singleton(earContext.getModuleName()));
}
appClientModuleGBeanData.setAttribute("deploymentDescriptor", appClientModule.getOriginalSpecDD());
} catch (Exception e) {
throw new DeploymentException("Unable to initialize AppClientModule GBean", e);
}
try {
earContext.addGBean(appClientModuleGBeanData);
} catch (GBeanAlreadyExistsException e) {
throw new DeploymentException("Could not add application client module gbean to configuration", e);
}
EARContext appClientDeploymentContext = appClientModule.getEarContext();
// ConfigurationData appClientConfigurationData = null;
// Create a Module ID Builder defaulting to similar settings to use for any children we create
ModuleIDBuilder idBuilder = new ModuleIDBuilder();
idBuilder.setDefaultGroup(appClientModule.getClientEnvironment().getConfigId().getGroupId());
idBuilder.setDefaultVersion(appClientModule.getClientEnvironment().getConfigId().getVersion());
try {
try {
//register the message destinations in the app client ear context.
MessageDestinationType[] messageDestinations = appClient.getMessageDestinationArray();
GerMessageDestinationType[] gerMessageDestinations = geronimoAppClient.getMessageDestinationArray();
ENCConfigBuilder.registerMessageDestinations(appClientDeploymentContext.getRefContext(), appClientModule.getName(), messageDestinations, gerMessageDestinations);
// extract the client Jar file into a standalone packed jar file and add the contents to the output
URI moduleBase = new URI(appClientModule.getTargetPath());
try {
appClientDeploymentContext.addIncludeAsPackedJar(moduleBase, moduleFile);
} catch (IOException e) {
throw new DeploymentException("Unable to copy app client module jar into configuration: " + moduleFile.getName());
}
// add manifest class path entries to the app client context
addManifestClassPath(appClientDeploymentContext, appClientModule.getEarFile(), moduleFile, moduleBase);
// get the classloader
ClassLoader appClientClassLoader = appClientDeploymentContext.getClassLoader();
// pop in all the gbeans declared in the geronimo app client file
if (geronimoAppClient != null) {
GbeanType[] gbeans = geronimoAppClient.getGbeanArray();
ServiceConfigBuilder.addGBeans(gbeans, appClientClassLoader, appClientDeploymentContext.getModuleName(), appClientDeploymentContext);
//deploy the resource adapters specified in the geronimo-application.xml
Collection resourceModules = new ArrayList();
try {
GerResourceType[] resources = geronimoAppClient.getResourceArray();
for (int i = 0; i < resources.length; i++) {
GerResourceType resource = resources[i];
String path;
JarFile connectorFile;
if (resource.isSetExternalRar()) {
path = resource.getExternalRar().trim();
Artifact artifact = Artifact.create(path);
File file = null;
for (Iterator iterator = repositories.iterator(); iterator.hasNext();) {
Repository repository = (Repository) iterator.next();
if (repository.contains(artifact)) {
file = repository.getLocation(artifact);
break;
}
}
if (file == null) {
throw new DeploymentException("Missing rar in repositories: " + path);
}
try {
connectorFile = new JarFile(file);
} catch (IOException e) {
throw new DeploymentException("Could not access rar contents", e);
}
} else {
path = resource.getInternalRar();
try {
connectorFile = new NestedJarFile(appClientModule.getEarFile(), path);
} catch (IOException e) {
throw new DeploymentException("Could not locate connector inside ear", e);
}
}
XmlObject connectorPlan = resource.getConnector();
Module connectorModule = getConnectorModuleBuilder().createModule(connectorPlan, connectorFile, path, null, appClientModule.getClientEnvironment(), null, appClientDeploymentContext.getModuleName(), earContext.getNaming(), idBuilder);
resourceModules.add(connectorModule);
//TODO configStore == null is fishy, consider moving these stages for connectors into the corresponding stages for this module.
getConnectorModuleBuilder().installModule(connectorFile, appClientDeploymentContext, connectorModule, null, null, repositories);
}
//the install step could have added more dependencies... we need a new cl.