Search in sources :

Example 1 with ModuleTestContext

use of org.apache.openejb.ModuleTestContext in project tomee by apache.

the class EjbJarBuilder method build.

public HashMap<String, BeanContext> build(final EjbJarInfo ejbJar, final Collection<Injection> appInjections, final ClassLoader classLoader) throws OpenEJBException {
    final InjectionBuilder injectionBuilder = new InjectionBuilder(classLoader);
    final List<Injection> moduleInjections = injectionBuilder.buildInjections(ejbJar.moduleJndiEnc);
    moduleInjections.addAll(appInjections);
    final Context moduleJndiContext = new JndiEncBuilder(ejbJar.moduleJndiEnc, moduleInjections, null, ejbJar.moduleName, ejbJar.moduleUri, ejbJar.uniqueId, classLoader, context.getProperties()).build(JndiEncBuilder.JndiScope.module);
    final HashMap<String, BeanContext> deployments = new HashMap<String, BeanContext>();
    final ModuleContext moduleContext = !ejbJar.properties.containsKey("openejb.test.module") ? new ModuleContext(ejbJar.moduleName, ejbJar.moduleUri, ejbJar.uniqueId, context, moduleJndiContext, classLoader) : new ModuleTestContext(ejbJar.moduleName, ejbJar.moduleUri, ejbJar.uniqueId, context, moduleJndiContext, classLoader);
    moduleContext.getProperties().putAll(ejbJar.properties);
    final InterceptorBindingBuilder interceptorBindingBuilder = new InterceptorBindingBuilder(classLoader, ejbJar);
    final MethodScheduleBuilder methodScheduleBuilder = new MethodScheduleBuilder();
    for (final EnterpriseBeanInfo ejbInfo : ejbJar.enterpriseBeans) {
        final ClassLoader loader = Thread.currentThread().getContextClassLoader();
        Thread.currentThread().setContextClassLoader(moduleContext.getClassLoader());
        try {
            final EnterpriseBeanBuilder deploymentBuilder = new EnterpriseBeanBuilder(ejbInfo, moduleContext, moduleInjections);
            final BeanContext bean = deploymentBuilder.build();
            interceptorBindingBuilder.build(bean, ejbInfo);
            methodScheduleBuilder.build(bean, ejbInfo);
            deployments.put(ejbInfo.ejbDeploymentId, bean);
            // TODO: replace with get() on application context or parent
            final Container container = (Container) props.get(ejbInfo.containerId);
            if (container == null) {
                throw new IllegalStateException("Container does not exist: " + ejbInfo.containerId + ".  Referenced by deployment: " + bean.getDeploymentID());
            }
            // Don't deploy to the container, yet. That will be done by deploy() once Assembler as finished configuring the DeploymentInfo
            bean.setContainer(container);
        } catch (final Throwable e) {
            throw new OpenEJBException("Error building bean '" + ejbInfo.ejbName + "'.  Exception: " + e.getClass() + ": " + e.getMessage(), e);
        } finally {
            Thread.currentThread().setContextClassLoader(loader);
        }
    }
    return deployments;
}
Also used : BeanContext(org.apache.openejb.BeanContext) ModuleTestContext(org.apache.openejb.ModuleTestContext) AppContext(org.apache.openejb.AppContext) Context(javax.naming.Context) ModuleContext(org.apache.openejb.ModuleContext) OpenEJBException(org.apache.openejb.OpenEJBException) HashMap(java.util.HashMap) Injection(org.apache.openejb.Injection) BeanContext(org.apache.openejb.BeanContext) ModuleTestContext(org.apache.openejb.ModuleTestContext) Container(org.apache.openejb.Container) ModuleContext(org.apache.openejb.ModuleContext)

Aggregations

HashMap (java.util.HashMap)1 Context (javax.naming.Context)1 AppContext (org.apache.openejb.AppContext)1 BeanContext (org.apache.openejb.BeanContext)1 Container (org.apache.openejb.Container)1 Injection (org.apache.openejb.Injection)1 ModuleContext (org.apache.openejb.ModuleContext)1 ModuleTestContext (org.apache.openejb.ModuleTestContext)1 OpenEJBException (org.apache.openejb.OpenEJBException)1