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