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;
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 (JAVAEE 5 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
GBeanData appClientModuleGBeanData = new GBeanData(appClientModuleName, J2EEAppClientModuleImpl.GBEAN_INFO);
try {
appClientModuleGBeanData.setReferencePattern("J2EEServer", earContext.getServerName());
if (!module.isStandAlone()) {
appClientModuleGBeanData.setReferencePattern("J2EEApplication", 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();
// 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.
namingBuilders.initContext(appClient, geronimoAppClient, appClientDeploymentContext.getConfiguration(), earContext.getConfiguration(), 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());
}
// 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) {
serviceBuilder.build(geronimoAppClient, appClientDeploymentContext, appClientDeploymentContext);
//deploy the resource adapters specified in the geronimo-application.xml
for (Iterator resources = appClientModule.getResourceModules().iterator(); resources.hasNext();) {
ConnectorModule connectorModule = (ConnectorModule) resources.next();
getConnectorModuleBuilder().addGBeans(appClientDeploymentContext, connectorModule, appClientClassLoader, repositories);
}
}
// 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.GBEAN_INFO);
try {
Map buildingContext = new HashMap();
buildingContext.put(NamingBuilder.JNDI_KEY, new HashMap());
buildingContext.put(NamingBuilder.GBEAN_NAME_KEY, jndiContextName);
Configuration localConfiguration = appClientDeploymentContext.getConfiguration();
Configuration remoteConfiguration = earContext.getConfiguration();
namingBuilders.buildNaming(appClient, geronimoAppClient, localConfiguration, remoteConfiguration, appClientModule, buildingContext);
jndiContextGBeanData.setAttribute("context", buildingContext.get(NamingBuilder.JNDI_KEY));
} catch (DeploymentException e) {
throw e;
} catch (Exception e) {
throw new DeploymentException("Unable to construct jndi context for AppClientModule GBean", e);
}
appClientDeploymentContext.addGBean(jndiContextGBeanData);
// finally add the app client container
AbstractName appClientContainerName = appClientDeploymentContext.getModuleName();
GBeanData appClientContainerGBeanData = new GBeanData(appClientContainerName, AppClientContainer.GBEAN_INFO);
try {
appClientContainerGBeanData.setAttribute("mainClassName", mainClasss);
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;
if (geronimoAppClient.isSetRealmName()) {
realmName = geronimoAppClient.getRealmName().trim();
}
if (callbackHandlerClassName != null && realmName == null) {
throw new DeploymentException("You must specify a realm name with the callback handler");
}
if (realmName != null) {
appClientContainerGBeanData.setAttribute("realmName", realmName);
appClientContainerGBeanData.setAttribute("callbackHandlerClassName", callbackHandlerClassName);
} else if (geronimoAppClient.isSetDefaultPrincipal()) {
DefaultPrincipal defaultPrincipal = getSecurityBuilder().buildDefaultPrincipal(geronimoAppClient.getDefaultPrincipal());
appClientContainerGBeanData.setAttribute("defaultPrincipal", defaultPrincipal);
}
appClientContainerGBeanData.setReferencePattern("JNDIContext", jndiContextName);
} catch (Exception e) {
throw new DeploymentException("Unable to initialize AppClientModule GBean", e);