You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tomee.apache.org by db...@apache.org on 2007/05/16 01:47:51 UTC

svn commit: r538389 - in /incubator/openejb/trunk/openejb3/container: openejb-core/src/main/java/org/apache/openejb/config/ openejb-core/src/main/java/org/apache/openejb/core/ openejb-core/src/main/java/org/apache/openejb/core/interceptor/ openejb-core...

Author: dblevins
Date: Tue May 15 16:47:50 2007
New Revision: 538389

URL: http://svn.apache.org/viewvc?view=rev&rev=538389
Log:
Compliant allowed operations

Added:
    incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/RestrictedUserTransaction.java
    incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/util/Debug.java
    incubator/openejb/trunk/openejb3/container/openejb-jee/src/main/java/org/apache/openejb/jee/TimerConsumer.java
Modified:
    incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/AnnotationDeployer.java
    incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/BaseSessionContext.java
    incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/CoreDeploymentInfo.java
    incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/interceptor/InterceptorData.java
    incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/stateful/SessionSynchronizationCoordinator.java
    incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/stateful/SessionSynchronizationTxPolicy.java
    incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/stateful/StatefulContainerManagedTxPolicy.java
    incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/stateful/StatefulContext.java
    incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/stateless/StatelessContext.java
    incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/transaction/TxManditory.java
    incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/transaction/TxNever.java
    incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/transaction/TxNotSupported.java
    incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/transaction/TxRequired.java
    incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/transaction/TxRequiresNew.java
    incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/transaction/TxSupports.java
    incubator/openejb/trunk/openejb3/container/openejb-jee/src/main/java/org/apache/openejb/jee/MessageDrivenBean.java
    incubator/openejb/trunk/openejb3/container/openejb-jee/src/main/java/org/apache/openejb/jee/SessionBean.java

Modified: incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/AnnotationDeployer.java
URL: http://svn.apache.org/viewvc/incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/AnnotationDeployer.java?view=diff&rev=538389&r1=538388&r2=538389
==============================================================================
--- incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/AnnotationDeployer.java (original)
+++ incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/AnnotationDeployer.java Tue May 15 16:47:50 2007
@@ -60,6 +60,8 @@
 import org.apache.openejb.jee.TransAttribute;
 import org.apache.openejb.jee.TransactionType;
 import org.apache.openejb.jee.SecurityRoleRef;
+import org.apache.openejb.jee.TimerConsumer;
+import org.apache.openejb.jee.SessionType;
 import org.apache.openejb.util.Logger;
 import org.apache.xbean.finder.ClassFinder;
 
@@ -218,6 +220,10 @@
                 if (enterpriseBean.getEjbClass() == null) {
                     enterpriseBean.setEjbClass(beanClass.getName());
                 }
+                if (enterpriseBean instanceof SessionBean) {
+                    SessionBean sessionBean = (SessionBean) enterpriseBean;
+                    sessionBean.setSessionType(SessionType.STATELESS);
+                }
             }
 
             classes = finder.findAnnotatedClasses(Stateful.class);
@@ -232,6 +238,10 @@
                 if (enterpriseBean.getEjbClass() == null) {
                     enterpriseBean.setEjbClass(beanClass.getName());
                 }
+                if (enterpriseBean instanceof SessionBean) {
+                    SessionBean sessionBean = (SessionBean) enterpriseBean;
+                    sessionBean.setSessionType(SessionType.STATEFUL);
+                }
             }
 
             classes = finder.findAnnotatedClasses(MessageDriven.class);
@@ -752,6 +762,16 @@
             if (aroundInvoke == null) {
                 for (Method method : classFinder.findAnnotatedMethods(javax.interceptor.AroundInvoke.class)) {
                     bean.getAroundInvoke().add(new AroundInvoke(method));
+                }
+            }
+
+            if (bean instanceof TimerConsumer) {
+                TimerConsumer timerConsumer = (TimerConsumer) bean;
+                if (timerConsumer.getTimeoutMethod() == null) {
+                    List<Method> timeoutMethods = classFinder.findAnnotatedMethods(javax.ejb.Timeout.class);
+                    for (Method method : timeoutMethods) {
+                        timerConsumer.setTimeoutMethod(new NamedMethod(method));
+                    }
                 }
             }
 

