public void addGBeans(EARContext earContext, Module module, Bundle earBundle, Collection repositories) throws DeploymentException {
AppClientModule appClientModule = (AppClientModule) module;
JarFile moduleFile = module.getModuleFile();
ApplicationClientType appClient = (ApplicationClientType) appClientModule.getSpecDD();
GerApplicationClientType geronimoAppClient = (GerApplicationClientType) appClientModule.getVendorDD();
//First, the silly gbean on the server that says there's an app client
// 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
GBeanData appClientModuleGBeanData = new GBeanData(appClientModuleName, J2EEAppClientModuleImpl.class);
try {
appClientModuleGBeanData.setReferencePattern("J2EEServer", earContext.getServerName());
if (!module.isStandAlone()) {
appClientModuleGBeanData.setReferencePattern("J2EEApplication", earContext.getModuleName());
}
} 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);
}
//Now, the gbeans for the actual remote app client
EARContext appClientDeploymentContext = appClientModule.getEarContext();
//Share the ejb info with the ear.
//TODO this might be too much, but I don't want to impose a dependency on geronimo-openejb to get
//EjbModuleBuilder.EarData.class
Map<EARContext.Key, Object> generalData = earContext.getGeneralData();
for (Map.Entry<EARContext.Key, Object> entry : generalData.entrySet()) {
EARContext.Key key = entry.getKey();
if (key.getClass().getName().startsWith("org.apache.geronimo.openejb.deployment.EjbModuleBuilder$EarData")) {
appClientDeploymentContext.getGeneralData().put(key, entry.getValue());
break;
}
}
// Create a Module ID Builder defaulting to similar settings to use for any children we create
ModuleIDBuilder idBuilder = new ModuleIDBuilder();
idBuilder.setDefaultGroup(appClientModule.getEnvironment().getConfigId().getGroupId());
idBuilder.setDefaultVersion(appClientModule.getEnvironment().getConfigId().getVersion());
try {
try {
//register the message destinations in the app client ear context.
namingBuilders.initContext(appClient, geronimoAppClient, appClientModule);
// 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(), e);
}
// add manifest class path entries to the app client context
addManifestClassPath(appClientDeploymentContext, appClientModule.getEarFile(), moduleFile, moduleBase);
// get the classloader
Bundle appClientClassBundle = appClientDeploymentContext.getDeploymentBundle();
// pop in all the gbeans declared in the geronimo app client file
if (geronimoAppClient != null) {
serviceBuilder.build(geronimoAppClient, appClientDeploymentContext, appClientDeploymentContext);
//deploy the resource adapters specified in the geronimo-application.xml
for (ConnectorModule connectorModule : appClientModule.getResourceModules()) {
getConnectorModuleBuilder().addGBeans(appClientDeploymentContext, connectorModule, appClientClassBundle, repositories);
}
}
//Holder may be loaded in the "client" module classloader here, whereas
//NamingBuilder.INJECTION_KEY.get(buildingContext) returns a Holder loaded in the j2ee-server classloader.
Object holder;
// add the app client static jndi provider
//TODO track resource ref shared and app managed security
AbstractName jndiContextName = earContext.getNaming().createChildName(appClientDeploymentContext.getModuleName(), "StaticJndiContext", "StaticJndiContext");
GBeanData jndiContextGBeanData = new GBeanData(jndiContextName, StaticJndiContextPlugin.class);
try {
Map<EARContext.Key, Object> buildingContext = new HashMap<EARContext.Key, Object>();
buildingContext.put(NamingBuilder.GBEAN_NAME_KEY, jndiContextName);
Configuration localConfiguration = appClientDeploymentContext.getConfiguration();
Configuration remoteConfiguration = earContext.getConfiguration();
if (!appClient.getMetadataComplete()) {
// Create a classfinder and populate it for the naming builder(s). The absence of a
// classFinder in the module will convey whether metadata-complete is set
// (or not)
appClientModule.setClassFinder(createAppClientClassFinder(appClient, appClientModule));
}
Map<JndiKey, Map<String, Object>> contexts = NamingBuilder.JNDI_KEY.get(earContext.getGeneralData());
Map<JndiKey, Map<String, Object>> clientContexts = new HashMap<JndiKey, Map<String, Object>>(contexts);
getJndiContext(clientContexts, JndiScope.module).put("module/ModuleName", module.getName());
buildingContext.put(NamingBuilder.JNDI_KEY, clientContexts);
namingBuilders.buildNaming(appClient, geronimoAppClient, appClientModule, buildingContext);
if (!appClient.getMetadataComplete()) {
appClient.setMetadataComplete(true);
module.setOriginalSpecDD(module.getSpecDD().toString());
}
//n the server
appClientModuleGBeanData.setAttribute("deploymentDescriptor", appClientModule.getOriginalSpecDD());
//in the app client
holder = NamingBuilder.INJECTION_KEY.get(buildingContext);
jndiContextGBeanData.setAttribute("context", NamingBuilder.JNDI_KEY.get(buildingContext));
} catch (DeploymentException e) {
throw e;
} catch (Exception e) {
throw new DeploymentException("Unable to construct jndi context for AppClientModule GBean " +
appClientModule.getName(), e);
}
appClientDeploymentContext.addGBean(jndiContextGBeanData);
// finally add the app client container
AbstractName appClientContainerName = appClientDeploymentContext.getModuleName();
GBeanData appClientContainerGBeanData = new GBeanData(appClientContainerName, AppClientContainer.class);
try {
appClientContainerGBeanData.setAttribute("mainClassName", appClientModule.getMainClassName());
appClientContainerGBeanData.setAttribute("appClientModuleName", appClientModuleName);
String callbackHandlerClassName = null;
if (appClient.isSetCallbackHandler()) {
callbackHandlerClassName = appClient.getCallbackHandler().getStringValue().trim();
}
if (geronimoAppClient.isSetCallbackHandler()) {
callbackHandlerClassName = geronimoAppClient.getCallbackHandler().trim();
}
String realmName = null;