use of org.apache.openejb.InternalErrorException 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.InternalErrorException 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.InternalErrorException in project tomee by apache.
the class BaseSessionContext method getBusinessObject.
public Object getBusinessObject(final Class interfce) {
doCheck(Call.getBusinessObject);
if (interfce == null) {
throw new IllegalStateException("Interface argument cannot me null.");
}
final ThreadContext threadContext = ThreadContext.getThreadContext();
final BeanContext di = threadContext.getBeanContext();
final InterfaceType interfaceType = di.getInterfaceType(interfce);
final BeanType type = di.getComponentType();
if (interfaceType == null) {
throw new IllegalStateException("Component has no such interface: " + interfce.getName());
}
if (!interfaceType.isBusiness()) {
throw new IllegalStateException("Interface is not a business interface for this bean: " + interfce.getName());
}
try {
final EjbObjectProxyHandler handler;
switch(di.getComponentType()) {
case STATEFUL:
{
handler = new StatefulEjbObjectHandler(di, threadContext.getPrimaryKey(), interfaceType, new ArrayList<Class>(), interfce);
break;
}
case STATELESS:
{
handler = new StatelessEjbObjectHandler(di, threadContext.getPrimaryKey(), interfaceType, new ArrayList<Class>(), interfce);
break;
}
case SINGLETON:
{
handler = new SingletonEjbObjectHandler(di, threadContext.getPrimaryKey(), interfaceType, new ArrayList<Class>(), interfce);
break;
}
case MANAGED:
{
handler = new ManagedObjectHandler(di, threadContext.getPrimaryKey(), interfaceType, new ArrayList<Class>(), interfce);
break;
}
default:
throw new IllegalStateException("Bean is not a session bean: " + di.getComponentType());
}
if (InterfaceType.LOCALBEAN.equals(interfaceType)) {
return LocalBeanProxyFactory.constructProxy(di.get(BeanContext.ProxyClass.class).getProxy(), handler);
} else {
final List<Class> interfaces = new ArrayList<Class>();
interfaces.addAll(di.getInterfaces(interfaceType));
interfaces.add(Serializable.class);
interfaces.add(IntraVmProxy.class);
if (BeanType.STATEFUL.equals(type) || BeanType.MANAGED.equals(type)) {
interfaces.add(BeanContext.Removable.class);
}
return ProxyManager.newProxyInstance(interfaces.toArray(new Class[interfaces.size()]), handler);
}
} catch (final IllegalAccessException iae) {
throw new InternalErrorException("Could not create IVM proxy for " + interfce.getName() + " interface", iae);
}
}
Aggregations