Modified: openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/mdb/MdbContext.java URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/mdb/MdbContext.java?rev=963626&r1=963625&r2=963626&view=diff ============================================================================== --- openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/mdb/MdbContext.java (original) +++ openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/mdb/MdbContext.java Tue Jul 13 09:21:07 2010 @@ -16,197 +16,61 @@ */ package org.apache.openejb.core.mdb; -import java.security.Principal; -import java.util.Map; -import javax.ejb.EJBHome; -import javax.ejb.EJBLocalHome; -import javax.ejb.MessageDrivenContext; -import javax.ejb.TimerService; -import javax.transaction.UserTransaction; - import org.apache.openejb.core.BaseContext; import org.apache.openejb.core.Operation; import org.apache.openejb.core.ThreadContext; import org.apache.openejb.spi.SecurityService; +import javax.ejb.EJBHome; +import javax.ejb.EJBLocalHome; +import javax.ejb.MessageDrivenContext; + /** * @version $Rev$ $Date$ */ public class MdbContext extends BaseContext implements MessageDrivenContext { - protected final static State[] states = new State[Operation.values().length]; - - public static State[] getStates() { - return states; - } - public MdbContext(SecurityService securityService) { super(securityService); } - protected State getState() { - Operation operation = ThreadContext.getThreadContext().getCurrentOperation(); - State state = states[operation.ordinal()]; - - if (state == null) throw new IllegalArgumentException("Invalid operation " + operation + " for this context"); - - return state; - } - - /** - * Dependency injection methods (e.g., setMessageDrivenContext) - */ - protected static class InjectionMdbState extends State { - @Override - public EJBHome getEJBHome() { - throw new IllegalStateException(); - } - - @Override - public EJBLocalHome getEJBLocalHome() { - throw new IllegalStateException(); - } - - @Override - public Principal getCallerPrincipal(SecurityService securityService) { - throw new IllegalStateException(); - } - - @Override - public boolean isCallerInRole(SecurityService securityService, String roleName) { - throw new IllegalStateException(); - } - - @Override - public UserTransaction getUserTransaction(UserTransaction userTransaction) throws IllegalStateException { - throw new IllegalStateException(); - } - - @Override - public boolean getRollbackOnly() throws IllegalStateException { - throw new IllegalStateException(); - } - - @Override - public void setRollbackOnly() throws IllegalStateException { - throw new IllegalStateException(); - } - - @Override - public TimerService getTimerService() throws IllegalStateException { - throw new IllegalStateException(); - } - - @Override - public boolean isUserTransactionAccessAllowed() { - return false; - } - - @Override - public boolean isMessageContextAccessAllowed() { - return false; - } - - @Override - public boolean isEntityManagerFactoryAccessAllowed() { - return false; - } - - @Override - public boolean isEntityManagerAccessAllowed() { - return false; - } - - @Override - public boolean isTimerAccessAllowed() { - return false; - } - - @Override - public boolean isTimerMethodAllowed() { - return false; + @Override + public EJBHome getEJBHome() { + throw new IllegalStateException(); + } + + @Override + public EJBLocalHome getEJBLocalHome() { + throw new IllegalStateException(); + } + + @Override + public void check(Call call) { + final Operation operation = ThreadContext.getThreadContext().getCurrentOperation(); + + switch (call) { + case getUserTransaction: + case getTimerService: + switch (operation) { + case INJECTION: + throw illegal(call, operation); + default: + return; + } + case getCallerPrincipal: + case isCallerInRole: + case timerMethod: + case setRollbackOnly: + case getRollbackOnly: + switch (operation) { + case INJECTION: + case CREATE: + case POST_CONSTRUCT: + case PRE_DESTROY: + throw illegal(call, operation); + default: + return; + } } } - - /** - * PostConstruct, Pre-Destroy lifecycle callback interceptor methods - */ - protected static class LifecycleMdbState extends State { - @Override - public EJBHome getEJBHome() { - throw new IllegalStateException(); - } - - @Override - public EJBLocalHome getEJBLocalHome() { - throw new IllegalStateException(); - } - - @Override - public Principal getCallerPrincipal(SecurityService securityService) { - throw new IllegalStateException(); - } - - @Override - public boolean isCallerInRole(SecurityService securityService, String roleName) { - throw new IllegalStateException(); - } - - @Override - public boolean getRollbackOnly() throws IllegalStateException { - throw new IllegalStateException(); - } - - @Override - public void setRollbackOnly() throws IllegalStateException { - throw new IllegalStateException(); - } - - @Override - public boolean isMessageContextAccessAllowed() { - return false; - } - - @Override - public boolean isEntityManagerAccessAllowed() { - return false; - } - - @Override - public boolean isTimerAccessAllowed() { - return super.isTimerAccessAllowed(); //todo: consider this autogenerated code - } - - @Override - public boolean isTimerMethodAllowed() { - return false; - } - } - - /** - * Message listener method, business method interceptor method - * and timeout callback method - */ - protected static class BusinessTimeoutMdbState extends State { - @Override - public EJBHome getEJBHome() { - throw new IllegalStateException(); - } - - @Override - public EJBLocalHome getEJBLocalHome() { - throw new IllegalStateException(); - } - - } - - static { - states[Operation.INJECTION.ordinal()] = new InjectionMdbState(); - states[Operation.CREATE.ordinal()] = new LifecycleMdbState(); - states[Operation.POST_CONSTRUCT.ordinal()] = new LifecycleMdbState(); - states[Operation.PRE_DESTROY.ordinal()] = new LifecycleMdbState(); - states[Operation.BUSINESS.ordinal()] = new BusinessTimeoutMdbState(); - states[Operation.TIMEOUT.ordinal()] = new BusinessTimeoutMdbState(); - } - }
Modified: openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/mdb/MdbInstanceFactory.java URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/mdb/MdbInstanceFactory.java?rev=963626&r1=963625&r2=963626&view=diff ============================================================================== --- openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/mdb/MdbInstanceFactory.java (original) +++ openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/mdb/MdbInstanceFactory.java Tue Jul 13 09:21:07 2010 @@ -29,6 +29,7 @@ import org.apache.openejb.spi.SecuritySe import org.apache.openejb.util.LogCategory; import org.apache.openejb.util.Logger; +import javax.ejb.EJBContext; import javax.ejb.MessageDrivenBean; import javax.naming.Context; import javax.naming.NamingException; @@ -78,6 +79,7 @@ public class MdbInstanceFactory { throw new OpenEJBException("Failed to bind EJBContext", e); } + deploymentInfo.set(EJBContext.class, this.mdbContext); } /** @@ -157,7 +159,6 @@ public class MdbInstanceFactory { try { // call post destroy method callContext.setCurrentOperation(Operation.PRE_DESTROY); - callContext.setCurrentAllowedStates(MdbContext.getStates()); Method remove = instance.bean instanceof MessageDrivenBean ? MessageDrivenBean.class.getMethod("ejbRemove") : null; List<InterceptorData> callbackInterceptors = deploymentInfo.getCallbackInterceptors(); InterceptorStack interceptorStack = new InterceptorStack(instance.bean, remove, Operation.PRE_DESTROY, callbackInterceptors, instance.interceptors); Modified: openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/singleton/SingletonContainer.java URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/singleton/SingletonContainer.java?rev=963626&r1=963625&r2=963626&view=diff ============================================================================== --- openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/singleton/SingletonContainer.java (original) +++ openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/singleton/SingletonContainer.java Tue Jul 13 09:21:07 2010 @@ -42,7 +42,6 @@ import javax.ejb.EJBHome; import javax.ejb.EJBLocalHome; import javax.ejb.EJBLocalObject; import javax.ejb.EJBObject; -import javax.ejb.LockType; import javax.interceptor.AroundInvoke; import org.apache.openejb.ContainerType; @@ -221,7 +220,7 @@ public class SingletonContainer implemen Instance instance = instanceManager.getInstance(callContext); callContext.setCurrentOperation(type == InterfaceType.TIMEOUT ? Operation.TIMEOUT : Operation.BUSINESS); - callContext.setCurrentAllowedStates(SingletonContext.getStates()); + callContext.setCurrentAllowedStates(null); callContext.set(Method.class, runMethod); callContext.setInvokedInterface(callInterface); Modified: openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/singleton/SingletonContext.java URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/singleton/SingletonContext.java?rev=963626&r1=963625&r2=963626&view=diff ============================================================================== --- openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/singleton/SingletonContext.java (original) +++ openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/singleton/SingletonContext.java Tue Jul 13 09:21:07 2010 @@ -21,46 +21,62 @@ import org.apache.openejb.core.Operation import org.apache.openejb.core.ThreadContext; import org.apache.openejb.spi.SecurityService; +import javax.xml.rpc.handler.MessageContext; + /** * @version $Rev$ $Date$ */ public class SingletonContext extends BaseSessionContext { - protected final static State[] states = new State[Operation.values().length]; - - public static State[] getStates() { - return states; - } public SingletonContext(SecurityService securityService) { super(securityService); } - protected State getState() { - Operation operation = ThreadContext.getThreadContext().getCurrentOperation(); - State state = states[operation.ordinal()]; - - if (state == null) throw new IllegalArgumentException("Invalid operation " + operation + " for this context"); - - return state; - } - - /** - * Business method from web service endpoint - */ - private static class BusinessWsStatelessState extends SessionState { - public Class getInvokedBusinessInterface() { - throw new IllegalStateException(); + @Override + public void check(Call call) { + final Operation operation = ThreadContext.getThreadContext().getCurrentOperation(); + + switch (call) { + case getEJBLocalObject: + case getEJBObject: + case getBusinessObject: + case getUserTransaction: + case getTimerService: + switch (operation) { + case INJECTION: + throw illegal(call, operation); + default: + return; + } + case getCallerPrincipal: + case isCallerInRole: + case timerMethod: + case setRollbackOnly: + case getRollbackOnly: + case UserTransactionMethod: + switch (operation) { + case INJECTION: + case CREATE: + case POST_CONSTRUCT: + case PRE_DESTROY: + throw illegal(call, operation); + default: + return; + } + case getInvokedBusinessInterface: + switch (operation) { + case BUSINESS: + return; + default: + throw illegal(call, operation); + } + case getMessageContext: + switch (operation) { + case BUSINESS_WS: + return; + default: + throw illegal(call, operation); + } } } - - static { - states[Operation.INJECTION.ordinal()] = new InjectionSessionState(); - states[Operation.CREATE.ordinal()] = new LifecycleSessionState(); - states[Operation.BUSINESS.ordinal()] = new BusinessSessionState(); - states[Operation.BUSINESS_WS.ordinal()] = new BusinessWsStatelessState(); - states[Operation.TIMEOUT.ordinal()] = new TimeoutSessionState(); - states[Operation.POST_CONSTRUCT.ordinal()] = new PostConstructSessionState(); - states[Operation.PRE_DESTROY.ordinal()] = new LifecycleSessionState(); - } - } Modified: openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/singleton/SingletonInstanceManager.java URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/singleton/SingletonInstanceManager.java?rev=963626&r1=963625&r2=963626&view=diff ============================================================================== --- openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/singleton/SingletonInstanceManager.java (original) +++ openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/singleton/SingletonInstanceManager.java Tue Jul 13 09:21:07 2010 @@ -32,6 +32,7 @@ import java.util.concurrent.Callable; import java.util.concurrent.ExecutionException; import java.util.concurrent.atomic.AtomicReference; +import javax.ejb.EJBContext; import javax.ejb.SessionBean; import javax.ejb.NoSuchEJBException; import javax.naming.Context; @@ -181,7 +182,7 @@ public class SingletonInstanceManager { try { callContext.setCurrentOperation(Operation.PRE_DESTROY); - callContext.setCurrentAllowedStates(SingletonContext.getStates()); + callContext.setCurrentAllowedStates(null); Method remove = instance.bean instanceof SessionBean? deploymentInfo.getCreateMethod(): null; @@ -211,6 +212,8 @@ public class SingletonInstanceManager { Data data = new Data(); deploymentInfo.setContainerData(data); + deploymentInfo.set(EJBContext.class, this.sessionContext); + // Create stats interceptor StatsInterceptor stats = new StatsInterceptor(deploymentInfo.getBeanClass()); deploymentInfo.addSystemInterceptor(stats); Modified: openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/stateful/StatefulContainer.java URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/stateful/StatefulContainer.java?rev=963626&r1=963625&r2=963626&view=diff ============================================================================== --- openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/stateful/StatefulContainer.java (original) +++ openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/stateful/StatefulContainer.java Tue Jul 13 09:21:07 2010 @@ -29,6 +29,7 @@ import java.util.concurrent.ConcurrentHa import java.util.concurrent.TimeUnit; import java.util.concurrent.locks.Lock; import javax.ejb.EJBAccessException; +import javax.ejb.EJBContext; import javax.ejb.EJBException; import javax.ejb.EJBHome; import javax.ejb.EJBLocalHome; @@ -266,6 +267,8 @@ public class StatefulContainer implement return deploymentInfo == instance.deploymentInfo; } }); + + deploymentInfo.set(EJBContext.class, this.sessionContext); } private synchronized void deploy(CoreDeploymentInfo deploymentInfo) throws OpenEJBException { @@ -364,7 +367,7 @@ public class StatefulContainer implement } createContext.setCurrentOperation(Operation.CREATE); - createContext.setCurrentAllowedStates(StatefulContext.getStates()); + createContext.setCurrentAllowedStates(null); // Start transaction TransactionPolicy txPolicy = createTransactionPolicy(createContext.getDeploymentInfo().getTransactionType(callMethod), createContext); @@ -486,7 +489,7 @@ public class StatefulContainer implement // Setup for remove invocation callContext.setCurrentOperation(Operation.REMOVE); - callContext.setCurrentAllowedStates(StatefulContext.getStates()); + callContext.setCurrentAllowedStates(null); callContext.setInvokedInterface(callInterface); runMethod = deploymentInfo.getMatchingBeanMethod(callMethod); callContext.set(Method.class, runMethod); @@ -584,7 +587,7 @@ public class StatefulContainer implement // Setup for business invocation callContext.setCurrentOperation(Operation.BUSINESS); - callContext.setCurrentAllowedStates(StatefulContext.getStates()); + callContext.setCurrentAllowedStates(null); callContext.setInvokedInterface(callInterface); Method runMethod = deploymentInfo.getMatchingBeanMethod(callMethod); callContext.set(Method.class, runMethod); @@ -887,7 +890,7 @@ public class StatefulContainer implement // Invoke afterBegin ThreadContext callContext = new ThreadContext(instance.deploymentInfo, instance.primaryKey, Operation.AFTER_BEGIN); - callContext.setCurrentAllowedStates(StatefulContext.getStates()); + callContext.setCurrentAllowedStates(null); ThreadContext oldCallContext = ThreadContext.enter(callContext); try { @@ -923,7 +926,7 @@ public class StatefulContainer implement // Invoke beforeCompletion ThreadContext callContext = new ThreadContext(instance.deploymentInfo, instance.primaryKey, Operation.BEFORE_COMPLETION); - callContext.setCurrentAllowedStates(StatefulContext.getStates()); + callContext.setCurrentAllowedStates(null); ThreadContext oldCallContext = ThreadContext.enter(callContext); try { instance.setInUse(true); @@ -963,7 +966,7 @@ public class StatefulContainer implement Instance instance = synchronization.instance; ThreadContext callContext = new ThreadContext(instance.deploymentInfo, instance.primaryKey, Operation.AFTER_COMPLETION); - callContext.setCurrentAllowedStates(StatefulContext.getStates()); + callContext.setCurrentAllowedStates(null); ThreadContext oldCallContext = ThreadContext.enter(callContext); try { instance.setInUse(true); @@ -1047,7 +1050,7 @@ public class StatefulContainer implement CoreDeploymentInfo deploymentInfo = instance.deploymentInfo; ThreadContext threadContext = new ThreadContext(deploymentInfo, instance.primaryKey, Operation.PRE_DESTROY); - threadContext.setCurrentAllowedStates(StatefulContext.getStates()); + threadContext.setCurrentAllowedStates(null); ThreadContext oldContext = ThreadContext.enter(threadContext); try { Method remove = instance.bean instanceof SessionBean ? SessionBean.class.getMethod("ejbRemove") : null; Modified: openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/stateful/StatefulContext.java URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/stateful/StatefulContext.java?rev=963626&r1=963625&r2=963626&view=diff ============================================================================== --- openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/stateful/StatefulContext.java (original) +++ openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/stateful/StatefulContext.java Tue Jul 13 09:21:07 2010 @@ -16,152 +16,85 @@ */ package org.apache.openejb.core.stateful; -import javax.transaction.UserTransaction; -import javax.xml.rpc.handler.MessageContext; - import org.apache.openejb.core.BaseSessionContext; import org.apache.openejb.core.Operation; import org.apache.openejb.core.ThreadContext; import org.apache.openejb.spi.SecurityService; +import javax.transaction.UserTransaction; +import javax.xml.rpc.handler.MessageContext; + /** * @version $Rev$ $Date$ */ public class StatefulContext extends BaseSessionContext { - protected final static State[] states = new State[Operation.values().length]; - - public static State[] getStates() { - return states; - } - public StatefulContext(SecurityService securityService, UserTransaction userTransaction) { super(securityService, userTransaction); } - protected State getState() { - Operation operation = ThreadContext.getThreadContext().getCurrentOperation(); - State state = states[operation.ordinal()]; - - if (state == null) throw new IllegalArgumentException("Invalid operation " + operation + " for this context"); - - return state; - } - - /** - * PostConstruct, Pre-Destroy lifecycle callback interceptor methods - */ - public static class LifecycleStatefulSessionState extends SessionState { - - public MessageContext getMessageContext() throws IllegalStateException { - throw new IllegalStateException(); - } - - public Class getInvokedBusinessInterface() { - throw new IllegalStateException(); - } - - public void setRollbackOnly() throws IllegalStateException { - throw new IllegalStateException(); - } - - public boolean getRollbackOnly() throws IllegalStateException { - throw new IllegalStateException(); - } - - public boolean isMessageContextAccessAllowed() { - return false; - } - - public boolean isTimerAccessAllowed() { - return false; - } - - public boolean isTimerMethodAllowed() { - return false; - } - } - - /** - * afterBegin - * beforeCompletion - */ - public static class BeforeCompletion extends SessionState { + @Override + public void check(Call call) { + final Operation operation = ThreadContext.getThreadContext().getCurrentOperation(); + switch (call) { + case getCallerPrincipal: + case isCallerInRole: + case getUserTransaction: + case getTimerService: + case getEJBLocalObject: + case getEJBObject: + case getBusinessObject: + switch (operation) { + case INJECTION: + throw illegal(call, operation); + default: + return; + } + case setRollbackOnly: + case getRollbackOnly: + case timerMethod: + switch (operation) { + case INJECTION: + case CREATE: + case AFTER_COMPLETION: + case PRE_DESTROY: + case REMOVE: + case POST_CONSTRUCT: + throw illegal(call, operation); + default: + return; + } + case getInvokedBusinessInterface: + switch (operation) { + case INJECTION: + case CREATE: + case AFTER_BEGIN: + case BEFORE_COMPLETION: + case AFTER_COMPLETION: + case TIMEOUT: + case PRE_DESTROY: + case REMOVE: + case POST_CONSTRUCT: + throw illegal(call, operation); + default: + return; + } + + case UserTransactionMethod: + switch (operation) { + case INJECTION: + case AFTER_COMPLETION: + throw illegal(call, operation); + default: + return; + } - public Class getInvokedBusinessInterface() { - throw new IllegalStateException(); - } - - public MessageContext getMessageContext() throws IllegalStateException { - throw new IllegalStateException(); - } - - public boolean isMessageContextAccessAllowed() { - return false; - } - } - - /** - * afterCompletion - */ - public static class AfterCompletion extends SessionState { - public MessageContext getMessageContext() throws IllegalStateException { - throw new IllegalStateException(); - } - - public Class getInvokedBusinessInterface() { - throw new IllegalStateException(); - } - - public void setRollbackOnly() throws IllegalStateException { - throw new IllegalStateException(); - } - - public boolean getRollbackOnly() throws IllegalStateException { - throw new IllegalStateException(); - } - - public boolean isUserTransactionAccessAllowed() { - return false; - } - - public boolean isMessageContextAccessAllowed() { - return false; - } - - public boolean isJNDIAccessAllowed() { - return false; - } - - public boolean isEntityManagerFactoryAccessAllowed() { - return false; - } - - public boolean isEntityManagerAccessAllowed() { - return false; - } - - public boolean isTimerAccessAllowed() { - return false; - } - - public boolean isTimerMethodAllowed() { - return false; } } - static { - states[Operation.INJECTION.ordinal()] = new InjectionSessionState(); - states[Operation.CREATE.ordinal()] = new LifecycleStatefulSessionState(); - states[Operation.BUSINESS.ordinal()] = new BusinessSessionState(); - states[Operation.AFTER_BEGIN.ordinal()] = new BeforeCompletion(); - states[Operation.BEFORE_COMPLETION.ordinal()] = new BeforeCompletion(); - states[Operation.AFTER_COMPLETION.ordinal()] = new AfterCompletion(); - states[Operation.TIMEOUT.ordinal()] = new TimeoutSessionState(); - states[Operation.PRE_DESTROY.ordinal()] = new LifecycleStatefulSessionState(); - states[Operation.REMOVE.ordinal()] = new LifecycleStatefulSessionState(); - states[Operation.POST_CONSTRUCT.ordinal()] = new LifecycleStatefulSessionState(); + @Override + public MessageContext getMessageContext() throws IllegalStateException { + throw new IllegalStateException("@Stateful beans do not support Web Service interfaces"); } - } Modified: openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/stateless/StatelessContainer.java URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/stateless/StatelessContainer.java?rev=963626&r1=963625&r2=963626&view=diff ============================================================================== --- openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/stateless/StatelessContainer.java (original) +++ openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/stateless/StatelessContainer.java Tue Jul 13 09:21:07 2010 @@ -191,7 +191,6 @@ public class StatelessContainer implemen bean = instanceManager.getInstance(callContext); callContext.setCurrentOperation(type == InterfaceType.TIMEOUT ? Operation.TIMEOUT : Operation.BUSINESS); - callContext.setCurrentAllowedStates(StatelessContext.getStates()); callContext.set(Method.class, runMethod); callContext.setInvokedInterface(callInterface); Object retValue = _invoke(callMethod, runMethod, args, (Instance) bean, callContext, type); Modified: openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/stateless/StatelessContext.java URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/stateless/StatelessContext.java?rev=963626&r1=963625&r2=963626&view=diff ============================================================================== --- openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/stateless/StatelessContext.java (original) +++ openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/stateless/StatelessContext.java Tue Jul 13 09:21:07 2010 @@ -29,46 +29,61 @@ import java.io.IOException; */ public class StatelessContext extends BaseSessionContext implements Flushable { - protected final static State[] states = new State[Operation.values().length]; private final Flushable flushable; - public static State[] getStates() { - return states; - } - public StatelessContext(SecurityService securityService, Flushable flushable) { super(securityService); this.flushable = flushable; } - protected State getState() { - Operation operation = ThreadContext.getThreadContext().getCurrentOperation(); - State state = states[operation.ordinal()]; - - if (state == null) throw new IllegalArgumentException("Invalid operation " + operation + " for this context"); - - return state; - } - - /** - * Business method from web service endpoint - */ - private static class BusinessWsStatelessState extends SessionState { - public Class getInvokedBusinessInterface() { - throw new IllegalStateException(); + @Override + public void check(Call call) { + final Operation operation = ThreadContext.getThreadContext().getCurrentOperation(); + + switch (call) { + case getEJBLocalObject: + case getEJBObject: + case getBusinessObject: + case getUserTransaction: + case getTimerService: + switch (operation) { + case INJECTION: + throw illegal(call, operation); + default: + return; + } + case getCallerPrincipal: + case isCallerInRole: + case timerMethod: + case setRollbackOnly: + case getRollbackOnly: + case UserTransactionMethod: + switch (operation) { + case INJECTION: + case CREATE: + case POST_CONSTRUCT: + case PRE_DESTROY: + throw illegal(call, operation); + default: + return; + } + case getInvokedBusinessInterface: + switch (operation) { + case BUSINESS: + return; + default: + throw illegal(call, operation); + } + case getMessageContext: + switch (operation) { + case BUSINESS_WS: + return; + default: + throw illegal(call, operation); + } } } - static { - states[Operation.INJECTION.ordinal()] = new InjectionSessionState(); - states[Operation.CREATE.ordinal()] = new LifecycleSessionState(); - states[Operation.BUSINESS.ordinal()] = new BusinessSessionState(); - states[Operation.BUSINESS_WS.ordinal()] = new BusinessWsStatelessState(); - states[Operation.TIMEOUT.ordinal()] = new TimeoutSessionState(); - states[Operation.POST_CONSTRUCT.ordinal()] = new PostConstructSessionState(); - states[Operation.PRE_DESTROY.ordinal()] = new LifecycleSessionState(); - } - public void flush() throws IOException { flushable.flush(); } Modified: openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/stateless/StatelessInstanceManager.java URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/stateless/StatelessInstanceManager.java?rev=963626&r1=963625&r2=963626&view=diff ============================================================================== --- openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/stateless/StatelessInstanceManager.java (original) +++ openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/stateless/StatelessInstanceManager.java Tue Jul 13 09:21:07 2010 @@ -31,6 +31,7 @@ import java.util.concurrent.Executor; import java.io.Flushable; import java.io.IOException; +import javax.ejb.EJBContext; import javax.ejb.SessionBean; import javax.ejb.SessionContext; import javax.ejb.ConcurrentAccessTimeoutException; @@ -242,7 +243,6 @@ public class StatelessInstanceManager { private void freeInstance(ThreadContext callContext, Instance instance) { try { callContext.setCurrentOperation(Operation.PRE_DESTROY); - callContext.setCurrentAllowedStates(StatelessContext.getStates()); CoreDeploymentInfo deploymentInfo = callContext.getDeploymentInfo(); Method remove = instance.bean instanceof SessionBean? deploymentInfo.getCreateMethod(): null; @@ -283,6 +283,8 @@ public class StatelessInstanceManager { Data data = new Data(builder.build(), accessTimeout, closeTimeout); deploymentInfo.setContainerData(data); + deploymentInfo.set(EJBContext.class, data.sessionContext); + try { final Context context = deploymentInfo.getJndiEnc(); context.bind("comp/EJBContext", data.sessionContext); Modified: openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/timer/EjbTimerServiceImpl.java URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/timer/EjbTimerServiceImpl.java?rev=963626&r1=963625&r2=963626&view=diff ============================================================================== --- openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/timer/EjbTimerServiceImpl.java (original) +++ openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/timer/EjbTimerServiceImpl.java Tue Jul 13 09:21:07 2010 @@ -27,6 +27,7 @@ import org.apache.openejb.util.LogCatego import org.apache.openejb.util.Logger; import org.apache.openejb.loader.SystemInstance; +import javax.ejb.EJBContext; import javax.ejb.EJBException; import javax.ejb.Timer; import javax.transaction.Status; @@ -45,7 +46,7 @@ public class EjbTimerServiceImpl impleme private static final Logger log = Logger.getInstance(LogCategory.TIMER, "org.apache.openejb.util.resources"); private final TransactionManager transactionManager; - private final DeploymentInfo deployment; + final DeploymentInfo deployment; private final boolean transacted; private final int retryAttempts; @@ -247,7 +248,8 @@ public class EjbTimerServiceImpl impleme * Insure that timer methods can be invoked for the current operation on this Context. */ private void checkState() throws IllegalStateException { - if (!BaseContext.isTimerMethodAllowed()) { + final BaseContext context = (BaseContext) deployment.get(EJBContext.class); + if (!context.isTimerMethodAllowed()) { throw new IllegalStateException("TimerService method not permitted for current operation " + ThreadContext.getThreadContext().getCurrentOperation().name()); } } Modified: openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/timer/TimerData.java URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/timer/TimerData.java?rev=963626&r1=963625&r2=963626&view=diff ============================================================================== --- openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/timer/TimerData.java (original) +++ openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/timer/TimerData.java Tue Jul 13 09:21:07 2010 @@ -30,7 +30,7 @@ import java.util.TimerTask; public class TimerData { private static final Logger log = Logger.getInstance(LogCategory.TIMER, "org.apache.openejb.util.resources"); private final long id; - private final EjbTimerServiceImpl timerService; + final EjbTimerServiceImpl timerService; private final String deploymentId; private final Object primaryKey; private final Object info; Modified: openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/timer/TimerImpl.java URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/timer/TimerImpl.java?rev=963626&r1=963625&r2=963626&view=diff ============================================================================== --- openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/timer/TimerImpl.java (original) +++ openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/timer/TimerImpl.java Tue Jul 13 09:21:07 2010 @@ -16,6 +16,7 @@ */ package org.apache.openejb.core.timer; +import javax.ejb.EJBContext; import javax.ejb.Timer; import javax.ejb.TimerHandle; import javax.ejb.NoSuchObjectLocalException; @@ -25,6 +26,7 @@ import javax.ejb.EJBException; import java.io.Serializable; import java.util.Date; +import org.apache.openejb.DeploymentInfo; import org.apache.openejb.core.BaseContext; import org.apache.openejb.core.ThreadContext; @@ -78,9 +80,10 @@ public class TimerImpl implements Timer * Insure that timer methods can be invoked for the current operation on this Context. */ private void checkState() throws IllegalStateException, NoSuchObjectLocalException { - if (!BaseContext.isTimerMethodAllowed()) { - throw new IllegalStateException("Timer method not permitted for current operation " + ThreadContext.getThreadContext().getCurrentOperation().name()); - } + final DeploymentInfo deployment = timerData.timerService.deployment; + final BaseContext context = (BaseContext) deployment.get(EJBContext.class); + context.check(BaseContext.Call.timerMethod); + if (timerData.isCancelled()) { throw new NoSuchObjectLocalException("Timer has been cancelled"); }
