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));
}
}
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());
}
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());
}
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);
}
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();
}
Aggregations