Search in sources :

Example 1 with ContextHandler

use of org.apache.openejb.core.ivm.ContextHandler in project tomee by apache.

the class javaURLContextFactory method getContext.

public static Context getContext() {
    final ThreadContext callContext = ThreadContext.getThreadContext();
    if (callContext == null) {
        final ContainerSystem containerSystem = SystemInstance.get().getComponent(ContainerSystem.class);
        final ClassLoader current = Thread.currentThread().getContextClassLoader();
        final Context globalContext = containerSystem.getJNDIContext();
        if (current == null) {
            return globalContext;
        }
        for (final AppContext appContext : containerSystem.getAppContexts()) {
            for (final WebContext web : appContext.getWebContexts()) {
                // more specific first
                if (current.equals(web.getClassLoader())) {
                    return new ContextHandler(web.getJndiEnc());
                }
            }
            if (current.equals(appContext.getClassLoader())) {
                return new ContextHandler(appContext.getAppJndiContext());
            }
        }
        return globalContext;
    }
    final BeanContext di = callContext.getBeanContext();
    if (di != null) {
        return di.getJndiEnc();
    } else {
        final ContainerSystem containerSystem = SystemInstance.get().getComponent(ContainerSystem.class);
        return containerSystem.getJNDIContext();
    }
}
Also used : ContainerSystem(org.apache.openejb.spi.ContainerSystem) BeanContext(org.apache.openejb.BeanContext) WebContext(org.apache.openejb.core.WebContext) AppContext(org.apache.openejb.AppContext) Context(javax.naming.Context) ThreadContext(org.apache.openejb.core.ThreadContext) ContextHandler(org.apache.openejb.core.ivm.ContextHandler) BeanContext(org.apache.openejb.BeanContext) WebContext(org.apache.openejb.core.WebContext) AppContext(org.apache.openejb.AppContext) ThreadContext(org.apache.openejb.core.ThreadContext)

Aggregations

Context (javax.naming.Context)1 AppContext (org.apache.openejb.AppContext)1 BeanContext (org.apache.openejb.BeanContext)1 ThreadContext (org.apache.openejb.core.ThreadContext)1 WebContext (org.apache.openejb.core.WebContext)1 ContextHandler (org.apache.openejb.core.ivm.ContextHandler)1 ContainerSystem (org.apache.openejb.spi.ContainerSystem)1