Modified: incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/BaseSessionContext.java
URL: http://svn.apache.org/viewvc/incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/BaseSessionContext.java?view=diff&rev=538389&r1=538388&r2=538389
==============================================================================
--- incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/BaseSessionContext.java (original)
+++ incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/BaseSessionContext.java Tue May 15 16:47:50 2007
@@ -26,6 +26,11 @@
 import javax.ejb.TimerService;
 import javax.transaction.TransactionManager;
 import javax.transaction.UserTransaction;
+import javax.transaction.NotSupportedException;
+import javax.transaction.SystemException;
+import javax.transaction.HeuristicMixedException;
+import javax.transaction.HeuristicRollbackException;
+import javax.transaction.RollbackException;
 import javax.xml.rpc.handler.MessageContext;
 
 import org.apache.openejb.DeploymentInfo;
@@ -79,26 +84,17 @@
             ThreadContext threadContext = ThreadContext.getThreadContext();
             DeploymentInfo di = threadContext.getDeploymentInfo();
 
-            EjbObjectProxyHandler handler = new StatelessEjbObjectHandler(di, threadContext.getPrimaryKey(), InterfaceType.EJB_LOCAL, new ArrayList<Class>());
-            try {
-                Class[] interfaces = new Class[]{di.getLocalInterface(), IntraVmProxy.class};
-                return (EJBLocalObject) ProxyManager.newProxyInstance(interfaces, handler);
-            } catch (IllegalAccessException iae) {
-                throw new InternalErrorException("Could not create IVM proxy for " + di.getLocalInterface() + " interface", iae);
-            }
+            if (di.getLocalHomeInterface() == null) throw new IllegalStateException("Bean does not have an EJBLocalObject interface: "+di.getDeploymentID());
+
+            return (EJBLocalObject) EjbObjectProxyHandler.createProxy(di, threadContext.getPrimaryKey(), InterfaceType.EJB_LOCAL);
         }
 
         public EJBObject getEJBObject() throws IllegalStateException {
             ThreadContext threadContext = ThreadContext.getThreadContext();
             DeploymentInfo di = threadContext.getDeploymentInfo();
+            if (di.getHomeInterface() == null) throw new IllegalStateException("Bean does not have an EJBObject interface: "+di.getDeploymentID());
 
-            EjbObjectProxyHandler handler = new StatelessEjbObjectHandler(di, threadContext.getPrimaryKey(), InterfaceType.EJB_OBJECT, new ArrayList<Class>());
-            try {
-                Class[] interfaces = new Class[]{di.getRemoteInterface(), IntraVmProxy.class};
-                return (EJBObject) ProxyManager.newProxyInstance(interfaces, handler);
-            } catch (IllegalAccessException iae) {
-                throw new InternalErrorException("Could not create IVM proxy for " + di.getLocalInterface() + " interface", iae);
-            }
+            return (EJBObject) EjbObjectProxyHandler.createProxy(di, threadContext.getPrimaryKey(), InterfaceType.EJB_OBJECT);
         }
 
         public MessageContext getMessageContext() throws IllegalStateException {
@@ -229,6 +225,10 @@
         public boolean isTimerAccessAllowed() {
             return false;
         }
+
+        public boolean isTimerMethodAllowed() {
+            return false;
+        }
     }
 
     /**
@@ -286,6 +286,13 @@
 
         public boolean isTimerMethodAllowed() {
             return false;
+        }
+    }
+
+    public static class PostConstructSessionState extends LifecycleSessionState {
+
+        public UserTransaction getUserTransaction(UserTransaction userTransaction) throws IllegalStateException {
+            return new RestrictedUserTransaction(super.getUserTransaction(userTransaction));
         }
     }
 

Modified: incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/CoreDeploymentInfo.java
URL: http://svn.apache.org/viewvc/incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/CoreDeploymentInfo.java?view=diff&rev=538389&r1=538388&r2=538389
==============================================================================
--- incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/CoreDeploymentInfo.java (original)
+++ incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/CoreDeploymentInfo.java Tue May 15 16:47:50 2007
@@ -375,7 +375,11 @@
                 }
             } else if (componentType == BeanType.STATEFUL) {
                 policy = new TxRequired((TransactionContainer) container);
-                policy = new StatefulContainerManagedTxPolicy(policy);
+                if (!isBeanManagedTransaction && SessionSynchronization.class.isAssignableFrom(beanClass)) {
+                    policy = new SessionSynchronizationTxPolicy(policy);
+                } else {
+                    policy = new StatefulContainerManagedTxPolicy(policy);
+                }
             } else {
                 // default transaction policy is required
                 policy = new TxRequired((TransactionContainer) container);
@@ -635,11 +639,9 @@
 
             if (SessionSynchronization.class.isAssignableFrom(beanClass)) {
                 if (!transAttribute.equals("Never") && !transAttribute.equals("NotSupported")) {
-
                     policy = new SessionSynchronizationTxPolicy(policy);
                 }
             } else {
-
                 policy = new StatefulContainerManagedTxPolicy(policy);
             }
         }

Added: incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/RestrictedUserTransaction.java
URL: http://svn.apache.org/viewvc/incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/RestrictedUserTransaction.java?view=auto&rev=538389
==============================================================================
--- incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/RestrictedUserTransaction.java (added)
+++ incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/RestrictedUserTransaction.java Tue May 15 16:47:50 2007
@@ -0,0 +1,72 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+package org.apache.openejb.core;
+
+import javax.transaction.UserTransaction;
+import javax.transaction.NotSupportedException;
+import javax.transaction.SystemException;
+import javax.transaction.HeuristicMixedException;
+import javax.transaction.HeuristicRollbackException;
+import javax.transaction.RollbackException;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class RestrictedUserTransaction implements UserTransaction {
+    private final UserTransaction userTransaction;
+
+    public RestrictedUserTransaction(UserTransaction userTransaction) {
+        this.userTransaction = userTransaction;
+    }
+
+    public void begin() throws NotSupportedException, SystemException {
+        checkAccess("begin");
+        userTransaction.begin();
+    }
+
+    public void commit() throws HeuristicMixedException, HeuristicRollbackException, IllegalStateException, RollbackException, SecurityException, SystemException {
+        checkAccess("commit");
+        userTransaction.commit();
+    }
+
+    public int getStatus() throws SystemException {
+        checkAccess("getStatus");
+        return userTransaction.getStatus();
+    }
+
+    public void rollback() throws IllegalStateException, SecurityException, SystemException {
+        checkAccess("rollback");
+        userTransaction.rollback();
+    }
+
+    public void setRollbackOnly() throws IllegalStateException, SystemException {
+        checkAccess("setRollbackOnly");
+        userTransaction.setRollbackOnly();
+    }
+
+    public void setTransactionTimeout(int i) throws SystemException {
+        checkAccess("setTransactionTimeout");
+        userTransaction.setTransactionTimeout(i);
+    }
+
+    private void checkAccess(String methodName) {
+        Operation operation = ThreadContext.getThreadContext().getCurrentOperation();
+        if (operation == Operation.POST_CONSTRUCT) {
+            throw new IllegalStateException("userTransaction."+methodName +"() not allowed in PostConstruct");
+        }
+    }
+}

Modified: incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/interceptor/InterceptorData.java
URL: http://svn.apache.org/viewvc/incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/interceptor/InterceptorData.java?view=diff&rev=538389&r1=538388&r2=538389
==============================================================================
--- incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/interceptor/InterceptorData.java (original)
+++ incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/interceptor/InterceptorData.java Tue May 15 16:47:50 2007
@@ -76,6 +76,9 @@
             case PRE_DESTROY: return getPreDestroy();
             case ACTIVATE: return getPostActivate();
             case PASSIVATE: return getPrePassivate();
+            case AFTER_BEGIN: return getAroundInvoke();
+            case AFTER_COMPLETION: return getAroundInvoke();
+            case BEFORE_COMPLETION: return getAroundInvoke();
         }
         return Collections.EMPTY_LIST;
     }

Modified: incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/stateful/SessionSynchronizationCoordinator.java
URL: http://svn.apache.org/viewvc/incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/stateful/SessionSynchronizationCoordinator.java?view=diff&rev=538389&r1=538388&r2=538389
==============================================================================
--- incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/stateful/SessionSynchronizationCoordinator.java (original)
+++ incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/stateful/SessionSynchronizationCoordinator.java Tue May 15 16:47:50 2007
@@ -22,6 +22,8 @@
 import org.apache.openejb.core.stateful.StatefulContext;
 import org.apache.openejb.core.Operation;
 import org.apache.openejb.core.ThreadContext;
+import org.apache.openejb.core.interceptor.InterceptorStack;
+import org.apache.openejb.core.interceptor.InterceptorData;
 import org.apache.openejb.core.transaction.TransactionContext;
 import org.apache.openejb.util.Logger;
 
@@ -31,6 +33,8 @@
 import javax.transaction.TransactionManager;
 import java.util.HashMap;
 import java.util.Map;
+import java.util.List;
+import java.lang.reflect.Method;
 
 public class SessionSynchronizationCoordinator implements javax.transaction.Synchronization {
     private static Logger logger = Logger.getInstance("OpenEJB", "org.apache.openejb.util.resources");
@@ -44,7 +48,7 @@
         this.transactionManager = transactionManager;
     }
 
-    public static void registerSessionSynchronization(SessionSynchronization session, TransactionContext context) throws javax.transaction.SystemException, javax.transaction.RollbackException {
+    public static void registerSessionSynchronization(StatefulInstanceManager.Instance instance, TransactionContext context) throws javax.transaction.SystemException, javax.transaction.RollbackException {
         SessionSynchronizationCoordinator coordinator = null;
 
         coordinator = coordinators.get(context.currentTx);
@@ -61,10 +65,10 @@
             coordinators.put(context.currentTx, coordinator);
         }
 
-        coordinator._registerSessionSynchronization(session, context.callContext);
+        coordinator._registerSessionSynchronization(instance, context.callContext);
     }
 
-    private void _registerSessionSynchronization(SessionSynchronization session, ThreadContext callContext) {
+    private void _registerSessionSynchronization(StatefulInstanceManager.Instance instance, ThreadContext callContext) {
         boolean registered = sessionSynchronizations.containsKey(callContext.getPrimaryKey());
 
         if (registered) return;
@@ -80,7 +84,11 @@
         BaseContext.State[] originalStates = callContext.setCurrentAllowedStates(StatefulContext.getStates());
         try {
 
-            session.afterBegin();
+            Method afterBegin = SessionSynchronization.class.getMethod("afterBegin");
+
+            List<InterceptorData> interceptors = callContext.getDeploymentInfo().getMethodInterceptors(afterBegin);
+            InterceptorStack interceptorStack = new InterceptorStack(instance.bean, afterBegin, Operation.AFTER_BEGIN, interceptors, instance.interceptors);
+            interceptorStack.invoke();
 
         } catch (Exception e) {
             String message = "An unexpected system exception occured while invoking the afterBegin method on the SessionSynchronization object: " + e.getClass().getName() + " " + e.getMessage();
@@ -115,8 +123,13 @@
                 callContext.setCurrentAllowedStates(StatefulContext.getStates());
 
                 StatefulInstanceManager.Instance instance = (StatefulInstanceManager.Instance) instanceManager.obtainInstance(callContext.getPrimaryKey(), callContext);
-                SessionSynchronization bean = (SessionSynchronization) instance.bean;
-                bean.beforeCompletion();
+
+                Method beforeCompletion = SessionSynchronization.class.getMethod("beforeCompletion");
+
+                List<InterceptorData> interceptors = callContext.getDeploymentInfo().getMethodInterceptors(beforeCompletion);
+                InterceptorStack interceptorStack = new InterceptorStack(instance.bean, beforeCompletion, Operation.BEFORE_COMPLETION, interceptors, instance.interceptors);
+                interceptorStack.invoke();
+
                 instanceManager.poolInstance(callContext, instance);
             } catch (org.apache.openejb.InvalidateReferenceException inv) {
 
@@ -179,9 +192,13 @@
                 callContext.setCurrentAllowedStates(StatefulContext.getStates());
 
                 StatefulInstanceManager.Instance instance = (StatefulInstanceManager.Instance) instanceManager.obtainInstance(callContext.getPrimaryKey(), callContext);
-                SessionSynchronization bean = (SessionSynchronization) instance.bean;
 
-                bean.afterCompletion(status == Status.STATUS_COMMITTED);
+                Method afterCompletion = SessionSynchronization.class.getMethod("afterCompletion", boolean.class);
+
+                List<InterceptorData> interceptors = callContext.getDeploymentInfo().getMethodInterceptors(afterCompletion);
+                InterceptorStack interceptorStack = new InterceptorStack(instance.bean, afterCompletion, Operation.AFTER_COMPLETION, interceptors, instance.interceptors);
+                interceptorStack.invoke(status == Status.STATUS_COMMITTED);
+
                 instanceManager.poolInstance(callContext, instance);
             } catch (org.apache.openejb.InvalidateReferenceException inv) {
 

Modified: incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/stateful/SessionSynchronizationTxPolicy.java
URL: http://svn.apache.org/viewvc/incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/stateful/SessionSynchronizationTxPolicy.java?view=diff&rev=538389&r1=538388&r2=538389
==============================================================================
--- incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/stateful/SessionSynchronizationTxPolicy.java (original)
+++ incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/stateful/SessionSynchronizationTxPolicy.java Tue May 15 16:47:50 2007
@@ -47,8 +47,7 @@
 
         try {
             StatefulInstanceManager.Instance instance2 = (StatefulInstanceManager.Instance) instance;
-            SessionSynchronization session = (SessionSynchronization) instance2.bean ;
-            SessionSynchronizationCoordinator.registerSessionSynchronization(session, context);
+            SessionSynchronizationCoordinator.registerSessionSynchronization(instance2, context);
         } catch (javax.transaction.RollbackException e) {
             logger.error("Cannot register the SessionSynchronization bean with the transaction, the transaction has been rolled back");
             handleSystemException(e, instance, context);

Modified: incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/stateful/StatefulContainerManagedTxPolicy.java
URL: http://svn.apache.org/viewvc/incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/stateful/StatefulContainerManagedTxPolicy.java?view=diff&rev=538389&r1=538388&r2=538389
==============================================================================
--- incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/stateful/StatefulContainerManagedTxPolicy.java (original)
+++ incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/stateful/StatefulContainerManagedTxPolicy.java Tue May 15 16:47:50 2007
@@ -23,6 +23,16 @@
 import org.apache.openejb.core.transaction.TransactionContext;
 import org.apache.openejb.core.transaction.TransactionPolicy;
 
+/**
+ * Wraps the TxPolicies for Stateful Session beans with container-managed
+ * transaction demarkation that do not implement the SessionSynchronization
+ * interface.
+ *
+ * The following method TxPolicies are wrapped regardless:
+ *
+ * TX_NEVER
+ * TX_NOT_SUPPORTED
+ */
 public class StatefulContainerManagedTxPolicy extends TransactionPolicy {
 
     protected TransactionPolicy policy;

Modified: incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/stateful/StatefulContext.java
URL: http://svn.apache.org/viewvc/incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/stateful/StatefulContext.java?view=diff&rev=538389&r1=538388&r2=538389
==============================================================================
--- incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/stateful/StatefulContext.java (original)
+++ incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/stateful/StatefulContext.java Tue May 15 16:47:50 2007
@@ -23,6 +23,7 @@
 import org.apache.openejb.core.BaseSessionContext;
 import org.apache.openejb.core.Operation;
 import org.apache.openejb.core.ThreadContext;
+import org.apache.openejb.core.RestrictedUserTransaction;
 import org.apache.openejb.spi.SecurityService;
 
 import java.security.Principal;
@@ -56,22 +57,10 @@
         return state;
     }
 
