public Object getBusinessObject(Class interfce) {
check(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 {
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.newProxyInstance(di.getClassLoader(), di.getBeanClass(), handler);
} else {
List<Class> interfaces = new ArrayList<Class>();
interfaces.addAll(di.getInterfaces(interfaceType));
interfaces.add(IntraVmProxy.class);
if (SessionType.STATEFUL.equals(type) || SessionType.MANAGED.equals(type)) {
interfaces.add(BeanContext.Removable.class);
}
return ProxyManager.newProxyInstance(interfaces.toArray(new Class[interfaces.size()]), handler);