Search in sources :

Example 11 with ModuleContext

use of org.apache.openejb.ModuleContext 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)

Example 12 with ModuleContext

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

the class LocalClientRunner method createDeployment.

private BeanContext createDeployment(final Class<?> testClass) {
    try {
        final AppContext appContext = new AppContext("", SystemInstance.get(), testClass.getClassLoader(), new IvmContext(), new IvmContext(), false);
        final ModuleContext moduleContext = new ModuleContext("", null, "", appContext, new IvmContext(), null);
        return new BeanContext(null, new IvmContext(), moduleContext, testClass, null, null, null, null, null, null, null, null, null, BeanType.MANAGED, false, false);
    } catch (final SystemException e) {
        throw new IllegalStateException(e);
    }
}
Also used : BeanContext(org.apache.openejb.BeanContext) IvmContext(org.apache.openejb.core.ivm.naming.IvmContext) SystemException(org.apache.openejb.SystemException) AppContext(org.apache.openejb.AppContext) ModuleContext(org.apache.openejb.ModuleContext)

Example 13 with ModuleContext

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

the class AppNamingReadOnlyTest method getMockBeanContextsList.

private List<BeanContext> getMockBeanContextsList() throws SystemException, URISyntaxException {
    IvmContext context = new IvmContext();
    AppContext mockAppContext = new AppContext("appId", SystemInstance.get(), this.getClass().getClassLoader(), context, context, false);
    ModuleContext mockModuleContext = new ModuleContext("moduleId", new URI(""), "uniqueId", mockAppContext, context, this.getClass().getClassLoader());
    BeanContext mockBeanContext = new BeanContext("test", context, mockModuleContext, this.getClass(), this.getClass(), new HashMap<String, String>());
    List<BeanContext> beanContextsList = new ArrayList<BeanContext>();
    beanContextsList.add(mockBeanContext);
    return beanContextsList;
}
Also used : BeanContext(org.apache.openejb.BeanContext) IvmContext(org.apache.openejb.core.ivm.naming.IvmContext) AppContext(org.apache.openejb.AppContext) ModuleContext(org.apache.openejb.ModuleContext) ArrayList(java.util.ArrayList) URI(java.net.URI)

Example 14 with ModuleContext

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

the class Timers method all.

public static Collection<Timer> all() {
    final ThreadContext threadContext = ThreadContext.getThreadContext();
    final BeanContext beanContext = threadContext.getBeanContext();
    final ModuleContext module = beanContext.getModuleContext();
    final Collection<Timer> timers = new HashSet<>();
    for (final BeanContext c : module.getAppContext().getBeanContexts()) {
        if (c.getModuleContext() == module) {
            // filter by module
            if (c.getComponentType() != BeanType.STATEFUL) {
                final TimerService timerService = getTimerService(null, c, true);
                if (timerService == null) {
                    continue;
                }
                final Collection<Timer> beanTimers = timerService.getTimers();
                timers.addAll(beanTimers);
            } else {
                // for all instances
                final TimerService timerService = getTimerService(null, c, true);
                if (timerService == null) {
                    continue;
                }
                final Collection<Timer> beanTimers = timerService.getTimers();
                timers.addAll(beanTimers);
            }
        }
    }
    return timers;
}
Also used : BeanContext(org.apache.openejb.BeanContext) Timer(javax.ejb.Timer) ThreadContext(org.apache.openejb.core.ThreadContext) ModuleContext(org.apache.openejb.ModuleContext) TimerService(javax.ejb.TimerService) HashSet(java.util.HashSet)

Example 15 with ModuleContext

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

the class ApplicationPropertiesTest method assertContexts.

private void assertContexts(final ContainerSystem containerSystem) {
    final BeanContext beanContext = containerSystem.getBeanContext("WidgetBean");
    final ModuleContext moduleContext = beanContext.getModuleContext();
    final AppContext appContext = moduleContext.getAppContext();
    {
        // Assert as Properties
        // AppContext should have color property
        assertProperty(appContext.getProperties(), "color", "orange");
        // BeanContext and ModuleContext should not
        assertNoProperty(beanContext.getProperties(), "color");
        assertNoProperty(moduleContext.getProperties(), "color");
        // Try all the above again with mixed case
        assertProperty(appContext.getProperties(), "coLOr", "orange");
        assertNoProperty(beanContext.getProperties(), "coLOr");
        assertNoProperty(moduleContext.getProperties(), "coLOr");
    }
    {
        // Assert as Options
        // AppContext should have color option
        assertOption(appContext.getOptions(), "color", "orange");
        // BeanContext and ModuleContext should inherit AppContext color
        assertOption(beanContext.getOptions(), "color", "orange");
        assertOption(moduleContext.getOptions(), "color", "orange");
        // Try all the above again using mixed case
        assertOption(appContext.getOptions(), "coLoR", "orange");
        assertOption(moduleContext.getOptions(), "coLoR", "orange");
        assertOption(beanContext.getOptions(), "coLoR", "orange");
    }
}
Also used : BeanContext(org.apache.openejb.BeanContext) AppContext(org.apache.openejb.AppContext) ModuleContext(org.apache.openejb.ModuleContext)

Aggregations

ModuleContext (org.apache.openejb.ModuleContext)15 BeanContext (org.apache.openejb.BeanContext)14 AppContext (org.apache.openejb.AppContext)13 Context (javax.naming.Context)4 HashMap (java.util.HashMap)3 ArrayList (java.util.ArrayList)2 HashSet (java.util.HashSet)2 TimerService (javax.ejb.TimerService)2 Injection (org.apache.openejb.Injection)2 OpenEJBException (org.apache.openejb.OpenEJBException)2 IvmContext (org.apache.openejb.core.ivm.naming.IvmContext)2 Method (java.lang.reflect.Method)1 URI (java.net.URI)1 Properties (java.util.Properties)1 EJBContext (javax.ejb.EJBContext)1 TimedObject (javax.ejb.TimedObject)1 Timer (javax.ejb.Timer)1 InitialContext (javax.naming.InitialContext)1 NameAlreadyBoundException (javax.naming.NameAlreadyBoundException)1 NamingException (javax.naming.NamingException)1