-    static {
-        states[Operation.INJECTION.ordinal()] = new InjectionSessionState();
-        states[Operation.CREATE.ordinal()] = new LifecycleSessionState();
-        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 LifecycleSessionState();
-        states[Operation.REMOVE.ordinal()] = new LifecycleSessionState();
-    }
-
     /**
      * PostConstruct, Pre-Destroy lifecycle callback interceptor methods
      */
-    public static class LifecycleSessionState extends SessionState {
+    public static class LifecycleStatefulSessionState extends SessionState {
 
         public MessageContext getMessageContext() throws IllegalStateException {
             throw new IllegalStateException();
@@ -133,14 +122,6 @@
             throw new IllegalStateException();
         }
 
-        public Principal getCallerPrincipal(SecurityService securityService) {
-            throw new IllegalStateException();
-        }
-
-        public boolean isCallerInRole(SecurityService securityService, String roleName) {
-            throw new IllegalStateException();
-        }
-
         public void setRollbackOnly(TransactionManager transactionManager) throws IllegalStateException {
             throw new IllegalStateException();
         }
@@ -173,4 +154,18 @@
             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();
+    }
+
 }

Modified: incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/stateless/StatelessContext.java
URL: http://svn.apache.org/viewvc/incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/stateless/StatelessContext.java?view=diff&rev=538389&r1=538388&r2=538389
==============================================================================
--- incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/stateless/StatelessContext.java (original)
+++ incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/stateless/StatelessContext.java Tue May 15 16:47:50 2007
@@ -68,6 +68,7 @@
         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: incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/transaction/TxManditory.java
