Search in sources :

Example 1 with EjbObjectProxyHandler

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

the class EntityContext method getEJBObject.

public EJBObject getEJBObject() throws IllegalStateException {
    doCheck(Call.getEJBObject);
    final ThreadContext threadContext = ThreadContext.getThreadContext();
    final BeanContext di = threadContext.getBeanContext();
    if (di.getRemoteInterface() == null) {
        throw new IllegalStateException("EJB " + di.getDeploymentID() + " does not have a remote interface");
    }
    final EjbObjectProxyHandler handler = new EntityEjbObjectHandler(di.getContainer().getBeanContext(di.getDeploymentID()), threadContext.getPrimaryKey(), InterfaceType.EJB_OBJECT, new ArrayList<Class>(), di.getRemoteInterface());
    try {
        final Class[] interfaces = new Class[] { di.getRemoteInterface(), IntraVmProxy.class };
        return (EJBObject) ProxyManager.newProxyInstance(interfaces, handler);
    } catch (final IllegalAccessException iae) {
        throw new InternalErrorException("Could not create IVM proxy for " + di.getRemoteInterface() + " interface", iae);
    }
}
Also used : BeanContext(org.apache.openejb.BeanContext) EJBObject(javax.ejb.EJBObject) ThreadContext(org.apache.openejb.core.ThreadContext) InternalErrorException(org.apache.openejb.InternalErrorException) IntraVmProxy(org.apache.openejb.core.ivm.IntraVmProxy) EjbObjectProxyHandler(org.apache.openejb.core.ivm.EjbObjectProxyHandler)

Example 2 with EjbObjectProxyHandler

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

the class EntityContext method getEJBLocalObject.

public EJBLocalObject getEJBLocalObject() throws IllegalStateException {
    doCheck(Call.getEJBLocalObject);
    final ThreadContext threadContext = ThreadContext.getThreadContext();
    final BeanContext di = threadContext.getBeanContext();
    if (di.getLocalInterface() == null) {
        throw new IllegalStateException("EJB " + di.getDeploymentID() + " does not have a local interface");
    }
    final EjbObjectProxyHandler handler = new EntityEjbObjectHandler(di, threadContext.getPrimaryKey(), InterfaceType.EJB_LOCAL, new ArrayList<Class>(), di.getLocalInterface());
    try {
        final Class[] interfaces = new Class[] { di.getLocalInterface(), IntraVmProxy.class };
        return (EJBLocalObject) ProxyManager.newProxyInstance(interfaces, handler);
    } catch (final IllegalAccessException iae) {
        throw new InternalErrorException("Could not create IVM proxy for " + di.getLocalInterface() + " interface", iae);
    }
}
Also used : BeanContext(org.apache.openejb.BeanContext) ThreadContext(org.apache.openejb.core.ThreadContext) InternalErrorException(org.apache.openejb.InternalErrorException) IntraVmProxy(org.apache.openejb.core.ivm.IntraVmProxy) EJBLocalObject(javax.ejb.EJBLocalObject) EjbObjectProxyHandler(org.apache.openejb.core.ivm.EjbObjectProxyHandler)

Example 3 with EjbObjectProxyHandler

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

the class Cmp2Util method getEntityBean.

public static <Bean extends EntityBean> Bean getEntityBean(final EJBObject proxy) {
    if (proxy == null) {
        return null;
    }
    final EjbObjectProxyHandler handler = (EjbObjectProxyHandler) ProxyManager.getInvocationHandler(proxy);
    if (handler.container == null) {
        return null;
    }
    if (!(handler.container instanceof CmpContainer)) {
        throw new IllegalArgumentException("Proxy is not connected to a CMP container but is conect to " + handler.container.getClass().getName());
    }
    final CmpContainer container = (CmpContainer) handler.container;
    final Bean entity = (Bean) container.getEjbInstance(handler.getBeanContext(), handler.primaryKey);
    return entity;
}
Also used : CmpContainer(org.apache.openejb.core.cmp.CmpContainer) EjbObjectProxyHandler(org.apache.openejb.core.ivm.EjbObjectProxyHandler) EntityBean(javax.ejb.EntityBean)

Example 4 with EjbObjectProxyHandler

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

the class EntityEjbHomeHandler method createProxy.

public Object createProxy(final Object primaryKey, final Class mainInterface) {
    final Object proxy = super.createProxy(primaryKey, mainInterface);
    final EjbObjectProxyHandler handler = (EjbObjectProxyHandler) ProxyManager.getInvocationHandler(proxy);
    /* 
        * Register the handle with the BaseEjbProxyHandler.liveHandleRegistry
        * If the bean is removed by its home or by an identical proxy, then the 
        * this proxy will be automatically invalidated because its properly registered
        * with the liveHandleRegistry.
        */
    registerHandler(handler.getRegistryId(), handler);
    return proxy;
}
Also used : EJBObject(javax.ejb.EJBObject) EJBLocalObject(javax.ejb.EJBLocalObject) EjbObjectProxyHandler(org.apache.openejb.core.ivm.EjbObjectProxyHandler)

Example 5 with EjbObjectProxyHandler

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

the class StatefulEjbHomeHandler method createProxy.

public Object createProxy(final Object primaryKey, final Class mainInterface) {
    final Object proxy = super.createProxy(primaryKey, mainInterface);
    EjbObjectProxyHandler handler = null;
    try {
        handler = (EjbObjectProxyHandler) ProxyManager.getInvocationHandler(proxy);
    } catch (final Exception e) {
        // try getting the invocation handler from the localbean
        try {
            final Field field = proxy.getClass().getDeclaredField("invocationHandler");
            field.setAccessible(true);
            handler = (EjbObjectProxyHandler) field.get(proxy);
        } catch (final Exception e1) {
        // no-op
        }
    }
    registerHandler(handler.getRegistryId(), handler);
    return proxy;
}
Also used : Field(java.lang.reflect.Field) EjbObjectProxyHandler(org.apache.openejb.core.ivm.EjbObjectProxyHandler) RemoveException(javax.ejb.RemoveException)

Aggregations

EjbObjectProxyHandler (org.apache.openejb.core.ivm.EjbObjectProxyHandler)8 BeanContext (org.apache.openejb.BeanContext)3 InternalErrorException (org.apache.openejb.InternalErrorException)3 Field (java.lang.reflect.Field)2 EJBLocalObject (javax.ejb.EJBLocalObject)2 EJBObject (javax.ejb.EJBObject)2 EntityBean (javax.ejb.EntityBean)2 RemoveException (javax.ejb.RemoveException)2 ThreadContext (org.apache.openejb.core.ThreadContext)2 CmpContainer (org.apache.openejb.core.cmp.CmpContainer)2 IntraVmProxy (org.apache.openejb.core.ivm.IntraVmProxy)2 ArrayList (java.util.ArrayList)1 BeanType (org.apache.openejb.BeanType)1 InterfaceType (org.apache.openejb.InterfaceType)1 ManagedObjectHandler (org.apache.openejb.core.managed.ManagedObjectHandler)1 SingletonEjbObjectHandler (org.apache.openejb.core.singleton.SingletonEjbObjectHandler)1 StatefulEjbObjectHandler (org.apache.openejb.core.stateful.StatefulEjbObjectHandler)1 StatelessEjbObjectHandler (org.apache.openejb.core.stateless.StatelessEjbObjectHandler)1