for (PersistenceUnitInfo info : appInfo.persistenceUnits) {
try {
EntityManagerFactory factory = persistenceBuilder.createEntityManagerFactory(info, classLoader);
emfLinkResolver.add(info.persistenceUnitRootUrl, info.name, factory);
} catch (Exception e) {
throw new OpenEJBException(e);
}
}
// EJB
EjbJarBuilder ejbJarBuilder = new EjbJarBuilder(props, classLoader);
for (EjbJarInfo ejbJar : appInfo.ejbJars) {
HashMap<String, DeploymentInfo> deployments = ejbJarBuilder.build(ejbJar, emfLinkResolver);
JaccPermissionsBuilder jaccPermissionsBuilder = new JaccPermissionsBuilder();
PolicyContext policyContext = jaccPermissionsBuilder.build(ejbJar, deployments);
if (System.getProperty("duct tape") == null) {
jaccPermissionsBuilder.install(policyContext);
}
MethodTransactionBuilder methodTransactionBuilder = new MethodTransactionBuilder();
methodTransactionBuilder.build(deployments, ejbJar.methodTransactions);
for (DeploymentInfo deploymentInfo : deployments.values()) {
containerSystem.addDeployment(deploymentInfo);
}
jndiBuilder.build(ejbJar, deployments);
// setup timers - must be after transaction attibutes are set
for (DeploymentInfo deploymentInfo : deployments.values()) {
CoreDeploymentInfo coreDeploymentInfo = (CoreDeploymentInfo) deploymentInfo;
if (coreDeploymentInfo.getComponentType() != BeanType.STATEFUL) {
Method ejbTimeout = coreDeploymentInfo.getEjbTimeout();
if (ejbTimeout != null) {
// If user set the tx attribute to RequiresNew change it to Required so a new transaction is not started
if (coreDeploymentInfo.getTransactionAttribute(ejbTimeout) == CoreDeploymentInfo.TX_REQUIRES_NEW) {
coreDeploymentInfo.setMethodTransactionAttribute(ejbTimeout, "Required");
}
// Create the timer
EjbTimerServiceImpl timerService = new EjbTimerServiceImpl(coreDeploymentInfo);
coreDeploymentInfo.setEjbTimerService(timerService);
} else {
coreDeploymentInfo.setEjbTimerService(new NullEjbTimerServiceImpl());
}
}
}
// process application exceptions
for (ApplicationExceptionInfo exceptionInfo : ejbJar.applicationException) {
try {
Class exceptionClass = classLoader.loadClass(exceptionInfo.exceptionClass);
for (DeploymentInfo deploymentInfo : deployments.values()) {
CoreDeploymentInfo coreDeploymentInfo = (CoreDeploymentInfo) deploymentInfo;
coreDeploymentInfo.addApplicationException(exceptionClass, exceptionInfo.rollback);
}
} catch (ClassNotFoundException e) {
logger.error("Application class invalid: class=" + exceptionInfo.exceptionClass + ". Exception: " + e.getMessage(), e);
}
}
// now that everything is configured, deploy to the container
ejbJarBuilder.deploy(deployments);
for (EnterpriseBeanInfo beanInfo : ejbJar.enterpriseBeans) {
logger.info("Created Ejb(deployment-id="+beanInfo.ejbDeploymentId+", ejb-name="+beanInfo.ejbName+", container="+beanInfo.containerId+")");
}
}
// App Client
for (ClientInfo clientInfo : appInfo.clients) {
JndiEncBuilder jndiEncBuilder = new JndiEncBuilder(clientInfo.jndiEnc, clientInfo.moduleId);
jndiEncBuilder.setUseCrossClassLoaderRef(false);
Context context = (Context) jndiEncBuilder.build().lookup("env");
containerSystem.getJNDIContext().bind("java:openejb/client/" + clientInfo.moduleId + "/comp/env", context);
if (clientInfo.codebase != null) {
containerSystem.getJNDIContext().bind("java:openejb/client/" + clientInfo.moduleId + "/comp/path", clientInfo.codebase);
}
if (clientInfo.mainClass != null) {
containerSystem.getJNDIContext().bind("java:openejb/client/" + clientInfo.moduleId + "/comp/mainClass", clientInfo.mainClass);
}
if (clientInfo.callbackHandler != null) {
containerSystem.getJNDIContext().bind("java:openejb/client/" + clientInfo.moduleId + "/comp/callbackHandler", clientInfo.callbackHandler);
}
ArrayList<Injection> injections = new ArrayList<Injection>();
JndiEncInfo jndiEnc = clientInfo.jndiEnc;
for (EjbReferenceInfo info : jndiEnc.ejbReferences) {
for (InjectionInfo target : info.targets) {
try {
Class targetClass = classLoader.loadClass(target.className);
Injection injection = new Injection(info.referenceName, target.propertyName, targetClass);
injections.add(injection);
} catch (ClassNotFoundException e) {
logger.error("Injection Target invalid: class=" + target.className + ", name=" + target.propertyName + ". Exception: " + e.getMessage(), e);
}
}
}
for (ResourceReferenceInfo info : jndiEnc.resourceRefs) {
for (InjectionInfo target : info.targets) {
try {
Class targetClass = classLoader.loadClass(target.className);
Injection injection = new Injection(info.referenceName, target.propertyName, targetClass);
injections.add(injection);
} catch (ClassNotFoundException e) {
logger.error("Injection Target invalid: class=" + target.className + ", name=" + target.propertyName + ". Exception: " + e.getMessage(), e);
}
}
}
for (ResourceEnvReferenceInfo info : jndiEnc.resourceEnvRefs) {
for (InjectionInfo target : info.targets) {
try {
Class targetClass = classLoader.loadClass(target.className);
Injection injection = new Injection(info.resourceEnvRefName, target.propertyName, targetClass);
injections.add(injection);
} catch (ClassNotFoundException e) {
logger.error("Injection Target invalid: class=" + target.className + ", name=" + target.propertyName + ". Exception: " + e.getMessage(), e);
}
}
}
containerSystem.getJNDIContext().bind("java:openejb/client/" + clientInfo.moduleId + "/comp/injections", injections);
}
// WebApp
WebAppBuilder webAppBuilder = SystemInstance.get().getComponent(WebAppBuilder.class);
if (webAppBuilder != null) {
for (WebAppInfo webAppInfo : appInfo.webApps) {
webAppBuilder.deploy(webAppInfo, emfLinkResolver);
}
}
logger.info("Deployed Application(path="+appInfo.jarPath+")");
deployedApplications.put(appInfo.jarPath, appInfo);
} catch (Throwable t) {
try {
destroyApplication(appInfo);
} catch (Exception e1) {
logger.debug("App failing deployment may not have undeployed cleanly: "+appInfo.jarPath, e1);
}
throw new OpenEJBException("Creating application failed: "+appInfo.jarPath, t);
}
}