Search in sources :

Example 21 with BeanContext

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

the class RequestScopedThreadContextListener method contextEntered.

@Override
public void contextEntered(final ThreadContext oldContext, final ThreadContext newContext) {
    final BeanContext beanContext = newContext.getBeanContext();
    final WebBeansContext webBeansContext = beanContext.getModuleContext().getAppContext().getWebBeansContext();
    if (webBeansContext == null) {
        return;
    }
    final ContextsService contextsService = webBeansContext.getContextsService();
    final Context requestContext = CdiAppContextsService.class.cast(contextsService).getRequestContext(false);
    if (requestContext == null) {
        contextsService.startContext(RequestScoped.class, CdiAppContextsService.EJB_REQUEST_EVENT);
        newContext.set(DestroyContext.class, new DestroyContext(contextsService, newContext));
    }
}
Also used : WebBeansContext(org.apache.webbeans.config.WebBeansContext) BeanContext(org.apache.openejb.BeanContext) Context(javax.enterprise.context.spi.Context) ThreadContext(org.apache.openejb.core.ThreadContext) BeanContext(org.apache.openejb.BeanContext) ContextsService(org.apache.webbeans.spi.ContextsService) WebBeansContext(org.apache.webbeans.config.WebBeansContext)

Example 22 with BeanContext

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

the class BaseSessionContext method getEJBLocalObject.

public EJBLocalObject getEJBLocalObject() throws IllegalStateException {
    doCheck(Call.getEJBLocalObject);
    final ThreadContext threadContext = ThreadContext.getThreadContext();
    final BeanContext di = threadContext.getBeanContext();
    if (di.getLocalHomeInterface() == null) {
        throw new IllegalStateException("Bean does not have an EJBLocalObject interface: " + di.getDeploymentID());
    }
    return (EJBLocalObject) EjbObjectProxyHandler.createProxy(di, threadContext.getPrimaryKey(), InterfaceType.EJB_LOCAL, di.getLocalInterface());
}
Also used : BeanContext(org.apache.openejb.BeanContext) EJBLocalObject(javax.ejb.EJBLocalObject)

Example 23 with BeanContext

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

the class BaseSessionContext method getEJBObject.

public EJBObject getEJBObject() throws IllegalStateException {
    doCheck(Call.getEJBObject);
    final ThreadContext threadContext = ThreadContext.getThreadContext();
    final BeanContext di = threadContext.getBeanContext();
    if (di.getHomeInterface() == null) {
        throw new IllegalStateException("Bean does not have an EJBObject interface: " + di.getDeploymentID());
    }
    return (EJBObject) EjbObjectProxyHandler.createProxy(di, threadContext.getPrimaryKey(), InterfaceType.EJB_OBJECT, di.getRemoteInterface());
}
Also used : BeanContext(org.apache.openejb.BeanContext) EJBObject(javax.ejb.EJBObject)

Example 24 with BeanContext

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

the class BaseContext method isCallerInRole.

protected boolean isCallerInRole(final SecurityService securityService, final String roleName) {
    doCheck(Call.isCallerInRole);
    final ThreadContext threadContext = ThreadContext.getThreadContext();
    final BeanContext di = threadContext.getBeanContext();
    final String roleLink = di.getSecurityRoleReference(roleName);
    return securityService.isCallerInRole(roleLink);
}
Also used : BeanContext(org.apache.openejb.BeanContext)

Example 25 with BeanContext

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

the class BaseContext method setRollbackOnly.

public void setRollbackOnly() throws IllegalStateException {
    doCheck(Call.setRollbackOnly);
    final ThreadContext threadContext = ThreadContext.getThreadContext();
    final BeanContext di = threadContext.getBeanContext();
    if (di.isBeanManagedTransaction()) {
        throw new IllegalStateException("bean-managed transaction beans can not access the setRollbackOnly() method");
    }
    final TransactionPolicy txPolicy = threadContext.getTransactionPolicy();
    if (txPolicy == null) {
        throw new IllegalStateException("ThreadContext does not contain a TransactionEnvironment");
    }
    if (txPolicy.getTransactionType() == TransactionType.Never || txPolicy.getTransactionType() == TransactionType.NotSupported || txPolicy.getTransactionType() == TransactionType.Supports) {
        throw new IllegalStateException("setRollbackOnly accessible only from MANDATORY, REQUIRED, or REQUIRES_NEW");
    }
    txPolicy.setRollbackOnly();
}
Also used : BeanContext(org.apache.openejb.BeanContext) TransactionPolicy(org.apache.openejb.core.transaction.TransactionPolicy)

Aggregations

BeanContext (org.apache.openejb.BeanContext)198 OpenEJBException (org.apache.openejb.OpenEJBException)40 ThreadContext (org.apache.openejb.core.ThreadContext)40 Method (java.lang.reflect.Method)38 ContainerSystem (org.apache.openejb.spi.ContainerSystem)28 ArrayList (java.util.ArrayList)27 AppContext (org.apache.openejb.AppContext)26 TransactionPolicy (org.apache.openejb.core.transaction.TransactionPolicy)26 NamingException (javax.naming.NamingException)24 InterceptorData (org.apache.openejb.core.interceptor.InterceptorData)23 Context (javax.naming.Context)22 ApplicationException (org.apache.openejb.ApplicationException)20 HashMap (java.util.HashMap)19 EJBLocalObject (javax.ejb.EJBLocalObject)18 EJBObject (javax.ejb.EJBObject)18 SystemException (org.apache.openejb.SystemException)18 OpenEJBRuntimeException (org.apache.openejb.OpenEJBRuntimeException)17 ModuleContext (org.apache.openejb.ModuleContext)16 EjbTransactionUtil.createTransactionPolicy (org.apache.openejb.core.transaction.EjbTransactionUtil.createTransactionPolicy)16 FinderException (javax.ejb.FinderException)14