ThreadContext callContext = new ThreadContext(deploymentInfo, primKey);
ThreadContext oldCallContext = ThreadContext.enter(callContext);
try {
checkAuthorization(deploymentInfo, callMethod, callInterface);
InterfaceType type = deploymentInfo.getInterfaceType(callInterface);
if (type.isComponent() && instanceManager.getBeanTransaction(callContext) != null) {
throw new ApplicationException(new RemoveException("A stateful EJB enrolled in a transaction can not be removed"));
}
Method runMethod = deploymentInfo.getMatchingBeanMethod(callMethod);
StatefulInstanceManager.Instance instance = (StatefulInstanceManager.Instance) instanceManager.obtainInstance(primKey, callContext);
if (instance == null) throw new ApplicationException(new javax.ejb.NoSuchEJBException());
boolean retain = false;
try {
callContext.setCurrentAllowedStates(StatefulContext.getStates());
callContext.setCurrentOperation(Operation.REMOVE);
callContext.setInvokedInterface(callInterface);
Class<?> declaringClass = callMethod.getDeclaringClass();
if (declaringClass.equals(EJBHome.class) || declaringClass.equals(EJBLocalHome.class)){
args = new Object[]{}; // no args to pass on home.remove(remote) calls
}
List<InterceptorData> interceptors = deploymentInfo.getMethodInterceptors(runMethod);
InterceptorStack interceptorStack = new InterceptorStack(instance.bean, runMethod, Operation.REMOVE, interceptors, instance.interceptors);
return _invoke(callMethod, interceptorStack, args, instance, callContext);
} catch(InvalidateReferenceException e){
throw e;
} catch(ApplicationException e){
if (type.isBusiness()){
retain = deploymentInfo.retainIfExeption(runMethod);
throw e;
} else {
return null;
}