URL: http://svn.apache.org/viewvc/incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/transaction/TxManditory.java?view=diff&rev=538389&r1=538388&r2=538389
==============================================================================
--- incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/transaction/TxManditory.java (original)
+++ incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/transaction/TxManditory.java Tue May 15 16:47:50 2007
@@ -21,6 +21,23 @@
 
 import javax.transaction.TransactionRequiredException;
 
+/**
+ * 17.6.2.5 Mandatory
+ *
+ * The Container must invoke an enterprise Bean method whose transaction
+ * attribute is set to Mandatory in a client's transaction context. The client
+ * is required to call with a transaction context.
+ *
+ * ¥ If the client calls with a transaction context, the container invokes the
+ *   enterprise Bean's method in the client's transaction context.
+ *
+ * ¥ If the client calls without a transaction context, the Container throws
+ *   the javax.transaction.TransactionRequiredException exception if the
+ *   client is a remote client, or the
+ *   javax.ejb.TransactionRequiredLocalException if the client is a local
+ *   client.
+ *
+ */
 public class TxManditory extends TransactionPolicy {
 
     public TxManditory(TransactionContainer container) {

Modified: incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/transaction/TxNever.java
URL: http://svn.apache.org/viewvc/incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/transaction/TxNever.java?view=diff&rev=538389&r1=538388&r2=538389
==============================================================================
--- incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/transaction/TxNever.java (original)
+++ incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/transaction/TxNever.java Tue May 15 16:47:50 2007
@@ -21,6 +21,21 @@
 
 import java.rmi.RemoteException;
 
+/**
+ * 17.6.2.6 Never
+ *
+ * The Container invokes an enterprise Bean method whose transaction attribute
+ * is set to Never without a transaction context defined by the EJB spec.
+ *
+ * The client is required to call without a transaction context.
+ *
+ * ¥ If the client calls with a transaction context, the Container throws the
+ *   java.rmi.RemoteException exception if the client is a remote client, or
+ *   the javax.ejb.EJBException if the client is a local client.
+ * ¥ If the client calls without a transaction context, the Container performs
+ *   the same steps as described in the NotSupported case.
+ *
+ */
 public class TxNever extends TransactionPolicy {
 
     public TxNever(TransactionContainer container) {

Modified: incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/transaction/TxNotSupported.java
URL: http://svn.apache.org/viewvc/incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/transaction/TxNotSupported.java?view=diff&rev=538389&r1=538388&r2=538389
==============================================================================
--- incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/transaction/TxNotSupported.java (original)
+++ incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/transaction/TxNotSupported.java Tue May 15 16:47:50 2007
@@ -21,6 +21,26 @@
 
 import javax.transaction.InvalidTransactionException;
 
+/**
+ * 17.6.2.1 NotSupported
+ *
+ * The Container invokes an enterprise Bean method whose transaction attribute
+ * is set to NotSupported with an unspecified transaction context.
+ *
+ * If a client calls with a transaction context, the container suspends the
+ * association of the transaction context with the current thread before
+ * invoking the enterprise bean's business method. The container resumes the
+ * suspended association when the business method has completed. The suspended
+ * transaction context of the client is not passed to the resource managers or
+ * other enterprise Bean objects that are invoked from the business method.
+ *
+ * If the business method invokes other enterprise beans, the Container passes
+ * no transaction context with the invocation.
+ *
+ * Refer to Subsection 17.6.5 for more details of how the Container can
+ * implement this case.
+ *
+ */
 public class TxNotSupported extends TransactionPolicy {
 
     public TxNotSupported(TransactionContainer container) {

Modified: incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/transaction/TxRequired.java
URL: http://svn.apache.org/viewvc/incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/transaction/TxRequired.java?view=diff&rev=538389&r1=538388&r2=538389
==============================================================================
--- incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/transaction/TxRequired.java (original)
+++ incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/transaction/TxRequired.java Tue May 15 16:47:50 2007
@@ -21,6 +21,27 @@
 import org.apache.openejb.ApplicationException;
 import org.apache.openejb.SystemException;
 
+/**
+ * 17.6.2.2 Required
+ *
+ * The Container must invoke an enterprise Bean method whose transaction
+ * attribute is set to Required with a valid transaction context.
+ *
+ * If a client invokes the enterprise Bean's method while the client is
+ * associated with a transaction context, the container invokes the enterprise
+ * Bean's method in the client's transaction context.
+ *
+ * If the client invokes the enterprise Bean's method while the client is not
+ * associated with a transaction context, the container automatically starts a
+ * new transaction before delegating a method call to the enterprise Bean
+ * business method. The Container automatically enlists all the resource
+ * managers accessed by the business method with the transaction. If the
+ * business method invokes other enterprise beans, the Container passes the
+ * transaction context with the invocation. The Container attempts to commit
+ * the transaction when the business method has completed. The container
+ * performs the commit protocol before the method result is sent to the client.
+ *
+ */
 public class TxRequired extends TransactionPolicy {
 
     public TxRequired(TransactionContainer container) {

Modified: incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/transaction/TxRequiresNew.java
URL: http://svn.apache.org/viewvc/incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/transaction/TxRequiresNew.java?view=diff&rev=538389&r1=538388&r2=538389
==============================================================================
--- incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/transaction/TxRequiresNew.java (original)
+++ incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/transaction/TxRequiresNew.java Tue May 15 16:47:50 2007
@@ -21,6 +21,29 @@
 
 import javax.transaction.Status;
 
+/**
+ * 17.6.2.4 RequiresNew
+ *
+ * The Container must invoke an enterprise Bean method whose transaction
+ * attribute is set to RequiresNew with a new transaction context.
+ *
+ * If the client invokes the enterprise BeanÕs method while the client is not
+ * associated with a transaction context, the container automatically starts a
+ * new transaction before delegating a method call to the enterprise Bean
+ * business method. The Container automatically enlists all the resource
+ * managers accessed by the business method with the transaction. If the
+ * business method invokes other enterprise beans, the Container passes the
+ * transaction context with the invocation. The Container attempts to commit
+ * the transaction when the business method has completed. The container
+ * performs the commit protocol before the method result is sent to the client.
+ *
+ * If a client calls with a transaction context, the container suspends the
+ * association of the transaction context with the current thread before
+ * starting the new transaction and invoking the business method. The container
+ * resumes the suspended transaction association after the business method and
+ * the new transaction have been completed.
+ *
+ */
 public class TxRequiresNew extends TransactionPolicy {
 
     public TxRequiresNew(TransactionContainer container) {

Modified: incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/transaction/TxSupports.java
URL: http://svn.apache.org/viewvc/incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/transaction/TxSupports.java?view=diff&rev=538389&r1=538388&r2=538389
==============================================================================
--- incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/transaction/TxSupports.java (original)
+++ incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/transaction/TxSupports.java Tue May 15 16:47:50 2007
@@ -19,6 +19,25 @@
 import org.apache.openejb.ApplicationException;
 import org.apache.openejb.SystemException;
 
+/**
+ * 17.6.2.3 Supports
+ *
+ * The Container invokes an enterprise Bean method whose transaction attribute
+ * is set to Supports as follows.
+ *
+ * ¥ If the client calls with a transaction context, the Container performs
+ *   the same steps as described in the Required case.
+ *
+ * ¥ If the client calls without a transaction context, the Container performs
+ *   the same steps as described in the NotSupported case.
+ *
+ * The Supports transaction attribute must be used with caution. This is
+ * because of the different transactional semantics provided by the two
+ * possible modes of execution. Only the enterprise beans that will
+ * execute correctly in both modes should use the Supports transaction
+ * attribute.
+ *
+ */
 public class TxSupports extends TransactionPolicy {
 
     public TxSupports(TransactionContainer container) {

Added: incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/util/Debug.java
URL: http://svn.apache.org/viewvc/incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/util/Debug.java?view=auto&rev=538389
==============================================================================
--- incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/util/Debug.java (added)
+++ incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/util/Debug.java Tue May 15 16:47:50 2007
@@ -0,0 +1,33 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+package org.apache.openejb.util;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.PrintStream;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class Debug {
+
+    public static String printStackTrace(Throwable t) {
+        ByteArrayOutputStream baos = new ByteArrayOutputStream();
+        t.printStackTrace(new PrintStream(baos));
+        return new String(baos.toByteArray());
+    }
+}

Modified: incubator/openejb/trunk/openejb3/container/openejb-jee/src/main/java/org/apache/openejb/jee/MessageDrivenBean.java
URL: http://svn.apache.org/viewvc/incubator/openejb/trunk/openejb3/container/openejb-jee/src/main/java/org/apache/openejb/jee/MessageDrivenBean.java?view=diff&rev=538389&r1=538388&r2=538389
==============================================================================
--- incubator/openejb/trunk/openejb3/container/openejb-jee/src/main/java/org/apache/openejb/jee/MessageDrivenBean.java (original)
+++ incubator/openejb/trunk/openejb3/container/openejb-jee/src/main/java/org/apache/openejb/jee/MessageDrivenBean.java Tue May 15 16:47:50 2007
@@ -106,7 +106,7 @@
         "preDestroy",
         "securityIdentity"
         })
-public class MessageDrivenBean implements EnterpriseBean {
+public class MessageDrivenBean implements EnterpriseBean, TimerConsumer  {
 
     @XmlTransient
     protected TextMap description = new TextMap();

Modified: incubator/openejb/trunk/openejb3/container/openejb-jee/src/main/java/org/apache/openejb/jee/SessionBean.java
URL: http://svn.apache.org/viewvc/incubator/openejb/trunk/openejb3/container/openejb-jee/src/main/java/org/apache/openejb/jee/SessionBean.java?view=diff&rev=538389&r1=538388&r2=538389
==============================================================================
--- incubator/openejb/trunk/openejb3/container/openejb-jee/src/main/java/org/apache/openejb/jee/SessionBean.java (original)
+++ incubator/openejb/trunk/openejb3/container/openejb-jee/src/main/java/org/apache/openejb/jee/SessionBean.java Tue May 15 16:47:50 2007
@@ -127,7 +127,7 @@
         "securityRoleRef",
         "securityIdentity"
         })
-public class SessionBean implements EnterpriseBean, RemoteBean, Session {
+public class SessionBean implements EnterpriseBean, RemoteBean, Session, TimerConsumer {
     @XmlTransient
     protected TextMap description = new TextMap();
     @XmlTransient

Added: incubator/openejb/trunk/openejb3/container/openejb-jee/src/main/java/org/apache/openejb/jee/TimerConsumer.java
URL: http://svn.apache.org/viewvc/incubator/openejb/trunk/openejb3/container/openejb-jee/src/main/java/org/apache/openejb/jee/TimerConsumer.java?view=auto&rev=538389
==============================================================================
--- incubator/openejb/trunk/openejb3/container/openejb-jee/src/main/java/org/apache/openejb/jee/TimerConsumer.java (added)
+++ incubator/openejb/trunk/openejb3/container/openejb-jee/src/main/java/org/apache/openejb/jee/TimerConsumer.java Tue May 15 16:47:50 2007
@@ -0,0 +1,26 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+package org.apache.openejb.jee;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public interface TimerConsumer {
+    NamedMethod getTimeoutMethod();
+
+    void setTimeoutMethod(NamedMethod value);
+}