geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ge...@apache.org
Subject cvs commit: incubator-geronimo/modules/core/src/java/org/apache/geronimo/ejb/metadata CommitOption.java EJBMetadata.java EJBMetadataImpl.java MethodMetadata.java MethodMetadataImpl.java TransactionAttribute.java TransactionDemarcation.java
Date Sun, 10 Aug 2003 20:51:55 GMT
geirm       2003/08/10 13:51:55

  Added:       modules/core/src/java/org/apache/geronimo/ejb
                        CallbackInterceptor.java EJBInvocationUtil.java
                        EJBProxyFactory.java EJBProxyFactoryManager.java
                        EnterpriseContext.java Entrancy.java
                        GeronimoSessionContext.java
                        SimpleEnterpriseContext.java
                        StatelessLifeCycleInterceptor.java
                        SynchronizationRegistry.java
               modules/core/src/java/org/apache/geronimo/ejb/cache
                        EnterpriseContextInstanceCache.java
                        EnterpriseContextInstancePool.java
                        EntityCreationInterceptor.java
                        EntitySynchronizationInterceptor.java
                        StatefulInstanceInterceptor.java
                        StatefulSessionSynchronizationInterceptor.java
                        StatelessInstanceFactory.java
                        StatelessInstanceInterceptor.java
               modules/core/src/java/org/apache/geronimo/ejb/container
                        ContainerImpl.java EJBContainerUtil.java
                        EJBPlugins.java PersistenceManager.java
               modules/core/src/java/org/apache/geronimo/ejb/context
                        CMTInterceptor.java EJBTransactionException.java
                        ExecutionContext.java
                        ExecutionContextInterceptor.java
                        GeronimoUserTransaction.java
                        NoTxExecutionContext.java
                        StatefulBMTInterceptor.java
                        StatelessBMTInterceptor.java
                        TransactionInterceptor.java TxExecutionContext.java
               modules/core/src/java/org/apache/geronimo/ejb/metadata
                        CommitOption.java EJBMetadata.java
                        EJBMetadataImpl.java MethodMetadata.java
                        MethodMetadataImpl.java TransactionAttribute.java
                        TransactionDemarcation.java
  Log:
  initial import
  
  Revision  Changes    Path
  1.1                  incubator-geronimo/modules/core/src/java/org/apache/geronimo/ejb/CallbackInterceptor.java
  
  Index: CallbackInterceptor.java
  ===================================================================
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2003 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Apache" and "Apache Software Foundation" and
   *    "Apache Geronimo" must not be used to endorse or promote products
   *    derived from this software without prior written permission. For
   *    written permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    "Apache Geronimo", nor may "Apache" appear in their name, without
   *    prior written permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   * ====================================================================
   */
  package org.apache.geronimo.ejb;
  
  import java.lang.reflect.Method;
  import java.lang.reflect.InvocationTargetException;
  
  import javax.ejb.EJBException;
  
  import org.apache.geronimo.ejb.metadata.EJBMetadata;
  import org.apache.geronimo.ejb.metadata.MethodMetadata;
  import org.apache.geronimo.ejb.container.EJBPlugins;
  import org.apache.geronimo.ejb.EnterpriseContext;
  import org.apache.geronimo.ejb.EJBInvocationUtil;
  import org.apache.geronimo.common.AbstractInterceptor;
  import org.apache.geronimo.common.InvocationResult;
  import org.apache.geronimo.common.Invocation;
  import org.apache.geronimo.common.SimpleInvocationResult;
  
  /**
   * This interceptor calls the callback method or throws an
   * IllegalArgumentException if there is no callback method in the invocation
   * object.  This should be the last interceptor in the chain.
   *
   *
   * @version $Revision: 1.1 $ $Date: 2003/08/10 20:51:54 $
   */
  public final class CallbackInterceptor extends AbstractInterceptor {
      public InvocationResult invoke(Invocation invocation) throws Exception {
          // Instance
          EnterpriseContext ctx = EJBInvocationUtil.getEnterpriseContext(invocation);
          if (ctx == null) {
              throw new IllegalArgumentException("Invocation does not contain an enterprise context");
          }
          Object instance = ctx.getInstance();
          if (instance == null) {
              throw new IllegalArgumentException("Context does not have an instance assigned");
          }
  
          // Method metadata
          EJBMetadata ejbMetadata = EJBPlugins.getEJBMetadata(getContainer());
          Method interfaceMethod = EJBInvocationUtil.getMethod(invocation);
          MethodMetadata methodMetadata = ejbMetadata.getMethodMetadata(interfaceMethod);
  
          // Callback Method
          Method callbackMethod = methodMetadata.getCallbackMethod();
          if (callbackMethod == null) {
              throw new IllegalArgumentException("Invocation does not contain a callback method");
          }
  
          // Callback Arguments
          Object[] callbackArgs = EJBInvocationUtil.getArguments(invocation);
  
          // Invoke it
          try {
              return new SimpleInvocationResult(callbackMethod.invoke(instance, callbackArgs));
          } catch (IllegalAccessException e) {
              // This method is using the Java language access control and the
              // underlying method is inaccessible.
              throw new EJBException(e);
          } catch (InvocationTargetException e) {
              // unwrap the exception
              Throwable t = e.getTargetException();
              if (t instanceof Exception) {
                  throw (Exception) t;
              } else if (t instanceof Error) {
                  throw (Error) t;
              } else {
                  throw new Error("Unexpected Throwable", t);
              }
          }
      }
  }
  
  
  
  1.1                  incubator-geronimo/modules/core/src/java/org/apache/geronimo/ejb/EJBInvocationUtil.java
  
  Index: EJBInvocationUtil.java
  ===================================================================
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2003 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Apache" and "Apache Software Foundation" and
   *    "Apache Geronimo" must not be used to endorse or promote products
   *    derived from this software without prior written permission. For
   *    written permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    "Apache Geronimo", nor may "Apache" appear in their name, without
   *    prior written permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   * ====================================================================
   */
  package org.apache.geronimo.ejb;
  
  import java.io.ObjectStreamException;
  import java.io.Serializable;
  import java.lang.reflect.Method;
  import java.security.Principal;
  
  import org.apache.geronimo.ejb.EnterpriseContext;
  import org.apache.geronimo.common.Invocation;
  
  /**
   *
   *
   *
   * @version $Revision: 1.1 $ $Date: 2003/08/10 20:51:54 $
   */
  public final class EJBInvocationUtil implements Serializable {
      // Be careful here.  If you change the oridnals, this class must be changed on evey client.
      private static int MAX_ORIDNAL = 5;
      private static final EJBInvocationUtil[] values = new EJBInvocationUtil[MAX_ORIDNAL + 1];
      private static final EJBInvocationUtil METHOD = new EJBInvocationUtil("METHOD", 0);
      private static final EJBInvocationUtil ID = new EJBInvocationUtil("ID", 1);
      private static final EJBInvocationUtil ARGUMENTS = new EJBInvocationUtil("ARGUMENTS", 2);
      private static final EJBInvocationUtil EJB_CONTEXT_KEY = new EJBInvocationUtil("EJB_CONTEXT_KEY", 3);
      private static final EJBInvocationUtil PRINCIPAL = new EJBInvocationUtil("PRINCIPAL", 4);
      private static final EJBInvocationUtil CREDENTIALS = new EJBInvocationUtil("CREDENTIALS", 5);
  
      public static Method getMethod(Invocation invocation) {
          return (Method) invocation.getAsIs(METHOD);
      }
  
      public static void putMethod(Invocation invocation, Method method) {
          invocation.putAsIs(METHOD, method);
      }
  
      public static Object getId(Invocation invocation) {
          return invocation.getMarshal(ID);
      }
  
      public static void putId(Invocation invocation, Object id) {
          invocation.putMarshal(ID, id);
      }
  
      public static Object[] getArguments(Invocation invocation) {
          return (Object[]) invocation.getMarshal(ARGUMENTS);
      }
  
      public static void putArguments(Invocation invocation, Object[] arguments) {
          invocation.putMarshal(ARGUMENTS, arguments);
      }
  
      public static EnterpriseContext getEnterpriseContext(Invocation invocation) {
          return (EnterpriseContext) invocation.getTransient(EJB_CONTEXT_KEY);
      }
  
      public static void putEnterpriseContext(Invocation invocation, EnterpriseContext enterpriseContext) {
          invocation.putTransient(EJB_CONTEXT_KEY, enterpriseContext);
      }
  
      public static Principal getPrincipal(Invocation invocation) {
          return (Principal) invocation.getAsIs(PRINCIPAL);
      }
  
      public static void putPrincipal(Invocation invocation, Principal principal) {
          invocation.putAsIs(PRINCIPAL, principal);
      }
  
      public static Object getCredentials(Invocation invocation) {
          return invocation.getMarshal(CREDENTIALS);
      }
  
      public static void putCredentials(Invocation invocation, Object credentials) {
          invocation.putMarshal(CREDENTIALS, credentials);
      }
  
      private final transient String name;
      private final int ordinal;
  
      private EJBInvocationUtil(String name, int ordinal) {
          assert(ordinal < MAX_ORIDNAL);
          assert(values[ordinal] == null);
          this.name = name;
          this.ordinal = ordinal;
          values[ordinal] = this;
      }
  
      public String toString() {
          return name;
      }
  
      Object readResolve() throws ObjectStreamException {
          return values[ordinal];
      }
  }
  
  
  
  1.1                  incubator-geronimo/modules/core/src/java/org/apache/geronimo/ejb/EJBProxyFactory.java
  
  Index: EJBProxyFactory.java
  ===================================================================
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2003 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Apache" and "Apache Software Foundation" and
   *    "Apache Geronimo" must not be used to endorse or promote products
   *    derived from this software without prior written permission. For
   *    written permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    "Apache Geronimo", nor may "Apache" appear in their name, without
   *    prior written permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   * ====================================================================
   */
  package org.apache.geronimo.ejb;
  
  /**
   * 
   * 
   *
   * @version $Revision: 1.1 $ $Date: 2003/08/10 20:51:54 $
   */
  public interface EJBProxyFactory {
      void create() throws Exception;
      void start() throws Exception;
      void stop();
      void destroy();
      Object getEJBObject();
      Object getEJBObject(Object primaryKey);
      Object getEJBHome();
  }
  
  
  
  1.1                  incubator-geronimo/modules/core/src/java/org/apache/geronimo/ejb/EJBProxyFactoryManager.java
  
  Index: EJBProxyFactoryManager.java
  ===================================================================
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2003 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Apache" and "Apache Software Foundation" and
   *    "Apache Geronimo" must not be used to endorse or promote products
   *    derived from this software without prior written permission. For
   *    written permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    "Apache Geronimo", nor may "Apache" appear in their name, without
   *    prior written permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   * ====================================================================
   */
  package org.apache.geronimo.ejb;
  
  import java.util.Map;
  import java.util.HashMap;
  import java.util.Iterator;
  import javax.ejb.EJBException;
  
  import org.apache.geronimo.common.AbstractComponent;
  import org.apache.geronimo.ejb.container.EJBPlugins;
  
  /**
   *
   *
   *
   * @version $Revision: 1.1 $ $Date: 2003/08/10 20:51:54 $
   */
  public class EJBProxyFactoryManager extends AbstractComponent {
      private Map proxies = new HashMap();
      private ThreadLocal threadEJBProxyFactory = new ThreadLocal();
  
      public void create() throws Exception {
          log.debug("Creating EJBProxyFactoryManager: ejbName=" + EJBPlugins.getEJBMetadata(getContainer()).getName());
          super.create();
          for (Iterator iterator = proxies.keySet().iterator(); iterator.hasNext();) {
              String proxyName = (String) iterator.next();
              EJBProxyFactory ejbProxyFactory = getEJBProxyFactory(proxyName);
              // @todo uncomment this when the ejb proxy factories are rewriten to be full components
              //ejbProxyFactory.setContainer(getContainer());
              log.debug("Creating EJBProxyFactory: proxyName=" + proxyName + " ejbName=" + EJBPlugins.getEJBMetadata(getContainer()).getName());
              ejbProxyFactory.create();
          }
      }
  
      public void start() throws Exception {
          log.debug("Starting EJBProxyFactoryManager: ejbName=" + EJBPlugins.getEJBMetadata(getContainer()).getName());
          super.start();
          for (Iterator iterator = proxies.keySet().iterator(); iterator.hasNext();) {
              String proxyName = (String) iterator.next();
              EJBProxyFactory ejbProxyFactory = getEJBProxyFactory(proxyName);
              log.debug("Starting EJBProxyFactory: proxyName=" + proxyName + " ejbName=" + EJBPlugins.getEJBMetadata(getContainer()).getName());
              ejbProxyFactory.start();
          }
      }
  
      public void stop() {
          log.debug("Stopping EJBProxyFactoryManager: ejbName=" + EJBPlugins.getEJBMetadata(getContainer()).getName());
          super.stop();
          for (Iterator iterator = proxies.keySet().iterator(); iterator.hasNext();) {
              String proxyName = (String) iterator.next();
              EJBProxyFactory ejbProxyFactory = getEJBProxyFactory(proxyName);
              log.debug("Stopping EJBProxyFactory: proxyName=" + proxyName + " ejbName=" + EJBPlugins.getEJBMetadata(getContainer()).getName());
              ejbProxyFactory.stop();
          }
      }
  
      public void destroy() {
          log.debug("Destroying EJBProxyFactoryManager: ejbName=" + EJBPlugins.getEJBMetadata(getContainer()).getName());
          super.destroy();
          for (Iterator iterator = proxies.keySet().iterator(); iterator.hasNext();) {
              String proxyName = (String) iterator.next();
              EJBProxyFactory ejbProxyFactory = getEJBProxyFactory(proxyName);
              log.debug("Destroying EJBProxyFactory: proxyName=" + proxyName + " ejbName=" + EJBPlugins.getEJBMetadata(getContainer()).getName());
              ejbProxyFactory.destroy();
              // @todo uncomment this when the ejb proxy factories are rewriten to be full components
              //ejbProxyFactory.setContainer(null);
          }
          proxies.clear();
      }
  
      public void addEJBProxyFactory(String name, EJBProxyFactory ejbProxyFactory) {
          proxies.put(name, ejbProxyFactory);
      }
  
      public EJBProxyFactory getEJBProxyFactory(String name) {
          return (EJBProxyFactory) proxies.get(name);
      }
  
      public void setThreadEJBProxyFactory(String name) {
          if (name == null) {
              // todo this seems wrong
              name = "local";
          }
          EJBProxyFactory ejbProxyFactory = getEJBProxyFactory(name);
          if (ejbProxyFactory == null) {
              throw new EJBException("Unknown proxy factory: name=" + name);
          }
          threadEJBProxyFactory.set(ejbProxyFactory);
      }
  
      public EJBProxyFactory getThreadEJBProxyFactory() {
          return (EJBProxyFactory) threadEJBProxyFactory.get();
      }
  }
  
  
  
  1.1                  incubator-geronimo/modules/core/src/java/org/apache/geronimo/ejb/EnterpriseContext.java
  
  Index: EnterpriseContext.java
  ===================================================================
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2003 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Apache" and "Apache Software Foundation" and
   *    "Apache Geronimo" must not be used to endorse or promote products
   *    derived from this software without prior written permission. For
   *    written permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    "Apache Geronimo", nor may "Apache" appear in their name, without
   *    prior written permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   * ====================================================================
   */
  package org.apache.geronimo.ejb;
  
  import javax.ejb.EnterpriseBean;
  
  import org.apache.geronimo.common.Container;
  
  /**
   *
   *
   *
   * @version $Revision: 1.1 $ $Date: 2003/08/10 20:51:54 $
   */
  public interface EnterpriseContext {
      void clear();
  
      void discard();
  
      Object getId();
  
      void setId(Object id);
  
      Container getContainer();
  
      EnterpriseBean getInstance();
  
      void setInstance(EnterpriseBean instance);
  
      boolean isValid();
  
      void setValid(boolean valid);
  }
  
  
  
  1.1                  incubator-geronimo/modules/core/src/java/org/apache/geronimo/ejb/Entrancy.java
  
  Index: Entrancy.java
  ===================================================================
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2003 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Apache" and "Apache Software Foundation" and
   *    "Apache Geronimo" must not be used to endorse or promote products
   *    derived from this software without prior written permission. For
   *    written permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    "Apache Geronimo", nor may "Apache" appear in their name, without
   *    prior written permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   * ====================================================================
   */
  package org.apache.geronimo.ejb;
  
  import java.io.ObjectStreamException;
  import java.io.Serializable;
  import java.util.HashSet;
  import java.util.Set;
  import javax.ejb.EJBLocalObject;
  import javax.ejb.EJBObject;
  
  import org.apache.geronimo.ejb.EJBInvocationUtil;
  import org.apache.geronimo.common.Invocation;
  import org.apache.geronimo.common.InvocationType;
  
  /**
   *
   *
   *
   * @version $Revision: 1.1 $ $Date: 2003/08/10 20:51:54 $
   */
  public final class Entrancy implements Serializable {
      private static final String ENTRANCY_KEY = "ENTRANCY_KEY";
  
      public static final Entrancy ENTRANT = new Entrancy("ENTRANT", true);
      public static final Entrancy NON_ENTRANT = new Entrancy("NON_ENTRANT", false);
  
      private static final Set nonEntrantMethods = new HashSet();
  
      static {
          try {
              Class[] noArg = new Class[0];
              nonEntrantMethods.add(EJBObject.class.getMethod("getEJBHome", noArg));
              nonEntrantMethods.add(EJBObject.class.getMethod("getHandle", noArg));
              nonEntrantMethods.add(EJBObject.class.getMethod("getPrimaryKey", noArg));
              nonEntrantMethods.add(EJBObject.class.getMethod("isIdentical", new Class[]{EJBObject.class}));
              nonEntrantMethods.add(EJBObject.class.getMethod("remove", noArg));
  
              nonEntrantMethods.add(EJBLocalObject.class.getMethod("getEJBLocalHome", noArg));
              nonEntrantMethods.add(EJBLocalObject.class.getMethod("getPrimaryKey", noArg));
              nonEntrantMethods.add(EJBLocalObject.class.getMethod("isIdentical", new Class[]{EJBLocalObject.class}));
              nonEntrantMethods.add(EJBLocalObject.class.getMethod("remove", noArg));
          } catch (Exception e) {
              throw new ExceptionInInitializerError(e);
          }
      }
  
      public static boolean isNonEntrant(Invocation invocation) {
          // Home invocations are not entrant
          if (InvocationType.getType(invocation).isHomeInvocation()) {
              return true;
          }
          // The methods above are not entrant
          if (nonEntrantMethods.contains(EJBInvocationUtil.getMethod(invocation))) {
              return true;
          }
          // If the invocation contains an entrancy value and it is non-entrant then we are non-entrant
          return getEntrancy(invocation) == NON_ENTRANT;
      }
  
      public static Entrancy getEntrancy(Invocation invocation) {
          return (Entrancy) invocation.getTransient(ENTRANCY_KEY);
      }
  
      public static void putEntrancy(Invocation invocation, Entrancy type) {
          invocation.putTransient(ENTRANCY_KEY, type);
      }
  
      private final transient String name;
      private final transient boolean entrant;
  
      private Entrancy(String name, boolean entrant) {
          this.name = name;
          this.entrant = entrant;
      }
  
      public String toString() {
          return name;
      }
  
      Object readResolve() throws ObjectStreamException {
          if (entrant) {
              return ENTRANT;
          } else {
              return NON_ENTRANT;
          }
      }
  }
  
  
  
  1.1                  incubator-geronimo/modules/core/src/java/org/apache/geronimo/ejb/GeronimoSessionContext.java
  
  Index: GeronimoSessionContext.java
  ===================================================================
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2003 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Apache" and "Apache Software Foundation" and
   *    "Apache Geronimo" must not be used to endorse or promote products
   *    derived from this software without prior written permission. For
   *    written permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    "Apache Geronimo", nor may "Apache" appear in their name, without
   *    prior written permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   * ====================================================================
   */
  package org.apache.geronimo.ejb;
  
  import java.security.Identity;
  import java.security.Principal;
  import java.util.Properties;
  import javax.ejb.EJBException;
  import javax.ejb.EJBHome;
  import javax.ejb.EJBLocalHome;
  import javax.ejb.EJBLocalObject;
  import javax.ejb.EJBObject;
  import javax.ejb.SessionContext;
  import javax.ejb.TimerService;
  import javax.transaction.Status;
  import javax.transaction.SystemException;
  import javax.transaction.TransactionManager;
  import javax.transaction.UserTransaction;
  import javax.xml.rpc.handler.MessageContext;
  
  import org.apache.geronimo.common.Container;
  import org.apache.geronimo.ejb.container.EJBPlugins;
  import org.apache.geronimo.ejb.context.GeronimoUserTransaction;
  import org.apache.geronimo.ejb.metadata.EJBMetadata;
  
  /**
   *
   *
   *
   * @version $Revision: 1.1 $ $Date: 2003/08/10 20:51:54 $
   */
  public class GeronimoSessionContext implements SessionContext {
      private final Container container;
      private final UserTransaction userTransaction;
      private final TransactionManager transactionManager;
  //    private String state;
  
      public GeronimoSessionContext(Container container) {
          this.container = container;
          EJBMetadata ejbMetadata = EJBPlugins.getEJBMetadata(container);
          transactionManager = EJBPlugins.getTransactionManager(container);
          if (ejbMetadata.getTransactionDemarcation().isBean()) {
              this.userTransaction = new GeronimoUserTransaction(transactionManager);
          } else {
              this.userTransaction = null;
          }
      }
  
      public EJBHome getEJBHome() throws IllegalStateException {
          EJBMetadata ejbMetadata = EJBPlugins.getEJBMetadata(container);
          if (ejbMetadata.getHomeInterface() == null) {
              throw new IllegalStateException("getEJBHome is not allowed for a bean without a (remote) home interface");
          }
          return (EJBHome) EJBPlugins.getEJBProxyFactoryManager(container).getThreadEJBProxyFactory().getEJBHome();
      }
  
      public EJBLocalHome getEJBLocalHome() throws IllegalStateException {
          EJBMetadata ejbMetadata = EJBPlugins.getEJBMetadata(container);
          if (ejbMetadata.getLocalHomeInterface() == null) {
              throw new IllegalStateException("getEJBLocalHome is not allowed for a bean without a local home interface");
          }
          return (EJBLocalHome) EJBPlugins.getEJBProxyFactoryManager(container).getEJBProxyFactory("local").getEJBHome();
      }
  
      public EJBObject getEJBObject() throws IllegalStateException {
          EJBMetadata ejbMetadata = EJBPlugins.getEJBMetadata(container);
          if (ejbMetadata.getRemoteInterface() == null) {
              throw new IllegalStateException("getEJBObject is not allowed for a bean without a remote interface");
          }
  //        if (state.equals("not-exits")) {
  //            throw new IllegalStateException("getEJBObject is not allowed until the bean has identity");
  //        }
          return (EJBObject) EJBPlugins.getEJBProxyFactoryManager(container).getThreadEJBProxyFactory().getEJBObject();
      }
  
      public EJBLocalObject getEJBLocalObject() throws IllegalStateException {
          EJBMetadata ejbMetadata = EJBPlugins.getEJBMetadata(container);
          if (ejbMetadata.getLocalHomeInterface() == null) {
              throw new IllegalStateException("getEJBLocalObject is not allowed for a bean without a local interface");
          }
  //        if (state.equals("not-exits")) {
  //            throw new IllegalStateException("getEJBLocalObject is not allowed until the bean has identity");
  //        }
          return (EJBLocalObject) EJBPlugins.getEJBProxyFactoryManager(container).getEJBProxyFactory("local").getEJBObject();
      }
  
      public Principal getCallerPrincipal() {
          return null;
      }
  
      public boolean isCallerInRole(String roleName) {
          return false;
      }
  
      public UserTransaction getUserTransaction() throws IllegalStateException {
          if (userTransaction == null) {
              throw new IllegalStateException("getUserTransaction is not allowed for bean with container-managed transaction demarcation.");
          }
          return userTransaction;
      }
  
      public boolean getRollbackOnly() throws IllegalStateException {
          if (userTransaction != null) {
              throw new IllegalStateException("getRollbackOnly is not allowed for beans with bean-managed transaction demarcation.");
          }
  //        if (!state.equals("method-ready")) {
  //            throw new IllegalStateException("getRollbackOnly is only allowed in the method ready state");
  //        }
          try {
              int status = transactionManager.getStatus();
              if (status == Status.STATUS_NO_TRANSACTION) {
                  throw new IllegalStateException("getRollbackOnly is only allowed during a transaction");
              }
              return status == Status.STATUS_MARKED_ROLLBACK;
          } catch (SystemException e) {
              throw new EJBException("Could not get transaction status", e);
          }
      }
  
      public void setRollbackOnly() throws IllegalStateException {
          if (userTransaction != null) {
              throw new IllegalStateException("getRollbackOnly is not allowed for beans with bean-managed transaction demarcation.");
          }
  //        if (!state.equals("method-ready")) {
  //            throw new IllegalStateException("getRollbackOnly is only allowed in the method ready state");
  //        }
  
          try {
              if (transactionManager.getStatus() == Status.STATUS_NO_TRANSACTION) {
                  throw new IllegalStateException("getRollbackOnly is only allowed during a transaction");
              }
              transactionManager.setRollbackOnly();
          } catch (SystemException e) {
              throw new EJBException("Could not get transaction status", e);
          }
      }
  
      /**
       * @deprecated Use JNDI instead
       * @throws EJBException always
       */
      public Properties getEnvironment() {
          throw new EJBException("getEnvironment is no longer supported; use JNDI instead");
      }
  
      /**
       * @deprecated Use getCallerPrincipal()
       * @throws EJBException always
       */
      public Identity getCallerIdentity() {
          throw new EJBException("getCallerIdentity is no longer supported; use getCallerPrincipal instead");
      }
  
      /**
       * @deprecated Use isCallerInRole(String roleName)
       * @throws EJBException always
       */
      public boolean isCallerInRole(Identity role) {
          throw new EJBException("isCallerInRole(Identity role) is no longer supported; use isCallerInRole(String roleName) instead");
      }
  
      public TimerService getTimerService() throws IllegalStateException {
          throw new UnsupportedOperationException("Not implemented yet");
      }
  
      public MessageContext getMessageContext() throws IllegalStateException {
          throw new UnsupportedOperationException("Not implemented yet");
      }
  }
  
  
  
  1.1                  incubator-geronimo/modules/core/src/java/org/apache/geronimo/ejb/SimpleEnterpriseContext.java
  
  Index: SimpleEnterpriseContext.java
  ===================================================================
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2003 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Apache" and "Apache Software Foundation" and
   *    "Apache Geronimo" must not be used to endorse or promote products
   *    derived from this software without prior written permission. For
   *    written permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    "Apache Geronimo", nor may "Apache" appear in their name, without
   *    prior written permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   * ====================================================================
   */
  package org.apache.geronimo.ejb;
  
  import javax.ejb.EnterpriseBean;
  
  import org.apache.geronimo.common.Container;
  import org.apache.geronimo.ejb.EnterpriseContext;
  
  /**
   *
   *
   *
   * @version $Revision: 1.1 $ $Date: 2003/08/10 20:51:54 $
   */
  public final class SimpleEnterpriseContext implements EnterpriseContext {
      private Container container;
      private Object id;
      private EnterpriseBean instance;
      private boolean valid = false;
  
      public void clear() {
          id = null;
          valid = false;
      }
  
      public void discard() {
          instance = null;
      }
  
      public Container getContainer() {
          return container;
      }
  
      public void setContainer(Container container) {
          this.container = container;
      }
  
      public Object getId() {
          return id;
      }
  
      public void setId(Object id) {
          this.id = id;
      }
  
      public EnterpriseBean getInstance() {
          return instance;
      }
  
      public void setInstance(EnterpriseBean instance) {
          this.instance = instance;
      }
  
      public boolean isValid() {
          return valid;
      }
  
      public void setValid(boolean valid) {
          this.valid = valid;
      }
  }
  
  
  
  1.1                  incubator-geronimo/modules/core/src/java/org/apache/geronimo/ejb/StatelessLifeCycleInterceptor.java
  
  Index: StatelessLifeCycleInterceptor.java
  ===================================================================
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2003 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Apache" and "Apache Software Foundation" and
   *    "Apache Geronimo" must not be used to endorse or promote products
   *    derived from this software without prior written permission. For
   *    written permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    "Apache Geronimo", nor may "Apache" appear in their name, without
   *    prior written permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   * ====================================================================
   */
  package org.apache.geronimo.ejb;
  
  import java.lang.reflect.Method;
  
  import javax.ejb.EJBObject;
  import javax.ejb.EJBLocalObject;
  
  import org.apache.geronimo.common.AbstractInterceptor;
  import org.apache.geronimo.common.Invocation;
  import org.apache.geronimo.common.InvocationResult;
  import org.apache.geronimo.common.SimpleInvocationResult;
  import org.apache.geronimo.ejb.container.EJBPlugins;
  import org.apache.geronimo.ejb.metadata.EJBMetadata;
  
  /**
   *
   *
   *
   * @version $Revision: 1.1 $ $Date: 2003/08/10 20:51:54 $
   */
  public class StatelessLifeCycleInterceptor extends AbstractInterceptor {
      private static final Method removeRemote;
      private static final Method removeLocal;
  
      static {
          try {
              removeRemote = EJBObject.class.getMethod("remove", null);
              removeLocal = EJBLocalObject.class.getMethod("remove", null);
          } catch(Exception e) {
              throw new ExceptionInInitializerError(e);
          }
      }
  
      private Method createRemote;
      private Method createLocal;
  
      public void start() throws Exception {
          super.start();
          EJBMetadata ejbMetadata = EJBPlugins.getEJBMetadata(getContainer());
          Class homeInterface = ejbMetadata.getHomeInterface();
          if(homeInterface != null) {
              createRemote = homeInterface.getMethod("create", null);
          }
  
          Class localHomeInterface = ejbMetadata.getLocalHomeInterface();
          if(localHomeInterface != null) {
              createLocal = localHomeInterface.getMethod("create", null);
          }
      }
  
      public void stop() {
          createRemote = null;
          createLocal = null;
          super.stop();
      }
  
      public InvocationResult invoke(Invocation invocation) throws Exception {
          Method method = EJBInvocationUtil.getMethod(invocation);
          if(method == null) {
              return getNext().invoke(invocation);
          }
  
          if (method.equals(removeRemote) || method.equals(removeLocal)) {
              // remove for a stateless bean does nothing
              return new SimpleInvocationResult();
          } else if (method.equals(createRemote)) {
              EJBProxyFactoryManager ejbProxyFactoryManager = EJBPlugins.getEJBProxyFactoryManager(getContainer());
              EJBProxyFactory ejbProxyFactory = ejbProxyFactoryManager.getThreadEJBProxyFactory();
              if (ejbProxyFactory == null) {
                  throw new IllegalStateException("No remote proxy factory set");
              }
              return new SimpleInvocationResult(ejbProxyFactory.getEJBObject());
          } else if (method.equals(createLocal)) {
              EJBProxyFactoryManager ejbProxyFactoryManager = EJBPlugins.getEJBProxyFactoryManager(getContainer());
              EJBProxyFactory ejbProxyFactory = ejbProxyFactoryManager.getEJBProxyFactory("local");
              if (ejbProxyFactory == null) {
                  throw new IllegalStateException("No local proxy factoy set");
              }
              return new SimpleInvocationResult(ejbProxyFactory.getEJBObject());
          } else {
              return getNext().invoke(invocation);
          }
      }
  }
  
  
  
  1.1                  incubator-geronimo/modules/core/src/java/org/apache/geronimo/ejb/SynchronizationRegistry.java
  
  Index: SynchronizationRegistry.java
  ===================================================================
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2003 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Apache" and "Apache Software Foundation" and
   *    "Apache Geronimo" must not be used to endorse or promote products
   *    derived from this software without prior written permission. For
   *    written permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    "Apache Geronimo", nor may "Apache" appear in their name, without
   *    prior written permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   * ====================================================================
   */
  package org.apache.geronimo.ejb;
  
  import java.util.HashMap;
  import java.util.Iterator;
  import java.util.LinkedList;
  import java.util.Map;
  import javax.ejb.EJBException;
  import javax.naming.InitialContext;
  import javax.transaction.Status;
  import javax.transaction.Synchronization;
  import javax.transaction.SystemException;
  import javax.transaction.TransactionManager;
  
  import org.apache.commons.logging.Log;
  import org.apache.commons.logging.LogFactory;
  
  import org.apache.geronimo.common.Container;
  import org.apache.geronimo.ejb.container.EJBPlugins;
  import org.apache.geronimo.ejb.context.ExecutionContext;
  import org.apache.geronimo.ejb.context.TxExecutionContext;
  import org.apache.geronimo.ejb.metadata.CommitOption;
  import org.apache.geronimo.ejb.metadata.EJBMetadata;
  
  /**
   *
   * @version $Revision: 1.1 $ $Date: 2003/08/10 20:51:54 $
   */
  public class SynchronizationRegistry {
      private static final String EJB_REGISTRY_KEY = "EJB_REGISTRY_KEY";
  
      private TransactionManager transactionManager;
  
      /**
       * Holds the entities registry for each thread.
       * This registry holds information for all entities in the
       * current thread, but not associated with a transaction.
       */
      private ThreadLocal registryThreadLocal;
  
      private final Log log = LogFactory.getLog(getClass());
  
      /**
       * @jmx:managed-operation
       */
      public void create() {
      }
  
      /**
       * @jmx:managed-operation
       */
      public void start() throws Exception {
          // Get the transaction manager
          InitialContext context = new InitialContext();
          transactionManager = (TransactionManager) context.lookup("java:/TransactionManager");
  
          // Create the thread local to hold the entity registry
          registryThreadLocal = new ThreadLocal() {
              protected Object initialValue() {
                  return new Registry();
              }
          };
      }
  
      /**
       * @jmx:managed-operation
       */
      public void stop() {
          transactionManager = null;
      }
  
      /**
       * @jmx:managed-operation
       */
      public void destroy() {
      }
  
      public void beginInvocation(EnterpriseContext ctx) throws Exception {
          Registry registry = getRegistry();
          Container container = ctx.getContainer();
  
          // load if not valid
          if (!ctx.isValid()) {
              // Not valid... tell the persistence manager to load the state
              // Note: make sure to not chnage anything befoe calling load
              // you can get an exception from load
              EJBPlugins.getPersistenceManager(container).load(ctx);
  
              // Now the state is valid
              ctx.setValid(true);
          }
  
          // before we add the new context to the invocation stack we need to
          // mark the current head of the stack as dirty because it could have
          // been modified
          LinkedList invocationStack = registry.getInvocationStack();
          if (!invocationStack.isEmpty()) {
              EnterpriseContext head = (EnterpriseContext) invocationStack.getFirst();
              ContextKey headKey = new ContextKey(head.getContainer(), head.getId());
              registry.getDirtyMap().put(headKey, head);
          }
  
          // Add the context to the stack of contexts being currently invoked
          invocationStack.addFirst(ctx);
  
          // if this is a previously unseen context log it
          ContextKey key = new ContextKey(container, ctx.getId());
          if (registry.getAssociatedMap().put(key, ctx) == null) {
              if (log.isTraceEnabled()) {
                  log.trace("Associated new entity: " +
                          "ejb=" + EJBPlugins.getEJBMetadata(container).getName() +
                          ", id=" + key.getId());
              }
          }
      }
  
      public void endInvocation(boolean threwException, Object id, EnterpriseContext ctx) throws Exception {
          ContextKey key = new ContextKey(ctx.getContainer(), id);
          Registry registry = getRegistry();
  
          // If the head context on the invocation stack is not the requested ctx
          // we have a serious problem.
          LinkedList invocationStack = registry.getInvocationStack();
          if (invocationStack.isEmpty()) {
              throw new IllegalStateException("The invocation stack in inconsistent.  " +
                      "Expected context=" + ctx + ", but stack was empty");
          }
  
          EnterpriseContext head = (EnterpriseContext) invocationStack.removeFirst();
          if (ctx != head) {
              throw new IllegalStateException("The invocation stack in inconsistent.  " +
                      "Expected context=" + ctx + ", but got context=" + head);
          }
  
          ExecutionContext executionContext = ExecutionContext.getContext();
          if (executionContext instanceof TxExecutionContext == false) {
              // only store the entity if an exception was not thrown
              if (!executionContext.isReadOnly() && !threwException) {
                  synchronizeEntity(registry, ctx);
              }
  
              // always disassociate the entity
              disassociateEntity(threwException, id, ctx);
              registry.getAssociatedMap().remove(key);
  
              // just to be safe clear the regisry if the invocation is done
              if (registry.getInvocationStack().isEmpty()) {
                  registry.clear();
              }
          } else {
              // If this is a read/write invocation, assume the context is dirty,
              // when an entity in a tx leave an invocation
              if (!executionContext.isReadOnly()) {
                  registry.getDirtyMap().put(key, ctx);
              }
          }
      }
  
      /**
       * Gets the EnterpriseContext for the current transaction in the
       * specified container with the specified key.
       */
      public EnterpriseContext getContext(Container container, Object id) {
          Registry registry = getRegistry();
          ContextKey key = new ContextKey(container, id);
          return (EnterpriseContext) registry.getAssociatedMap().get(key);
      }
  
      public void synchronizeEntities() {
          // First we synchronize the head context in the invocation.  We
          // always synchronize the current context, because there is
          // no way to detect if current context has been modified or not.
          // After that, we synchronize anything in the dirty map.  We
          // loop over that map because an ejbStore call back can modifiy
          // another bean.
          Registry registry = getRegistry();
  
          LinkedList invocationStack = registry.getInvocationStack();
          if (!invocationStack.isEmpty()) {
              EnterpriseContext ctx = (EnterpriseContext) invocationStack.getFirst();
              try {
                  synchronizeEntity(registry, ctx);
              } catch (RuntimeException e) {
                  throw e;
              } catch (Exception e) {
                  throw new EJBException("Unable to store entity: " +
                          "ejb=" + EJBPlugins.getEJBMetadata(ctx.getContainer()).getName() +
                          ", id=" + ctx.getId(), e);
              }
          }
  
          // @todo add a limit on the number of loops (say 10)
          while (!registry.getDirtyMap().isEmpty()) {
              // get an iterator over the current dirty map
              Iterator entities = registry.getDirtyMap().values().iterator();
  
              // reset the dirty map, because when we synchronize an entity
              // it may modify another entity and we need to know the additional
              // entities to synchronize in the next iteration of the outer loop
              registry.setDirtyMap(new HashMap());
  
              // synchronize the dirty entities
              while (entities.hasNext()) {
                  EnterpriseContext ctx = (EnterpriseContext) entities.next();
                  try {
                      synchronizeEntity(registry, ctx);
                  } catch (RuntimeException e) {
                      throw e;
                  } catch (Exception e) {
                      throw new EJBException("Unable to store entity: " +
                              "ejb=" + EJBPlugins.getEJBMetadata(ctx.getContainer()).getName() +
                              ", id=" + ctx.getId(), e);
                  }
              }
          }
      }
  
      private void synchronizeEntity(Registry registry, EnterpriseContext ctx) throws Exception {
          Container container = ctx.getContainer();
          EJBMetadata ejbMetadata = EJBPlugins.getEJBMetadata(container);
  
          // any one can mark the tx rollback at any time so check
          // before continuing to the store
          try {
              // store only happens when the transaction will be committed
              if (transactionManager.getStatus() != Status.STATUS_ACTIVE) {
                  return;
              }
          } catch (SystemException e) {
              throw new EJBException("Unable to get transaction status", e);
          }
  
          // only synchronize if we are not already synchronizing
          // the context or the id is not null.  We keep track of what
          // we are already synchronizing to catch the case where an ejbStore
          // call back calls a finder which would result in a store infinite loop.
          // A null id means that the entity has already been removed.
          if (ctx == registry.getInStoreContext() || ctx.getId() == null) {
              return;
          }
  
          if (log.isTraceEnabled()) {
              log.trace("Synchronizing entity: " +
                      "ejb=" + ejbMetadata.getName() +
                      ", id=" + ctx.getId());
          }
  
          ClassLoader oldCl = Thread.currentThread().getContextClassLoader();
          Thread.currentThread().setContextClassLoader(ejbMetadata.getClassLoader());
          try {
              registry.setInStoreContext(ctx);
              boolean rollback = true;
              try {
                  EJBPlugins.getPersistenceManager(container).store(ctx);
                  rollback = true;
              } finally {
                  if (rollback) {
                      try {
                          transactionManager.setRollbackOnly();
                      } catch (Throwable e) {
                          log.error("Could not mark transaction for rollback", e);
                      }
                  }
              }
          } finally {
              registry.setInStoreContext(null);
              Thread.currentThread().setContextClassLoader(oldCl);
          }
      }
  
      /**
       * Disassociate entity with transaction.
       */
      private void disassociateEntity(boolean rollback, Object id, EnterpriseContext ctx) {
          // Get the container associated with this context
          Container container = ctx.getContainer();
          EJBMetadata ejbMetadata = EJBPlugins.getEJBMetadata(container);
  
          ClassLoader oldClassLoader = Thread.currentThread().getContextClassLoader();
          Thread.currentThread().setContextClassLoader(ejbMetadata.getClassLoader());
          try {
              // If rolled back, invalidate instance
              CommitOption commitOption = ejbMetadata.getCommitOption();
              if (rollback) {
                  EJBPlugins.getInstanceCache(container).remove(id);
              } else if (commitOption == CommitOption.A || commitOption == CommitOption.D) {
                  ctx.setValid(true);
              } else if (commitOption == CommitOption.B) {
                  ctx.setValid(false);
              } else {
                  EJBPlugins.getInstanceCache(container).remove(id);
                  ctx.discard();
                  try {
                      EJBPlugins.getPersistenceManager(container).passivate(ctx);
                  } catch (RuntimeException e) {
                      throw e;
                  } catch (Exception e) {
                      throw new EJBException("Could not passivate commit-option C entity bean", e);
                  }
              }
          } finally {
              Thread.currentThread().setContextClassLoader(oldClassLoader);
          }
      }
  
      private Registry getRegistry() {
          ExecutionContext context = ExecutionContext.getContext();
          if (context instanceof TxExecutionContext == false) {
              return (Registry) registryThreadLocal.get();
          }
  
          // get the map of container to containerMap
          Registry registry = (Registry) context.get(EJB_REGISTRY_KEY);
          if (registry == null) {
              registry = new Registry();
              context.put(EJB_REGISTRY_KEY, registry);
              context.register(new EJBSynchronization());
          }
          return registry;
      }
  
      private final class Registry {
          private Map dirtyMap = new HashMap();
          private LinkedList invocationStack = new LinkedList();
          private Map associatedMap = new HashMap();
          private EnterpriseContext inStoreContext;
  
          public void clear() {
              dirtyMap = new HashMap();
              invocationStack = new LinkedList();
              associatedMap = new HashMap();
          }
  
          public Map getDirtyMap() {
              return dirtyMap;
          }
  
          public void setDirtyMap(final Map dirtyMap) {
              this.dirtyMap = dirtyMap;
          }
  
          public LinkedList getInvocationStack() {
              return invocationStack;
          }
  
          public void setInvocationStack(final LinkedList invocationStack) {
              this.invocationStack = invocationStack;
          }
  
          public Map getAssociatedMap() {
              return associatedMap;
          }
  
          public void setAssociatedMap(final Map associatedMap) {
              this.associatedMap = associatedMap;
          }
  
          public EnterpriseContext getInStoreContext() {
              return inStoreContext;
          }
  
          public void setInStoreContext(EnterpriseContext inStoreContext) {
              this.inStoreContext = inStoreContext;
          }
      }
  
      private final class ContextKey {
          private final Container container;
          private final Object id;
  
          public ContextKey(final Container container, final Object id) {
              if (container == null) {
                  throw new IllegalArgumentException("Container is null");
              }
              if (id == null) {
                  throw new IllegalArgumentException("Id is null");
              }
              this.container = container;
              this.id = id;
          }
  
          public Container getContainer() {
              return container;
          }
  
          public Object getId() {
              return id;
          }
  
          public boolean equals(Object object) {
              if (!(object instanceof ContextKey)) {
                  return false;
              }
  
              ContextKey key = (ContextKey) object;
              return container.equals(key.getContainer()) && id.equals(key.getId());
          }
  
          public int hashCode() {
              int result = 17;
              result = 37 * result + container.hashCode();
              result = 37 * result + id.hashCode();
              return result;
          }
      }
  
      private final class EJBSynchronization implements Synchronization {
          public void beforeCompletion() {
              if (log.isTraceEnabled()) {
                  log.trace("beforeCompletion called");
              }
  
              // let the runtime exceptions fall out, so the committer can determine
              // the root cause of a rollback
              synchronizeEntities();
          }
  
          public void afterCompletion(int status) {
              Registry registry = getRegistry();
              Map entityMap = registry.getAssociatedMap();
              registry.clear();
              for (Iterator iter = entityMap.entrySet().iterator(); iter.hasNext();) {
                  Map.Entry entry = (Map.Entry) iter.next();
                  disassociateEntity(
                          status == Status.STATUS_ROLLEDBACK,
                          ((ContextKey) entry.getKey()).getId(),
                          (EnterpriseContext) entry.getValue());
              }
          }
      }
  }
  
  
  
  
  1.1                  incubator-geronimo/modules/core/src/java/org/apache/geronimo/ejb/cache/EnterpriseContextInstanceCache.java
  
  Index: EnterpriseContextInstanceCache.java
  ===================================================================
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2003 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Apache" and "Apache Software Foundation" and
   *    "Apache Geronimo" must not be used to endorse or promote products
   *    derived from this software without prior written permission. For
   *    written permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    "Apache Geronimo", nor may "Apache" appear in their name, without
   *    prior written permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   * ====================================================================
   */
  package org.apache.geronimo.ejb.cache;
  
  import java.rmi.NoSuchObjectException;
  
  import org.apache.commons.logging.Log;
  import org.apache.commons.logging.LogFactory;
  
  import org.apache.geronimo.ejb.EnterpriseContext;
  import org.apache.geronimo.common.AbstractComponent;
  import org.apache.geronimo.common.Container;
  import org.apache.geronimo.ejb.container.EJBPlugins;
  import org.apache.geronimo.cache.InstanceCache;
  import org.apache.geronimo.cache.LRUInstanceCache;
  import org.apache.geronimo.cache.LRURunner;
  
  /**
   *
   * @version $Revision: 1.1 $ $Date: 2003/08/10 20:51:54 $
   */
  public final class EnterpriseContextInstanceCache extends AbstractComponent implements InstanceCache {
      private LRUInstanceCache cache;
      private int highSize = 10;
      private int lowSize = 5;
      private Passivator passivator = new Passivator();
      private Log log = LogFactory.getLog(getClass());
  
      public void start() throws Exception {
          super.start();
          cache = new LRUInstanceCache();
          passivator = new Passivator();
          passivator.start();
      }
  
      public void stop() {
          passivator.stopRunning();
          passivator = null;
  
          // clean up cache
          cache = null;
  
          super.stop();
      }
  
      public Object get(Object id) throws Exception {
          EnterpriseContext ctx = null;
          synchronized (cache) {
              ctx = (EnterpriseContext) cache.get(id);
              if (ctx == null) {
                  //addBeanToTx();
  
                  // verify that there is enough room in the cache
                  passivator.checkSize();
  
                  // create a new context
                  Container container = getContainer();
                  try {
                      ctx = (EnterpriseContext) EJBPlugins.getInstanceFactory(container).createInstance();
                  } catch (Exception e) {
                      throw new NoSuchObjectException("An error occured while getting a new context");
                  }
  
                  // set the id of the new context
                  ctx.setId(id);
  
                  EJBPlugins.getPersistenceManager(container).activate(ctx);
                  cache.putActive(id, ctx);
              }
          }
          return ctx;
      }
  
      public Object peek(Object id) {
          synchronized (cache) {
              return cache.peek(id);
          }
      }
  
      public void putActive(Object key, Object value) {
          if (key == null) {
              throw new IllegalArgumentException("Cannot insert an EnterpriseContext with a null id");
          }
          if (!(value instanceof EnterpriseContext)) {
              throw new IllegalArgumentException("Value is not an instance of EnterpriseContext");
          }
          assert(key.equals(((EnterpriseContext) value).getId()));
          synchronized (cache) {
              //addBeanToTx();
  
              // verify that there is enough room in the cache
              passivator.checkSize();
  
              cache.putActive(key, value);
          }
      }
  
      public void putInactive(Object key, Object value) {
          if (key == null) {
              throw new IllegalArgumentException("Cannot insert an EnterpriseContext with a null id");
          }
          if (!(value instanceof EnterpriseContext)) {
              throw new IllegalArgumentException("Value is not an instance of EnterpriseContext");
          }
          assert(key.equals(((EnterpriseContext) value).getId()));
          synchronized (cache) {
              //removeBeanFromTx();
              cache.putInactive(key, value);
          }
      }
  
      public Object remove(Object key) {
          if (key == null) {
              throw new IllegalArgumentException("Cannot remove an EnterpriseContext with a null id");
          }
  
          synchronized (cache) {
              //removeBeanFromTx();
              return cache.remove(key);
          }
      }
  
      public boolean isActive(Object key) {
          synchronized (cache) {
              return cache.isActive(key);
          }
      }
  
      public long getSize() {
          synchronized (cache) {
              return cache.size();
          }
      }
  
      /*
      private TransactionLocal beanCount = new TransactionLocal();
  
      // @todo this is a dirty hack
      private void addBeanToTx() {
          Transaction tx = null;
          try {
              tx = EJBPlugins.getTransactionManager(getContainer()).getTransaction();
          } catch (SystemException ignore) {
          }
          if (tx == null) {
              return;
          }
  
          Integer integerCount = (Integer) beanCount.get();
          int count = 0;
          if (integerCount != null) {
              count = integerCount.intValue();
          }
          count++;
          beanCount.set(new Integer(count));
          if (count > maxBeansInTx) {
              log.info("******* Store Entities In Tx *******");
              EntityContainer.synchronizeEntitiesWithinTransaction(tx);
          }
      }
  
      // @todo this is a dirty hack
      private void removeBeanFromTx() {
          Transaction tx = null;
          try {
              tx = EJBPlugins.getTransactionManager(getContainer()).getTransaction();
          } catch (SystemException ignore) {
          }
          if (tx == null) {
              return;
          }
  
          Integer integerCount = (Integer) beanCount.get();
          int count = 0;
          if (integerCount != null) {
              count = integerCount.intValue();
              if (count > 0) {
                  count--;
              }
          }
          beanCount.set(new Integer(count));
      }
      */
      private final class Passivator extends Thread implements LRURunner {
          private boolean running = true;
  
          public Passivator() {
              setDaemon(true);
          }
  
          public synchronized void stopRunning() {
              running = false;
              notify();
          }
  
          public synchronized void checkSize() {
              if (running && cache.size() > highSize) {
                  notify();
              }
          }
  
          // todo This synchronization is all broken... will eventually deadlock
          public void run() {
              while (true) {
                  synchronized (this) {
                      if (!running) {
                          return;
                      }
                      try {
                          wait();
                      } catch (InterruptedException ignored) {
                          // we have another way to signify exit so we can safely ignore this exception
                      }
                  }
                  if (cache.size() > highSize) {
                      cache.run(this);
                  }
              }
          }
  
          public synchronized boolean shouldContinue() {
              return running && cache.size() > lowSize;
          }
  
          public boolean shouldRemove(Object key, Object value) {
              return true;
          }
  
          public void remove(Object key, Object value) {
              try {
                  EnterpriseContext context = (EnterpriseContext) value;
                  EJBPlugins.getPersistenceManager(getContainer()).passivate(context);
              } catch (Throwable e) {
                  log.error("Could not passivate ejb: id=" + key, e);
              }
          }
      }
  
  }
  
  
  
  1.1                  incubator-geronimo/modules/core/src/java/org/apache/geronimo/ejb/cache/EnterpriseContextInstancePool.java
  
  Index: EnterpriseContextInstancePool.java
  ===================================================================
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2003 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Apache" and "Apache Software Foundation" and
   *    "Apache Geronimo" must not be used to endorse or promote products
   *    derived from this software without prior written permission. For
   *    written permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    "Apache Geronimo", nor may "Apache" appear in their name, without
   *    prior written permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   * ====================================================================
   */
  package org.apache.geronimo.ejb.cache;
  
  
  import java.util.Iterator;
  import java.util.LinkedList;
  import java.util.List;
  
  import org.apache.commons.logging.Log;
  import org.apache.commons.logging.LogFactory;
  
  import org.apache.geronimo.common.AbstractComponent;
  import org.apache.geronimo.ejb.EnterpriseContext;
  import org.apache.geronimo.ejb.container.EJBPlugins;
  import org.apache.geronimo.cache.InstancePool;
  import org.apache.geronimo.cache.SimpleInstancePool;
  
  /**
   *
   *
   * @version $Revision: 1.1 $ $Date: 2003/08/10 20:51:54 $
   */
  public final class EnterpriseContextInstancePool extends AbstractComponent implements  InstancePool {
      private SimpleInstancePool pool;
      private DiscardQueue discardQueue;
      private int maxSize = 100;
      private boolean hardLimit = false;
  
      public void create() throws Exception {
          super.create();
          pool = new SimpleInstancePool(EJBPlugins.getInstanceFactory(getContainer()), maxSize, hardLimit);
          discardQueue = new DiscardQueue();
      }
  
      public void start() throws Exception {
          super.start();
          pool.fill();
      }
  
      public void destroy() {
          List contexts = pool.stopPooling();
          pool = null;
          for (Iterator iter = contexts.iterator(); iter.hasNext();) {
              try {
                  EnterpriseContext ctx = (EnterpriseContext) iter.next();
                  ctx.discard();
              } catch (Throwable e) {
                  log.error("Error while disposing of context", e);
              }
          }
  
          discardQueue.stop();
          discardQueue = null;
  
          super.destroy();
      }
  
      /**
       * Get an instance from the pool.  This method may block indefinately if the pool has a
       * strict limit.
       *
       * @return an instance
       * @throws java.lang.InterruptedException if pool is using hard limits and thread was interrupted
       * while waiting for an instance to become available
       */
      public Object acquire() throws Exception {
          return pool.acquire();
      }
  
      /**
       * Releases the hold on the instance.  This method may or may not reinsert the instance
       * into the pool. This method can not block.
       *
       * @param instance the instance to return to the pool
       * @return true is the instance was reinserted into the pool.
       */
      public boolean release(Object instance) {
          if (!(instance instanceof EnterpriseContext)) {
              throw new IllegalArgumentException("Instance is not an instance of EnterpriseContext");
          }
          EnterpriseContext ctx = (EnterpriseContext) instance;
  
          // first recycle the context (outside the sync block)
          ctx.clear();
  
          if (!pool.release(ctx)) {
              // instance was not reinserted into the pool so we need to discard it
              discardQueue.put(ctx);
              return false;
          }
          return true;
      }
  
      /**
       * Drop an instance permanently from the pool.  The instance will never be used again.
       * This method can not block.
       *
       * @param instance the instance to discard
       */
      public void remove(Object instance) {
          if (!(instance instanceof EnterpriseContext)) {
              throw new IllegalArgumentException("Instance is not an instance of EnterpriseContext");
          }
          pool.remove(instance);
      }
  
      public int getSize() {
          return pool.getSize();
      }
  
      public int getAllocatedSize() {
          return pool.getAllocatedSize();
      }
  
      public int getMaxSize() {
          return pool.getMaxSize();
      }
  
      public void setSize(int maxSize) {
          this.maxSize = maxSize;
      }
  
      public boolean isHardLimit() {
          return pool.isHardLimit();
      }
  
      public void setHardLimit(boolean hardLimit) {
          this.hardLimit = hardLimit;
      }
  
      private static final class DiscardQueue implements Runnable {
          private final Log log = LogFactory.getLog(this.getClass());
          private final LinkedList discardQueue;
          private final Thread discardThread;
          private boolean running = true;
  
          public DiscardQueue() {
              discardQueue = new LinkedList();
              discardThread = new Thread(this, "EnterpriseContextInstancePool.DiscardQueue");
              discardThread.setDaemon(true);
              discardThread.start();
          }
  
          public void stop() {
              synchronized (discardQueue) {
                  running = false;
                  discardQueue.notify();
              }
          }
  
          public void put(EnterpriseContext ctx) {
              synchronized (discardQueue) {
                  discardQueue.addLast(ctx);
                  discardQueue.notify();
              }
          }
  
          public void run() {
              EnterpriseContext context = null;
              while (running) {
                  synchronized (discardQueue) {
                      if (!discardQueue.isEmpty()) {
                          context = (EnterpriseContext) discardQueue.removeFirst();
                      } else {
                          try {
                              discardQueue.wait();
                          } catch (InterruptedException ignored) {
                              // ignore this exception... there is a better way be ended
                          }
                      }
                  }
                  if (context != null) {
                      try {
                          context.discard();
                      } catch (Throwable e) {
                          log.error("Error while disposing of context", e);
                      }
                      context = null;
                  }
              }
          }
      }
  }
  
  
  
  1.1                  incubator-geronimo/modules/core/src/java/org/apache/geronimo/ejb/cache/EntityCreationInterceptor.java
  
  Index: EntityCreationInterceptor.java
  ===================================================================
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2003 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Apache" and "Apache Software Foundation" and
   *    "Apache Geronimo" must not be used to endorse or promote products
   *    derived from this software without prior written permission. For
   *    written permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    "Apache Geronimo", nor may "Apache" appear in their name, without
   *    prior written permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   * ====================================================================
   */
  package org.apache.geronimo.ejb.cache;
  
  import org.apache.geronimo.common.AbstractInterceptor;
  import org.apache.geronimo.ejb.EJBInvocationUtil;
  import org.apache.geronimo.ejb.EnterpriseContext;
  import org.apache.geronimo.common.Invocation;
  import org.apache.geronimo.common.InvocationResult;
  import org.apache.geronimo.common.InvocationType;
  
  /**
   * This interceptor does a double invocation for entity creation.  The first invocation handles
   * the ejbCreate method down the invokeHome chain, and gets the primary key.  The second invocation
   * is down the normal invoke() chain and handles ejbPostCreate.  This makes ejbPostCreate act like
   * a normal business method.
   *
   *
   * @version $Revision: 1.1 $ $Date: 2003/08/10 20:51:54 $
   */
  public final class EntityCreationInterceptor extends AbstractInterceptor {
      public InvocationResult invoke(Invocation invocation) throws Exception {
          InvocationResult result = getNext().invoke(invocation);
  
          InvocationType type = InvocationType.getType(invocation);
          EnterpriseContext ctx = EJBInvocationUtil.getEnterpriseContext(invocation);
  
          // if this is a creation method invoke down the stack again
          if (type.isHomeInvocation() && ctx != null && ctx.getId() != null) {
              try {
                  if (type.isRemoteInvocation()) {
                      InvocationType.putType(invocation, InvocationType.REMOTE);
                  } else {
                      InvocationType.putType(invocation, InvocationType.LOCAL);
                  }
                  EJBInvocationUtil.putId(invocation, ctx.getId());
                  getNext().invoke(invocation);
              } finally {
                  InvocationType.putType(invocation, type);
              }
          }
          return result;
  
      }
  }
  
  
  
  1.1                  incubator-geronimo/modules/core/src/java/org/apache/geronimo/ejb/cache/EntitySynchronizationInterceptor.java
  
  Index: EntitySynchronizationInterceptor.java
  ===================================================================
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2003 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Apache" and "Apache Software Foundation" and
   *    "Apache Geronimo" must not be used to endorse or promote products
   *    derived from this software without prior written permission. For
   *    written permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    "Apache Geronimo", nor may "Apache" appear in their name, without
   *    prior written permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   * ====================================================================
   */
  package org.apache.geronimo.ejb.cache;
  
  import org.apache.geronimo.common.AbstractInterceptor;
  import org.apache.geronimo.ejb.EJBInvocationUtil;
  import org.apache.geronimo.ejb.EnterpriseContext;
  import org.apache.geronimo.common.Invocation;
  import org.apache.geronimo.common.InvocationResult;
  import org.apache.geronimo.ejb.SynchronizationRegistry;
  
  /**
   *
   *
   *
   * @version $Revision: 1.1 $ $Date: 2003/08/10 20:51:54 $
   */
  public final class EntitySynchronizationInterceptor extends AbstractInterceptor {
      // todo find a home for me... should be a JMX object
      private static final SynchronizationRegistry synchronizationRegistry = new SynchronizationRegistry();
  
      public InvocationResult invoke(Invocation invocation) throws Exception {
          // register the context for synchronization
          EnterpriseContext ctx = EJBInvocationUtil.getEnterpriseContext(invocation);
          Object id = EJBInvocationUtil.getId(invocation);
          if (id != null) {
              synchronizationRegistry.beginInvocation(ctx);
          }
  
          boolean threwException = true;
          try {
              // Note there is no need to lock on creation after the invoke because the EntityCreationInterceptor
              // will immedately do a second invoke down the chain for post create causing a lock
              InvocationResult result = getNext().invoke(invocation);
              threwException = false;
              return result;
          } finally {
              // notify the synchronization registry that the invocation has finished
              if (id != null) {
                  synchronizationRegistry.endInvocation(threwException, id, ctx);
              }
          }
      }
  }
  
  
  
  1.1                  incubator-geronimo/modules/core/src/java/org/apache/geronimo/ejb/cache/StatefulInstanceInterceptor.java
  
  Index: StatefulInstanceInterceptor.java
  ===================================================================
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2003 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Apache" and "Apache Software Foundation" and
   *    "Apache Geronimo" must not be used to endorse or promote products
   *    derived from this software without prior written permission. For
   *    written permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    "Apache Geronimo", nor may "Apache" appear in their name, without
   *    prior written permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   * ====================================================================
   */
  package org.apache.geronimo.ejb.cache;
  
  import java.rmi.RemoteException;
  
  import org.apache.geronimo.common.AbstractInterceptor;
  import org.apache.geronimo.ejb.EJBInvocationUtil;
  import org.apache.geronimo.ejb.EnterpriseContext;
  import org.apache.geronimo.common.Invocation;
  import org.apache.geronimo.common.InvocationResult;
  import org.apache.geronimo.common.InvocationType;
  import org.apache.geronimo.common.Container;
  import org.apache.geronimo.ejb.container.EJBPlugins;
  import org.apache.geronimo.ejb.context.ExecutionContext;
  import org.apache.geronimo.lock.LockContext;
  import org.apache.geronimo.lock.LockDomain;
  import org.apache.geronimo.lock.LockReentranceException;
  import org.apache.geronimo.cache.InstancePool;
  import org.apache.geronimo.cache.InstanceCache;
  
  /**
   *
   *
   *
   * @version $Revision: 1.1 $ $Date: 2003/08/10 20:51:54 $
   */
  public final class StatefulInstanceInterceptor extends AbstractInterceptor {
      private InstancePool pool;
      private InstanceCache cache;
      private LockDomain lockDomain;
  
      public void start() throws Exception {
          super.start();
          Container container = getContainer();
          lockDomain = EJBPlugins.getLockDomain(container);
          pool = EJBPlugins.getInstancePool(container);
          cache = EJBPlugins.getInstanceCache(container);
      }
  
      public void stop() {
          lockDomain = null;
          cache = null;
          pool = null;
          super.stop();
      }
  
      public InvocationResult invoke(Invocation invocation) throws Exception {
          EnterpriseContext ctx;
          Object id = null;
  
          InvocationType type = InvocationType.getType(invocation);
          if (type.isHomeInvocation()) {
              ctx = (EnterpriseContext) pool.acquire();
          } else {
              id = EJBInvocationUtil.getId(invocation);
              ctx = (EnterpriseContext) cache.get(id);
          }
          EJBInvocationUtil.putEnterpriseContext(invocation, ctx);
  
          // @todo I don't think we need to set princpal
          //ctx.setPrincipal(invocation.getPrincipal());
  
          boolean threwSystemException = false;
          try {
              return getNext().invoke(invocation);
          } catch (RuntimeException e) {
              threwSystemException = true;
              throw e;
          } catch (RemoteException e) {
              threwSystemException = true;
              throw e;
          } catch (Error e) {
              threwSystemException = true;
              throw e;
          } finally {
              // this invocation is done so remove the reference to the context
              EJBInvocationUtil.putEnterpriseContext(invocation, null);
              if (type.isHomeInvocation()) {
                  if (threwSystemException) {
                      // invocation threw a system exception so the pool needs to dispose of the context
                      pool.remove(ctx);
                  } else if (ctx.getId() != null) {
                      // we were created
                      LockContext lockContext = ExecutionContext.getContext().getLockContext();
                      try {
                          lockContext.exclusiveLock(lockDomain, ctx.getId());
                      } catch (LockReentranceException e) {
                          // this should never happen as we have a new id
                          throw new AssertionError();
                      } catch (InterruptedException e) {
                          // this should never happen as we have a new id
                          throw new AssertionError();
                      }
                      // todo we should get from the instance factory for a create
                      // move this context from the pool to the cache
                      pool.remove(ctx);
                      cache.putActive(ctx.getId(), ctx);
                  } else {
                      // return the context to the pool
                      pool.release(ctx);
                  }
              } else {
                  if (threwSystemException) {
                      // invocation threw a system exception so the cache needs to dispose of the context
                      cache.remove(id);
                  } else if (ctx.getId() == null) {
                      // the instance was removed
                      cache.remove(id);
                  } else {
                      assert (ctx.getId().equals(id));
                  }
              }
          }
      }
  }
  
  
  
  1.1                  incubator-geronimo/modules/core/src/java/org/apache/geronimo/ejb/cache/StatefulSessionSynchronizationInterceptor.java
  
  Index: StatefulSessionSynchronizationInterceptor.java
  ===================================================================
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2003 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Apache" and "Apache Software Foundation" and
   *    "Apache Geronimo" must not be used to endorse or promote products
   *    derived from this software without prior written permission. For
   *    written permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    "Apache Geronimo", nor may "Apache" appear in their name, without
   *    prior written permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   * ====================================================================
   */
  package org.apache.geronimo.ejb.cache;
  
  import java.rmi.RemoteException;
  import java.util.HashMap;
  import java.util.Map;
  import javax.ejb.EJBException;
  import javax.ejb.SessionSynchronization;
  import javax.transaction.Status;
  import javax.transaction.Synchronization;
  import javax.transaction.SystemException;
  import javax.transaction.TransactionManager;
  
  import org.apache.geronimo.common.AbstractInterceptor;
  import org.apache.geronimo.ejb.EJBInvocationUtil;
  import org.apache.geronimo.ejb.EnterpriseContext;
  import org.apache.geronimo.common.Invocation;
  import org.apache.geronimo.common.InvocationResult;
  import org.apache.geronimo.common.InvocationType;
  import org.apache.geronimo.common.Container;
  import org.apache.geronimo.ejb.container.EJBPlugins;
  import org.apache.geronimo.ejb.context.ExecutionContext;
  import org.apache.geronimo.ejb.context.TxExecutionContext;
  import org.apache.geronimo.ejb.metadata.EJBMetadata;
  import org.apache.geronimo.cache.InstanceCache;
  
  /**
   *
   *
   *
   * @version $Revision: 1.1 $ $Date: 2003/08/10 20:51:54 $
   */
  public final class StatefulSessionSynchronizationInterceptor extends AbstractInterceptor {
      protected TransactionManager tm;
      private InstanceCache cache;
      private boolean hasSynchronization;
  
      public void start() throws Exception {
          super.start();
          Container container = getContainer();
          tm = EJBPlugins.getTransactionManager(container);
          cache = EJBPlugins.getInstanceCache(container);
          EJBMetadata ejbMetadata = EJBPlugins.getEJBMetadata(container);
          hasSynchronization = SessionSynchronization.class.isAssignableFrom(ejbMetadata.getBeanClass());
      }
  
      public void stop() {
          cache = null;
          tm = null;
          super.stop();
      }
  
      public InvocationResult invoke(Invocation invocation) throws Exception {
          if (InvocationType.getType(invocation).isHomeInvocation()) {
              // Home invocation's don't have state so they don't need to be synchronized
              return getNext().invoke(invocation);
          }
  
          Object id = EJBInvocationUtil.getId(invocation);
          EnterpriseContext ctx = EJBInvocationUtil.getEnterpriseContext(invocation);
          if (hasSynchronization) {
              register(id, ctx);
          }
          return getNext().invoke(invocation);
      }
  
      private static final String INSTANCE_SYNC_KEY = "Stateful Session Synchronization";
  
      private void register(Object id, EnterpriseContext ctx) throws RemoteException {
          ExecutionContext context = ExecutionContext.getContext();
          if (context instanceof TxExecutionContext == false) {
              return;
          }
  
          // get the map of container to containerMap
          Map syncMap = (Map) context.get(INSTANCE_SYNC_KEY);
          if (syncMap == null) {
              syncMap = new HashMap();
              context.put(INSTANCE_SYNC_KEY, syncMap);
          }
          // get the map from id to InstanceSynchronization for this container
          Map containerMap = (Map) syncMap.get(getContainer());
          if (containerMap == null) {
              containerMap = new HashMap();
              syncMap.put(getContainer(), containerMap);
          }
          // get the instance synchronization for this id
          InstanceSynchronization sync = (InstanceSynchronization) containerMap.get(id);
          if (sync == null) {
              sync = new InstanceSynchronization(ctx);
              sync.begin();
              context.register(sync);
              containerMap.put(id, sync);
          }
      }
  
      public class InstanceSynchronization implements Synchronization {
          private final EnterpriseContext ctx;
          private boolean discard = false;
  
          public InstanceSynchronization(EnterpriseContext ctx) {
              this.ctx = ctx;
          }
  
          private void begin() throws RemoteException {
              ((SessionSynchronization) ctx.getInstance()).afterBegin();
          }
  
          public void beforeCompletion() {
              try {
                  int status = tm.getStatus();
                  // beforeCompletion only happens when the transaction will be committed
                  if (status != Status.STATUS_ACTIVE) {
                      return;
                  }
              } catch (SystemException e) {
                  throw new EJBException("Unable to get transaction status", e);
              }
  
              try {
                  ((SessionSynchronization) ctx.getInstance()).beforeCompletion();
              } catch (Error e) {
                  discard = true;
                  throw e;
              } catch (RuntimeException e) {
                  discard = true;
                  throw e;
              } catch (RemoteException e) {
                  discard = true;
                  throw new EJBException(e);
              } finally {
                  if (discard) {
                      cache.remove(ctx);
                      try {
                          tm.setRollbackOnly();
                      } catch (SystemException e) {
                          throw new EJBException("Unable to set transaction rollback only", e);
                      }
                  }
              }
          }
  
          public void afterCompletion(int status) {
              // can't do much if the instance was discarded
              if (discard) {
                  return;
              }
  
              try {
                  ((SessionSynchronization) ctx.getInstance()).afterCompletion(status == Status.STATUS_COMMITTED);
              } catch (Error e) {
                  discard = true;
                  // give this to the parent, so don't log
                  throw e;
              } catch (RuntimeException e) {
                  discard = true;
                  // log and eat
                  log.warn(e);
              } catch (RemoteException e) {
                  discard = true;
                  // log and eat
                  log.warn(e);
              } finally {
                  if (discard) {
                      cache.remove(ctx);
                  }
              }
          }
      }
  }
  
  
  
  1.1                  incubator-geronimo/modules/core/src/java/org/apache/geronimo/ejb/cache/StatelessInstanceFactory.java
  
  Index: StatelessInstanceFactory.java
  ===================================================================
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2003 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Apache" and "Apache Software Foundation" and
   *    "Apache Geronimo" must not be used to endorse or promote products
   *    derived from this software without prior written permission. For
   *    written permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    "Apache Geronimo", nor may "Apache" appear in their name, without
   *    prior written permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   * ====================================================================
   */
  package org.apache.geronimo.ejb.cache;
  
  import java.lang.reflect.InvocationTargetException;
  import java.lang.reflect.Method;
  import javax.ejb.EJBException;
  import javax.ejb.SessionBean;
  
  import org.apache.geronimo.common.AbstractComponent;
  import org.apache.geronimo.ejb.EnterpriseContext;
  import org.apache.geronimo.ejb.SimpleEnterpriseContext;
  import org.apache.geronimo.ejb.container.EJBPlugins;
  import org.apache.geronimo.ejb.GeronimoSessionContext;
  import org.apache.geronimo.cache.InstanceFactory;
  
  /**
   * 
   * 
   *
   * @version $Revision: 1.1 $ $Date: 2003/08/10 20:51:54 $
   */
  public class StatelessInstanceFactory extends AbstractComponent implements InstanceFactory {
      private Class beanClass;
      private Method ejbCreate;
  
      public void start() throws Exception {
          super.start();
          beanClass = EJBPlugins.getEJBMetadata(getContainer()).getBeanClass();
          ejbCreate = beanClass.getMethod("ejbCreate", null);
      }
  
      public void stop() {
          beanClass = null;
          ejbCreate = null;
          super.stop();
      }
  
      public Object createInstance() throws Exception {
          // create the instance
          SessionBean instance = (SessionBean)beanClass.newInstance();
  
          // initialize the instance
          instance.setSessionContext(new GeronimoSessionContext(getContainer()));
          try {
              ejbCreate.invoke(instance, null);
          } catch (IllegalAccessException e) {
              // This method is using the Java language access control and the
              // underlying method is inaccessible.
              throw new EJBException(e);
          } catch (InvocationTargetException e) {
              // unwrap the exception
              Throwable t = e.getTargetException();
              if (t instanceof Exception) {
                  throw (Exception) t;
              } else if (t instanceof Error) {
                  throw (Error) t;
              } else {
                  throw new Error("Unexpected Throwable", t);
              }
          }
  
          // wrape the instance in an enterprise context
          EnterpriseContext enterpriseContext = new SimpleEnterpriseContext();
          enterpriseContext.setInstance(instance);
          return enterpriseContext;
      }
  }
  
  
  
  1.1                  incubator-geronimo/modules/core/src/java/org/apache/geronimo/ejb/cache/StatelessInstanceInterceptor.java
  
  Index: StatelessInstanceInterceptor.java
  ===================================================================
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2003 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Apache" and "Apache Software Foundation" and
   *    "Apache Geronimo" must not be used to endorse or promote products
   *    derived from this software without prior written permission. For
   *    written permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    "Apache Geronimo", nor may "Apache" appear in their name, without
   *    prior written permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   * ====================================================================
   */
  package org.apache.geronimo.ejb.cache;
  
  import java.rmi.RemoteException;
  
  import org.apache.geronimo.common.AbstractInterceptor;
  import org.apache.geronimo.ejb.EJBInvocationUtil;
  import org.apache.geronimo.ejb.EnterpriseContext;
  import org.apache.geronimo.common.Invocation;
  import org.apache.geronimo.common.InvocationResult;
  import org.apache.geronimo.common.InvocationType;
  import org.apache.geronimo.common.Container;
  import org.apache.geronimo.ejb.container.EJBPlugins;
  import org.apache.geronimo.cache.InstancePool;
  
  /**
   * This interceptor acquires an instance from the pool before invocation,
   * and returns it to the pools after invocation.
   *
   *
   * @version $Revision: 1.1 $ $Date: 2003/08/10 20:51:54 $
   */
  public final class StatelessInstanceInterceptor extends AbstractInterceptor {
      private InstancePool pool;
  
      public void start() throws Exception {
          super.start();
          Container container = getContainer();
          pool = EJBPlugins.getInstancePool(container);
      }
  
      public void stop() {
          pool = null;
          super.stop();
      }
  
      public InvocationResult invoke(final Invocation invocation) throws Exception {
          if (InvocationType.getType(invocation).isHomeInvocation()) {
              // Stateless home invocations don't call on an instance
              return getNext().invoke(invocation);
          }
  
          // get the context
          EnterpriseContext ctx = (EnterpriseContext) pool.acquire();
          assert ctx.getInstance() != null: "Got a context with no instance assigned";
  
          // initialize the context and set it into the invocation
          EJBInvocationUtil.putEnterpriseContext(invocation, ctx);
  
          // @todo I don't think we need set principal at all
          //ctx.setPrincipal(invocation.getPrincipal());
  
          // invoke next, but remember if it threw a system exception
          boolean threwSystemException = false;
          try {
              return getNext().invoke(invocation);
          } catch (RuntimeException e) {
              threwSystemException = true;
              throw e;
          } catch (RemoteException e) {
              threwSystemException = true;
              throw e;
          } catch (Error e) {
              threwSystemException = true;
              throw e;
          } finally {
              // this invocation is done so remove the reference to the context
              EJBInvocationUtil.putEnterpriseContext(invocation, null);
              if (threwSystemException) {
                  // invocation threw a system exception so the pool needs to dispose of the context
                  pool.remove(ctx);
              } else {
                  // return the context to the pool
                  pool.release(ctx);
              }
          }
      }
  }
  
  
  
  1.1                  incubator-geronimo/modules/core/src/java/org/apache/geronimo/ejb/container/ContainerImpl.java
  
  Index: ContainerImpl.java
  ===================================================================
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2003 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Apache" and "Apache Software Foundation" and
   *    "Apache Geronimo" must not be used to endorse or promote products
   *    derived from this software without prior written permission. For
   *    written permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    "Apache Geronimo", nor may "Apache" appear in their name, without
   *    prior written permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   * ====================================================================
   */
  package org.apache.geronimo.ejb.container;
  
  import java.util.Iterator;
  import java.util.LinkedHashMap;
  import java.util.LinkedList;
  import java.util.ListIterator;
  import java.util.Map;
  import javax.management.ObjectName;
  
  import org.apache.geronimo.common.AbstractComponent;
  import org.apache.geronimo.common.Component;
  import org.apache.geronimo.common.Interceptor;
  import org.apache.geronimo.common.Invocation;
  import org.apache.geronimo.common.InvocationResult;
  import org.apache.geronimo.common.State;
  import org.apache.geronimo.common.Container;
  
  /**
   *
   *
   *
   * @version $Revision: 1.1 $ $Date: 2003/08/10 20:51:54 $
   */
  public class ContainerImpl extends AbstractComponent implements Container {
      private final Map plugins = new LinkedHashMap();
      private final Map pluginObjects = new LinkedHashMap();
      private final LinkedList interceptors = new LinkedList();
      // for efficency keep a reference to the first interceptor
      private Interceptor firstInterceptor;
  
      public InvocationResult invoke(Invocation invocation) throws Exception {
          return firstInterceptor.invoke(invocation);
      }
  
      public void addInterceptor(Interceptor interceptor) {
          if (firstInterceptor == null) {
              firstInterceptor = interceptor;
              interceptors.addLast(interceptor);
          } else {
              Interceptor lastInterceptor = (Interceptor) interceptors.getLast();
              lastInterceptor.setNext(interceptor);
              interceptors.addLast(interceptor);
          }
      }
  
      public void create() throws Exception {
          super.create();
          // Create all the interceptors in forward insertion order
          for (Iterator iterator = pluginObjects.values().iterator(); iterator.hasNext();) {
              Object object = iterator.next();
              if (object instanceof Component) {
                  Component component = (Component) object;
                  component.setContainer(this);
                  component.create();
              }
          }
  
          // Create all the plugins in forward insertion order
          for (Iterator iterator = interceptors.iterator(); iterator.hasNext();) {
              Interceptor interceptor = (Interceptor) iterator.next();
              interceptor.setContainer(this);
              interceptor.create();
          }
      }
  
      public void start() throws Exception {
          super.start();
          // Start all the interceptors in forward insertion order
          for (Iterator iterator = pluginObjects.values().iterator(); iterator.hasNext();) {
              Object object = iterator.next();
              if (object instanceof Component) {
                  Component component = (Component) object;
                  component.start();
              }
          }
  
          // Start all the plugins in forward insertion order
          for (Iterator iterator = interceptors.iterator(); iterator.hasNext();) {
              Interceptor interceptor = (Interceptor) iterator.next();
              interceptor.start();
          }
      }
  
      public void stop() {
          // Stop all the interceptors in reverse insertion order
          for (ListIterator iterator = interceptors.listIterator(interceptors.size()); iterator.hasPrevious();) {
              Interceptor interceptor = (Interceptor) iterator.previous();
              interceptor.stop();
          }
  
          // Stop all the plugins in reverse insertion order
          LinkedList list = new LinkedList();
          for (Iterator iterator = pluginObjects.values().iterator(); iterator.hasNext();) {
              Object object = iterator.next();
              if (object instanceof Component) {
                  list.addFirst(object);
              }
          }
          for (Iterator iterator = list.iterator(); iterator.hasNext();) {
              Component component = (Component) iterator.next();
              component.stop();
          }
  
          super.stop();
      }
  
      public void destroy() {
          // Destroy all the interceptors in reverse insertion order
          for (ListIterator iterator = interceptors.listIterator(interceptors.size()); iterator.hasPrevious();) {
              Interceptor interceptor = (Interceptor) iterator.previous();
              interceptor.destroy();
              interceptor.setContainer(null);
          }
  
          // Destroy all the plugins in reverse insertion order
          LinkedList list = new LinkedList();
          for (Iterator iterator = pluginObjects.values().iterator(); iterator.hasNext();) {
              Object object = iterator.next();
              if (object instanceof Component) {
                  list.addFirst(object);
              }
          }
          for (Iterator iterator = list.iterator(); iterator.hasNext();) {
              Component component = (Component) iterator.next();
              component.destroy();
              component.setContainer(null);
          }
  
          plugins.clear();
          pluginObjects.clear();
          super.destroy();
      }
  
      public ObjectName getPlugin(String logicalPluginName) {
          return (ObjectName) plugins.get(logicalPluginName);
      }
  
      public void putPlugin(String logicalPluginName, ObjectName objectName) {
          State state = getState();
          if (state != State.NOT_CREATED && state != State.DESTROYED) {
              throw new IllegalStateException("putPluginObject can only be called while in the not-created or destroyed states: state=" + state);
          }
          if (state == State.NOT_CREATED && objectName == null) {
              throw new IllegalArgumentException("Container has not been created; objectName must be NOT null.");
          }
          if (state == State.DESTROYED && objectName != null) {
              throw new IllegalArgumentException("Container has been destroyed; objectName must be null.");
          }
  
          plugins.put(logicalPluginName, objectName);
      }
  
      public Object getPluginObject(String logicalPluginName) {
          return pluginObjects.get(logicalPluginName);
      }
  
      public void putPluginObject(String logicalPluginName, Object plugin) {
          State state = getState();
          if (state != State.NOT_CREATED && state != State.DESTROYED) {
              throw new IllegalStateException("putPluginObject can only be called while in the not-created or destroyed states: state=" + state);
          }
          if (state == State.NOT_CREATED && plugin == null) {
              throw new IllegalArgumentException("Container has not been created; plugin must be NOT null.");
          }
          if (state == State.DESTROYED && plugin != null) {
              throw new IllegalArgumentException("Container has been destroyed; plugin must be null.");
          }
  
          pluginObjects.put(logicalPluginName, plugin);
      }
  }
  
  
  
  
  1.1                  incubator-geronimo/modules/core/src/java/org/apache/geronimo/ejb/container/EJBContainerUtil.java
  
  Index: EJBContainerUtil.java
  ===================================================================
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2003 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Apache" and "Apache Software Foundation" and
   *    "Apache Geronimo" must not be used to endorse or promote products
   *    derived from this software without prior written permission. For
   *    written permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    "Apache Geronimo", nor may "Apache" appear in their name, without
   *    prior written permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   * ====================================================================
   */
  package org.apache.geronimo.ejb.container;
  
  import java.io.ObjectStreamException;
  import java.io.Serializable;
  import java.lang.reflect.Method;
  import java.security.Principal;
  
  import org.apache.geronimo.common.Invocation;
  
  /**
   *
   *
   *
   * @version $Revision: 1.1 $ $Date: 2003/08/10 20:51:54 $
   */
  public final class EJBContainerUtil implements Serializable {
      // Be careful here.  If you change the oridnals, this class must be changed on evey client.
      private static int MAX_ORIDNAL = 4;
      private static final EJBContainerUtil[] values = new EJBContainerUtil[MAX_ORIDNAL + 1];
      private static final EJBContainerUtil METHOD = new EJBContainerUtil("METHOD", 0);
      private static final EJBContainerUtil ID = new EJBContainerUtil("ID", 1);
      private static final EJBContainerUtil ARGUMENTS = new EJBContainerUtil("ARGUMENTS", 2);
      private static final EJBContainerUtil PRINCIPAL = new EJBContainerUtil("PRINCIPAL", 3);
      private static final EJBContainerUtil CREDENTIALS = new EJBContainerUtil("CREDENTIALS", 4);
  
      public static Method getMethod(Invocation invocation) {
          return (Method) invocation.getAsIs(METHOD);
      }
  
      public static void putMethod(Invocation invocation, Method method) {
          invocation.putAsIs(METHOD, method);
      }
  
      public static Object getId(Invocation invocation) {
          return invocation.getMarshal(ID);
      }
  
      public static void putId(Invocation invocation, Object id) {
          invocation.putMarshal(ID, id);
      }
  
      public static Object[] getArguments(Invocation invocation) {
          return (Object[]) invocation.getMarshal(ARGUMENTS);
      }
  
      public static void putArguments(Invocation invocation, Object[] arguments) {
          invocation.putMarshal(ARGUMENTS, arguments);
      }
  
      public static Principal getPrincipal(Invocation invocation) {
          return (Principal) invocation.getAsIs(PRINCIPAL);
      }
  
      public static void putPrincipal(Invocation invocation, Principal principal) {
          invocation.putAsIs(PRINCIPAL, principal);
      }
  
      public static Object getCredentials(Invocation invocation) {
          return invocation.getMarshal(CREDENTIALS);
      }
  
      public static void putCredentials(Invocation invocation, Object credentials) {
          invocation.putMarshal(CREDENTIALS, credentials);
      }
  
      private final transient String name;
      private final int ordinal;
  
      private EJBContainerUtil(String name, int ordinal) {
          assert(ordinal < MAX_ORIDNAL);
          assert(values[ordinal] == null);
          this.name = name;
          this.ordinal = ordinal;
          values[ordinal] = this;
      }
  
      public String toString() {
          return name;
      }
  
      Object readResolve() throws ObjectStreamException {
          return values[ordinal];
      }
  }
  
  
  
  1.1                  incubator-geronimo/modules/core/src/java/org/apache/geronimo/ejb/container/EJBPlugins.java
  
  Index: EJBPlugins.java
  ===================================================================
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2003 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Apache" and "Apache Software Foundation" and
   *    "Apache Geronimo" must not be used to endorse or promote products
   *    derived from this software without prior written permission. For
   *    written permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    "Apache Geronimo", nor may "Apache" appear in their name, without
   *    prior written permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   * ====================================================================
   */
  package org.apache.geronimo.ejb.container;
  
  import javax.transaction.TransactionManager;
  
  import org.apache.geronimo.cache.InstanceCache;
  import org.apache.geronimo.cache.InstanceFactory;
  import org.apache.geronimo.cache.InstancePool;
  import org.apache.geronimo.ejb.EJBProxyFactoryManager;
  import org.apache.geronimo.lock.LockDomain;
  import org.apache.geronimo.ejb.metadata.EJBMetadata;
  import org.apache.geronimo.common.Container;
  
  /**
   *
   *
   *
   * @version $Revision: 1.1 $ $Date: 2003/08/10 20:51:54 $
   */
  public final class EJBPlugins {
      // only static methods are allowed for this class
      private EJBPlugins() {}
  
      public static String EJB_PROXY_FACTORY_MANAGER = "EJB Proxy Factory Manager";
      public static String EJB_METADATA = "EJB Metadata";
      public static String TRANSACTION_MANAGER = "Transaction Manager";
      public static String EJB_CONTEXT_INSTANCE_FACTORY = "EJB Context Instance Factory";
      public static String EJB_CONTEXT_INSTANCE_POOL = "EJB Context Instance Pool";
      public static String EJB_CONTEXT_INSTANCE_CACHE = "EJB Context Instance Cache";
      public static String PERSISTENCE_MANAGER = "Persustence Manager";
      public static String LOCK_DOMAIN = "Lock Domain";
  
      public static EJBProxyFactoryManager getEJBProxyFactoryManager(Container container) {
          return (EJBProxyFactoryManager) container.getPluginObject(EJB_PROXY_FACTORY_MANAGER);
      }
  
      public static void putEJBProxyFactoryManager(Container container, EJBProxyFactoryManager ejbProxyFactoryManager) {
          container.putPluginObject(EJB_PROXY_FACTORY_MANAGER, ejbProxyFactoryManager);
      }
  
      public static EJBMetadata getEJBMetadata(Container container) {
          return (EJBMetadata) container.getPluginObject(EJB_METADATA);
      }
  
      public static void putEJBMetadata(Container container, EJBMetadata ejbMetadata) {
          container.putPluginObject(EJB_METADATA, ejbMetadata);
      }
  
      public static TransactionManager getTransactionManager(Container container) {
          return (TransactionManager) container.getPluginObject(TRANSACTION_MANAGER);
      }
  
      public static void putTransactionManager(Container container, TransactionManager transactionManager) {
          container.putPluginObject(TRANSACTION_MANAGER, transactionManager);
      }
  
      public static InstanceFactory getInstanceFactory(Container container) {
          return (InstanceFactory) container.getPluginObject(EJB_CONTEXT_INSTANCE_FACTORY);
      }
  
      public static void putInstanceFactory(Container container, InstanceFactory instanceFactory) {
          container.putPluginObject(EJB_CONTEXT_INSTANCE_FACTORY, instanceFactory);
      }
  
      public static InstancePool getInstancePool(Container container) {
          return (InstancePool) container.getPluginObject(EJB_CONTEXT_INSTANCE_POOL);
      }
  
      public static void putInstancePool(Container container, InstancePool instancePool) {
          container.putPluginObject(EJB_CONTEXT_INSTANCE_POOL, instancePool);
      }
  
      public static InstanceCache getInstanceCache(Container container) {
          return (InstanceCache) container.getPluginObject(EJB_CONTEXT_INSTANCE_CACHE);
      }
  
      public static void putInstanceCache(Container container, InstanceCache instanceCache) {
          container.putPluginObject(EJB_CONTEXT_INSTANCE_CACHE, instanceCache);
      }
  
      public static PersistenceManager getPersistenceManager(Container container) {
          return (PersistenceManager) container.getPluginObject(EJB_CONTEXT_INSTANCE_CACHE);
      }
  
      public static void putPersistenceManager(Container container, PersistenceManager persistenceManager) {
          container.putPluginObject(EJB_CONTEXT_INSTANCE_CACHE, persistenceManager);
      }
  
      public static LockDomain getLockDomain(Container container) {
          return (LockDomain) container.getPluginObject(LOCK_DOMAIN);
      }
  
      public static void putLockDomain(Container container, LockDomain lockDomain) {
          container.putPluginObject(LOCK_DOMAIN, lockDomain);
      }
  }
  
  
  
  1.1                  incubator-geronimo/modules/core/src/java/org/apache/geronimo/ejb/container/PersistenceManager.java
  
  Index: PersistenceManager.java
  ===================================================================
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2003 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Apache" and "Apache Software Foundation" and
   *    "Apache Geronimo" must not be used to endorse or promote products
   *    derived from this software without prior written permission. For
   *    written permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    "Apache Geronimo", nor may "Apache" appear in their name, without
   *    prior written permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   * ====================================================================
   */
  package org.apache.geronimo.ejb.container;
  
  import java.lang.reflect.Method;
  import java.util.Collection;
  
  import org.apache.geronimo.ejb.EnterpriseContext;
  
  /**
   *
   *
   *
   * @version $Revision: 1.1 $ $Date: 2003/08/10 20:51:54 $
   */
  public interface PersistenceManager {
      Object createBeanClassInstance() throws Exception;
  
      void create(Method m, Object[] args, EnterpriseContext context) throws Exception;
  
      void postCreate(Method m, Object[] args, EnterpriseContext context) throws Exception;
  
      Collection find(Method finderMethod, Object[] args, EnterpriseContext context) throws Exception;
  
      void activate(EnterpriseContext context) throws Exception;
  
      void load(EnterpriseContext context) throws Exception;
  
      boolean isModified(EnterpriseContext context) throws Exception;
  
      void store(EnterpriseContext context) throws Exception;
  
      void passivate(EnterpriseContext context) throws Exception;
  
      void remove(EnterpriseContext context) throws Exception;
  }
  
  
  
  1.1                  incubator-geronimo/modules/core/src/java/org/apache/geronimo/ejb/context/CMTInterceptor.java
  
  Index: CMTInterceptor.java
  ===================================================================
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2003 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Apache" and "Apache Software Foundation" and
   *    "Apache Geronimo" must not be used to endorse or promote products
   *    derived from this software without prior written permission. For
   *    written permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    "Apache Geronimo", nor may "Apache" appear in their name, without
   *    prior written permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   * ====================================================================
   */
  package org.apache.geronimo.ejb.context;
  
  import java.lang.reflect.Method;
  import java.rmi.RemoteException;
  import javax.ejb.EJBException;
  import javax.ejb.TransactionRequiredLocalException;
  import javax.transaction.RollbackException;
  import javax.transaction.Status;
  import javax.transaction.SystemException;
  import javax.transaction.Transaction;
  import javax.transaction.TransactionRequiredException;
  
  import org.apache.geronimo.ejb.EJBInvocationUtil;
  import org.apache.geronimo.common.Invocation;
  import org.apache.geronimo.common.InvocationResult;
  import org.apache.geronimo.common.InvocationType;
  import org.apache.geronimo.ejb.container.EJBPlugins;
  import org.apache.geronimo.ejb.metadata.EJBMetadata;
  import org.apache.geronimo.ejb.metadata.TransactionAttribute;
  import org.apache.geronimo.ejb.metadata.MethodMetadata;
  import org.apache.geronimo.transaction.GeronimoRollbackException;
  import org.apache.geronimo.transaction.GeronimoTransactionRolledbackException;
  import org.apache.geronimo.transaction.GeronimoTransactionRolledbackLocalException;
  
  /**
   *
   * @version $Revision: 1.1 $ $Date: 2003/08/10 20:51:54 $
   */
  public final class CMTInterceptor extends ExecutionContextInterceptor {
      private EJBMetadata ejbMetadata;
  
      public void start() throws Exception {
          super.start();
          ejbMetadata = EJBPlugins.getEJBMetadata(getContainer());
      }
  
      public void stop() {
          ejbMetadata = null;
          super.stop();
      }
  
      public InvocationResult invoke(Invocation invocation) throws Exception {
          Method m = EJBInvocationUtil.getMethod(invocation);
          if (m == null) {
              // we are not invoking a method (e.g. its a CMR message) so pass straight through
              return getNext().invoke(invocation);
          }
          MethodMetadata methodMetadata = ejbMetadata.getMethodMetadata(m);
          TransactionAttribute transactionAttribute = null;
          if(methodMetadata != null) {
              transactionAttribute = methodMetadata.getTransactionAttribute();
          }
  
          if (transactionAttribute == null) {
              return getNext().invoke(invocation);
          }
  
          Transaction oldTransaction = getTransaction();
          boolean inTransaction = (oldTransaction != null);
          InvocationType type = InvocationType.getType(invocation);
  
          if (transactionAttribute == TransactionAttribute.NOT_SUPPORTED) {
              // suspend any current transaction and invoke without one
              return noTxContext(invocation, oldTransaction);
          } else if (transactionAttribute == TransactionAttribute.UNSPECIFIED ||
                  transactionAttribute == TransactionAttribute.REQUIRED) {
              // if we have a transaction use it otherwise start one
              if (inTransaction) {
                  return sameTxContext(invocation, oldTransaction);
              } else {
                  return newTxContext(invocation, oldTransaction);
              }
          } else if (transactionAttribute == TransactionAttribute.SUPPORTS) {
              // use the existing context
              if (inTransaction) {
                  return sameTxContext(invocation, oldTransaction);
              } else {
                  return noTxContext(invocation, oldTransaction);
              }
          } else if (transactionAttribute == TransactionAttribute.REQUIRES_NEW) {
              // always start a new transaction
              return newTxContext(invocation, oldTransaction);
          } else if (transactionAttribute == TransactionAttribute.MANDATORY) {
              // we must have a transaction, otherwise error
              if (inTransaction) {
                  return sameTxContext(invocation, oldTransaction);
              } else {
                  if (type.isLocalInvocation()) {
                      throw new TransactionRequiredLocalException("Transaction is mandatory");
                  } else {
                      throw new TransactionRequiredException("Transaction is mandatory");
                  }
              }
          } else if (transactionAttribute == TransactionAttribute.NEVER) {
              // we must not have a transaction, if we do error
              if (inTransaction) {
                  if (type.isLocalInvocation()) {
                      throw new EJBException("Transaction present and method is marked NEVER");
                  } else {
                      throw new RemoteException("Transaction present and method is marked NEVER");
                  }
              } else {
                  return noTxContext(invocation, oldTransaction);
              }
          } else {
              // we should never get here because the above is a type safe enumeration, but someone may
              // hack in another value, so be safe...
              throw new AssertionError();
          }
      }
  
      /**
       * Invoke the next interceptor with a new TxExecutionContext and a new Transaction.
       * If the current Thread is associated with a Transaction, it will be suspended and
       * a new transactional context created.
       * @param invocation the invocation to pass down
       * @return the result from the interceptor
       * @throws Exception from the next interceptor
       * @throws EJBTransactionException if there was a problem interacting with the TransactionManager
       */
      private InvocationResult newTxContext(Invocation invocation, Transaction oldTransaction) throws EJBTransactionException, Exception {
          if (oldTransaction == null) {
              // we have no transaction, start the new one
              return invokeWithNewTx(invocation);
          } else {
              // we have a transaction, so suspend it first and then start a new one
              suspend();
              try {
                  return invokeWithNewTx(invocation);
              } finally {
                  resume(oldTransaction);
              }
          }
      }
  
      /**
       * Invoke the next interceptor with a new TxExecutionContext and a new Transaction.
       * There must not be a Transaction currently associated with the Thread
       * @param invocation the invocation to pass down
       * @return the result from the interceptor
       * @throws Exception from the next interceptor
       * @throws EJBTransactionException if there was a problem interacting with the TransactionManager
       */
      private InvocationResult invokeWithNewTx(Invocation invocation) throws Exception {
          TxExecutionContext newContext = new TxExecutionContext(tm);
          InvocationResult result;
          try {
              newContext.startTransaction();
          } catch (Exception e) {
              // [EJB2.0 18.3.6 pp 379] failed to start so throw appropriate exception
              throw wrapTransactionException(invocation, e);
          }
  
          try {
              result = invokeNext(newContext, invocation);
          } catch (Error e) {
              systemException(newContext, e);
              throw e;
          } catch (RuntimeException e) {
              systemException(newContext, e);
              throw e;
          } catch (RemoteException e) {
              systemException(newContext, e);
              throw e;
          } catch (Exception e) {
              // application exception
              endTransaction(invocation, newContext);
              throw e;
          }
          endTransaction(invocation, newContext);
          return result;
      }
  
      /**
       * Handle a system exception returned by the interceptor chain
       * @param newContext the current execution context
       * @param t the system exception
       */
      private void systemException(TxExecutionContext newContext, Throwable t) {
          try {
              tm.setRollbackOnly();
              tm.rollback();
          } catch (SystemException e) {
              log.error("Unable to roll back after system exception, continuing", e);
          } finally {
              newContext.abnormalTermination(t);
          }
      }
  
      /**
       * End the current transaction normally. This will rollback if the transaction is
       * marked for rollback, otherwise it tries to commit. Any errors result in
       * an abnormal termination for the context
       * @param invocation the current invocation
       * @param newContext the current execution context
       * @throws Exception if the commit or rollback failed
       */
      private void endTransaction(Invocation invocation, TxExecutionContext newContext) throws Exception {
          Transaction tx = newContext.getTransaction();
          try {
              if (tx.getStatus() == Status.STATUS_MARKED_ROLLBACK) {
                  tm.rollback();
              } else {
                  tm.commit();
              }
              newContext.normalTermination();
          } catch (Exception e) {
              // [EJB2.0 18.3.6 pp 379] failed to commit/rollback so throw appropriate exception
              // This overrides the normal return of the result or app exception defined in [EJB2.0 18.3.1]
              newContext.abnormalTermination(e);
              throw wrapTransactionException(invocation, e);
          }
      }
  
      /**
       * Invoke the next interceptor with a new NoTxExecutionContext. If the current Thread
       * is associated with a Transaction, it will be suspended.
       * @param invocation the invocation to pass down
       * @return the result from the interceptor
       * @throws Exception from the next interceptor
       * @throws EJBTransactionException if there was a problem interacting with the TransactionManager
       */
      private InvocationResult noTxContext(Invocation invocation, Transaction oldTransaction) throws EJBTransactionException, Exception {
          if (oldTransaction == null) {
              // we have no transaction, so just invoke
              return invokeWithNoTx(invocation);
          } else {
              // we have a transaction, so suspend it and then invoke without one
              suspend();
              try {
                  return invokeWithNoTx(invocation);
              } finally {
                  resume(oldTransaction);
              }
          }
      }
  
      /**
       * Create a new non-transactional context and then invoke the next interceptor
       * @param invocation the invocation to pass down
       * @return the result from the interceptor
       * @throws Exception from the next interceptor
       */
      private InvocationResult invokeWithNoTx(Invocation invocation) throws Exception {
          NoTxExecutionContext newContext = new NoTxExecutionContext();
          try {
              return invokeNext(newContext, invocation);
          } catch (Error e) {
              newContext.abnormalTermination(e);
              throw e;
          } catch (RuntimeException e) {
              newContext.abnormalTermination(e);
              throw e;
          } catch (RemoteException e) {
              newContext.abnormalTermination(e);
              throw e;
          } catch (Exception e) {
              newContext.normalTermination();
              throw e;
          } finally {
              newContext.normalTermination();
          }
      }
  
      /**
       * Invoke the next interceptor in the same context as we were invoked.
       * Will associate the appropriate ExecutionContext with the current Thread
       * if it does not already have one.
       * @param invocation the invocation to pass down
       * @return the result from the interceptor
       * @throws Exception from the next interceptor
       * @throws EJBTransactionException if we could not register a new TxExecutionContext with the TransactionManager
       */
      private InvocationResult sameTxContext(Invocation invocation, Transaction oldTransaction) throws EJBTransactionException, Exception {
          TxExecutionContext context = TxExecutionContext.getContext(oldTransaction);
          if (context == null) {
              assert (oldTransaction != null);
              try {
                  context = new TxExecutionContext(tm, oldTransaction);
              } catch (RollbackException e) {
                  throw wrapTransactionException(invocation, e);
              } catch (SystemException e) {
                  throw new EJBTransactionException("Unable to register with Transaction", e);
              }
          } else {
              assert (context.getTransaction() == oldTransaction);
          }
          return invokeNext(context, invocation);
      }
  
      /**
       * Wrap an Exception thrown during start or commit in a RemoteException or EJBException.
       * We use the appropriate GeronimoTransactionRolledback sub-class so that the caller can
       * extract the root cause of the rollback if needed.
       * @param invocation the current invocation
       * @param e the exception thrown during start or commit
       * @return a GeronimoTransactionRolledbackException if the invocation is remote,
       *         a GeronimoTransactionRolledbackLocalException if the invocation is local
       */
      private Exception wrapTransactionException(Invocation invocation, Exception e) {
          if (e instanceof GeronimoRollbackException) {
              GeronimoRollbackException jre = (GeronimoRollbackException) e;
              if (jre.getCause() instanceof Exception) {
                  e = (Exception) jre.getCause();
              }
          }
          if (InvocationType.getType(invocation).isLocalInvocation()) {
              return new GeronimoTransactionRolledbackLocalException(e);
          } else {
              return new GeronimoTransactionRolledbackException(e);
          }
      }
  }
  
  
  
  1.1                  incubator-geronimo/modules/core/src/java/org/apache/geronimo/ejb/context/EJBTransactionException.java
  
  Index: EJBTransactionException.java
  ===================================================================
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2003 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Apache" and "Apache Software Foundation" and
   *    "Apache Geronimo" must not be used to endorse or promote products
   *    derived from this software without prior written permission. For
   *    written permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    "Apache Geronimo", nor may "Apache" appear in their name, without
   *    prior written permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   * ====================================================================
   */
  package org.apache.geronimo.ejb.context;
  
  import javax.ejb.EJBException;
  
  /**
   *
   *
   * @version $Revision: 1.1 $ $Date: 2003/08/10 20:51:54 $
   */
  public class EJBTransactionException extends EJBException {
      public EJBTransactionException() {
      }
  
      public EJBTransactionException(Exception e) {
          super(e);
      }
  
      public EJBTransactionException(String s) {
          super(s);
      }
  
      public EJBTransactionException(String s, Exception e) {
          super(s, e);
      }
  }
  
  
  
  1.1                  incubator-geronimo/modules/core/src/java/org/apache/geronimo/ejb/context/ExecutionContext.java
  
  Index: ExecutionContext.java
  ===================================================================
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2003 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Apache" and "Apache Software Foundation" and
   *    "Apache Geronimo" must not be used to endorse or promote products
   *    derived from this software without prior written permission. For
   *    written permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    "Apache Geronimo", nor may "Apache" appear in their name, without
   *    prior written permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   * ====================================================================
   */
  package org.apache.geronimo.ejb.context;
  
  import java.util.IdentityHashMap;
  import java.util.Iterator;
  import java.util.LinkedList;
  import java.util.Map;
  import javax.transaction.Synchronization;
  
  import org.apache.commons.logging.Log;
  import org.apache.commons.logging.LogFactory;
  
  import org.apache.geronimo.lock.LockContext;
  
  /**
   *
   *
   * @version $Revision: 1.1 $ $Date: 2003/08/10 20:51:54 $
   */
  public abstract class ExecutionContext {
      private static Log log = LogFactory.getLog(ExecutionContext.class);
  
      private static ThreadLocal context = new ThreadLocal() {
          protected Object initialValue() {
              return new LinkedList();
          }
      };
  
      private static LinkedList getList() {
          return (LinkedList) context.get();
      }
  
      public static ExecutionContext getContext() {
          LinkedList list = getList();
          return list.isEmpty() ? null : (ExecutionContext) list.getFirst();
      }
  
      public static void push(ExecutionContext newContext) {
          assert (newContext != null);
          getList().addFirst(newContext);
      }
  
      public static void pop(ExecutionContext newContext) {
          assert (newContext != null);
          assert (getContext() == newContext);
          getList().removeFirst();
      }
  
      private final Map values = new IdentityHashMap();
      protected final LinkedList listeners = new LinkedList();
      private final LockContext lockContext;
      private boolean readOnly = false;
  
      protected ExecutionContext(LockContext lockContext) {
          this.lockContext = lockContext;
          register(lockContext);
      }
  
      public LockContext getLockContext() {
          return lockContext;
      }
  
      public boolean isReadOnly() {
          return readOnly;
      }
  
      public void setReadOnly(boolean readOnly) {
          this.readOnly = readOnly;
      }
  
      public synchronized void register(Synchronization listener) {
          listeners.add(listener);
      }
  
      protected void runBeforeCompletion() {
          // do beforeCompletion in order that they registered
          for (Iterator i = listeners.iterator(); i.hasNext();) {
              Synchronization synchronization = (Synchronization) i.next();
              synchronization.beforeCompletion();
          }
      }
  
      protected void runAfterCompletion(int status) {
          // do afterCompletion in reverse order
          while (!listeners.isEmpty()) {
              Synchronization synchronization = (Synchronization) listeners.removeLast();
              try {
                  synchronization.afterCompletion(status);
              } catch (RuntimeException e) {
                  log.error("Error in afterCompletion", e);
              } catch (Error e) {
                  log.error("Error in afterCompletion", e);
              }
          }
      }
  
      public void normalTermination() {
      }
  
      public void abnormalTermination(Throwable t) {
      }
  
      public Object put(Object key, Object value) {
          return values.put(key, value);
      }
  
      public Object get(Object key) {
          return values.get(key);
      }
  
      public Object remove(Object key) {
          return values.remove(key);
      }
  }
  
  
  
  1.1                  incubator-geronimo/modules/core/src/java/org/apache/geronimo/ejb/context/ExecutionContextInterceptor.java
  
  Index: ExecutionContextInterceptor.java
  ===================================================================
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2003 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Apache" and "Apache Software Foundation" and
   *    "Apache Geronimo" must not be used to endorse or promote products
   *    derived from this software without prior written permission. For
   *    written permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    "Apache Geronimo", nor may "Apache" appear in their name, without
   *    prior written permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   * ====================================================================
   */
  package org.apache.geronimo.ejb.context;
  
  import javax.transaction.SystemException;
  import javax.transaction.Transaction;
  import javax.transaction.TransactionManager;
  
  import org.apache.geronimo.common.AbstractInterceptor;
  import org.apache.geronimo.common.Invocation;
  import org.apache.geronimo.common.InvocationResult;
  import org.apache.geronimo.ejb.container.EJBPlugins;
  
  /**
   *
   *
   *
   * @version $Revision: 1.1 $ $Date: 2003/08/10 20:51:54 $
   */
  public abstract class ExecutionContextInterceptor extends AbstractInterceptor {
      protected TransactionManager tm;
  
      public void start() throws Exception {
          super.start();
          tm = EJBPlugins.getTransactionManager(getContainer());
      }
  
      public void stop() {
          tm = null;
          super.stop();
      }
  
      /**
       * Invoke the appropriate method on the next interceptor inside the supplied context.
       * @param context the context to run inside
       * @param invocation the invocation to pass down
       * @return the result of the invocation
       * @throws java.lang.Exception any Exception from the next interceptor
       */
      protected InvocationResult invokeNext(ExecutionContext context, Invocation invocation) throws Exception {
          ExecutionContext.push(context);
          try {
              return getNext().invoke(invocation);
          } finally {
              ExecutionContext.pop(context);
          }
      }
  
      protected Transaction getTransaction() throws EJBTransactionException {
          try {
              return tm.getTransaction();
          } catch (SystemException e) {
              throw new EJBTransactionException("Unable to get current Transaction", e);
          }
      }
  
      /**
       * Suspend the current Transaction
       * @throws org.apache.geronimo.ejb.context.EJBTransactionException if the Transaction could not be suspended
       */
      protected Transaction suspend() throws EJBTransactionException {
          try {
              return tm.suspend();
          } catch (SystemException e) {
              throw new EJBTransactionException("Unable to suspend current transaction", e);
          }
      }
  
      /**
       * Resume a previous Transaction
       * @param tx the Transaction to resume
       * @throws org.apache.geronimo.ejb.context.EJBTransactionException if the Transaction could not be resumed
       */
      protected void resume(Transaction tx) throws EJBTransactionException {
          try {
              tm.resume(tx);
          } catch (Exception e) {
              throw new EJBTransactionException("Unable to resume current transaction", e);
          }
      }
  }
  
  
  
  1.1                  incubator-geronimo/modules/core/src/java/org/apache/geronimo/ejb/context/GeronimoUserTransaction.java
  
  Index: GeronimoUserTransaction.java
  ===================================================================
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2003 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Apache" and "Apache Software Foundation" and
   *    "Apache Geronimo" must not be used to endorse or promote products
   *    derived from this software without prior written permission. For
   *    written permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    "Apache Geronimo", nor may "Apache" appear in their name, without
   *    prior written permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   * ====================================================================
   */
  package org.apache.geronimo.ejb.context;
  
  import javax.transaction.HeuristicMixedException;
  import javax.transaction.HeuristicRollbackException;
  import javax.transaction.NotSupportedException;
  import javax.transaction.RollbackException;
  import javax.transaction.SystemException;
  import javax.transaction.TransactionManager;
  import javax.transaction.UserTransaction;
  
  /**
   * 
   * 
   *
   * @version $Revision: 1.1 $ $Date: 2003/08/10 20:51:54 $
   */
  public final class GeronimoUserTransaction implements UserTransaction {
      private TransactionManager transactionManager;
  
      public GeronimoUserTransaction(TransactionManager transactionManager) {
          this.transactionManager = transactionManager;
      }
  
      public void begin() throws NotSupportedException, SystemException {
          TxExecutionContext newContext = new TxExecutionContext(transactionManager);
          try {
              newContext.startTransaction();
          } catch (RollbackException e) {
              SystemException systemException = new SystemException();
              systemException.initCause(e);
              throw systemException;
          }
          ExecutionContext.push(newContext);
      }
  
      public void commit() throws RollbackException, HeuristicMixedException, HeuristicRollbackException, SecurityException, IllegalStateException, SystemException {
          ExecutionContext executionContext = ExecutionContext.getContext();
          if(!(executionContext instanceof TxExecutionContext)) {
              throw new IllegalStateException("Not in a transaction execution context");
          }
  
          // @todo this lame exeception handling is all Jeremy's fault for makeing abnormalTermination take the root cause exception
          Exception exception = null;
          try {
              transactionManager.commit();
              executionContext.normalTermination();
          } catch (RollbackException e) {
              exception = e;
              throw e;
          } catch (HeuristicMixedException e) {
              exception = e;
              throw e;
          } catch (HeuristicRollbackException e) {
              exception = e;
              throw e;
          } catch (SecurityException e) {
              exception = e;
              throw e;
          } catch (IllegalStateException e) {
              exception = e;
              throw e;
          } catch (SystemException e) {
              exception = e;
              throw e;
          } finally {
              if (exception != null) {
                  executionContext.abnormalTermination(exception);
              }
          }
      }
  
      public void rollback() throws IllegalStateException, SecurityException, SystemException {
          ExecutionContext executionContext = ExecutionContext.getContext();
          if(!(executionContext instanceof TxExecutionContext)) {
              throw new IllegalStateException("Not in a transaction execution context");
          }
  
          // @todo this lame exeception handling is all Jeremy's fault for makeing abnormalTermination take the root cause exception
          Exception exception = null;
          try {
              transactionManager.rollback();
              executionContext.normalTermination();
          } catch (IllegalStateException e) {
              exception = e;
              throw e;
          } catch (SecurityException e) {
              exception = e;
              throw e;
          } catch (SystemException e) {
              exception = e;
              throw e;
          } finally {
              if (exception != null) {
                  executionContext.abnormalTermination(exception);
              }
          }
      }
  
      public void setRollbackOnly() throws IllegalStateException, SystemException {
          transactionManager.setRollbackOnly();
      }
  
      public int getStatus() throws SystemException {
          return transactionManager.getStatus();
      }
  
      public void setTransactionTimeout(int seconds) throws SystemException {
          transactionManager.setTransactionTimeout(seconds);
      }
  }
  
  
  
  1.1                  incubator-geronimo/modules/core/src/java/org/apache/geronimo/ejb/context/NoTxExecutionContext.java
  
  Index: NoTxExecutionContext.java
  ===================================================================
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2003 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Apache" and "Apache Software Foundation" and
   *    "Apache Geronimo" must not be used to endorse or promote products
   *    derived from this software without prior written permission. For
   *    written permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    "Apache Geronimo", nor may "Apache" appear in their name, without
   *    prior written permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   * ====================================================================
   */
  package org.apache.geronimo.ejb.context;
  
  import javax.transaction.Status;
  
  import org.apache.geronimo.lock.NoTxLockContext;
  
  
  /**
   *
   *
   * @version $Revision: 1.1 $ $Date: 2003/08/10 20:51:54 $
   */
  public class NoTxExecutionContext extends ExecutionContext {
      public NoTxExecutionContext() {
          super(new NoTxLockContext());
      }
  
      public void normalTermination() {
          super.normalTermination();
          try {
              runBeforeCompletion();
          } finally {
              runAfterCompletion(Status.STATUS_NO_TRANSACTION);
          }
      }
  
      public void abnormalTermination(Throwable t) {
          super.abnormalTermination(t);
          try {
              runBeforeCompletion();
          } finally {
              runAfterCompletion(Status.STATUS_NO_TRANSACTION);
          }
      }
  }
  
  
  
  1.1                  incubator-geronimo/modules/core/src/java/org/apache/geronimo/ejb/context/StatefulBMTInterceptor.java
  
  Index: StatefulBMTInterceptor.java
  ===================================================================
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2003 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Apache" and "Apache Software Foundation" and
   *    "Apache Geronimo" must not be used to endorse or promote products
   *    derived from this software without prior written permission. For
   *    written permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    "Apache Geronimo", nor may "Apache" appear in their name, without
   *    prior written permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   * ====================================================================
   */
  package org.apache.geronimo.ejb.context;
  
  import java.rmi.RemoteException;
  import java.util.HashMap;
  import java.util.Map;
  import javax.ejb.EJBException;
  import javax.transaction.Transaction;
  
  import org.apache.geronimo.ejb.EJBInvocationUtil;
  import org.apache.geronimo.common.Invocation;
  import org.apache.geronimo.common.InvocationResult;
  
  /**
   * Interceptor for Bean-Managed Transactions for Stateful Session Beans.
   * Allows a transaction that is still active when a method completes to be
   * re-associated with the invocation the next time the bean is invoked.
   *
   *
   * @version $Revision: 1.1 $ $Date: 2003/08/10 20:51:54 $
   */
  public final class StatefulBMTInterceptor extends ExecutionContextInterceptor {
      private final static Map savedTransactions = new HashMap();
  
      public InvocationResult invoke(Invocation invocation) throws Exception {
          InvocationResult result;
          Object id = EJBInvocationUtil.getId(invocation);
          // suspend any transaction supplied by the client
          Transaction oldTransaction = suspend();
          try {
              // push an outer, non-transactional context
              NoTxExecutionContext noTxContext = new NoTxExecutionContext();
              ExecutionContext.push(noTxContext);
              try {
                  resumeInstanceTx(id);
                  try {
                      result = getNext().invoke(invocation);
                  } finally {
                      suspendInstanceTx(id);
                      assert (getTransaction() == null);
                  }
              } catch (Error e) {
                  // system exception
                  ExecutionContext.pop(noTxContext);
                  noTxContext.abnormalTermination(e);
                  throw e;
              } catch (RuntimeException e) {
                  // system exception
                  ExecutionContext.pop(noTxContext);
                  noTxContext.abnormalTermination(e);
                  throw e;
              } catch (RemoteException e) {
                  // system exception
                  ExecutionContext.pop(noTxContext);
                  noTxContext.abnormalTermination(e);
                  throw e;
              } catch (Exception e) {
                  // application exception
                  ExecutionContext.pop(noTxContext);
                  noTxContext.normalTermination();
                  throw e;
              }
              ExecutionContext.pop(noTxContext);
              noTxContext.normalTermination();
              return result;
          } finally {
              if (oldTransaction != null) {
                  // resume original transaction from client
                  resume(oldTransaction);
              }
          }
      }
  
      /**
       * Locate any previous transaction for this bean
       * @param id the id of the bean
       */
      private void resumeInstanceTx(Object id) {
          TxExecutionContext txContext;
          synchronized (savedTransactions) {
              txContext = (TxExecutionContext) savedTransactions.remove(id);
          }
          if (txContext != null) {
              resume(txContext.getTransaction());
              ExecutionContext.push(txContext);
          }
      }
  
      /**
       * If the call returned with a transaction associated, then save it
       * so that it can be resumed the next time
       * @param id
       */
      private void suspendInstanceTx(Object id) {
          Transaction tx = getTransaction();
          if (tx != null) {
              TxExecutionContext context = TxExecutionContext.getContext(tx);
              if (context == null) {
                  // we have not seen this one yet, maybe they started it directly and not through UserTransaction
                  // anyway, we roll it back and error out
                  try {
                      tx.rollback();
                  } catch (Exception e) {
                      log.error("Unable to roll back transaction", e);
                  }
                  throw new EJBException("Invalid transaction");
              }
  
              ExecutionContext.pop(context);
              suspend();
              synchronized (savedTransactions) {
                  savedTransactions.put(id, context);
              }
          }
      }
  }
  
  
  
  1.1                  incubator-geronimo/modules/core/src/java/org/apache/geronimo/ejb/context/StatelessBMTInterceptor.java
  
  Index: StatelessBMTInterceptor.java
  ===================================================================
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2003 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Apache" and "Apache Software Foundation" and
   *    "Apache Geronimo" must not be used to endorse or promote products
   *    derived from this software without prior written permission. For
   *    written permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    "Apache Geronimo", nor may "Apache" appear in their name, without
   *    prior written permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   * ====================================================================
   */
  package org.apache.geronimo.ejb.context;
  
  import java.rmi.RemoteException;
  import javax.ejb.EJBException;
  import javax.transaction.Status;
  import javax.transaction.SystemException;
  import javax.transaction.Transaction;
  
  import org.apache.geronimo.common.Invocation;
  import org.apache.geronimo.common.InvocationResult;
  import org.apache.geronimo.common.InvocationType;
  import org.apache.geronimo.ejb.container.EJBPlugins;
  
  /**
   *
   *
   *
   * @version $Revision: 1.1 $ $Date: 2003/08/10 20:51:54 $
   */
  public final class StatelessBMTInterceptor extends ExecutionContextInterceptor {
      private String ejbName;
  
      public void start() throws Exception {
          super.start();
          ejbName = EJBPlugins.getEJBMetadata(getContainer()).getName();
      }
  
      public InvocationResult invoke(Invocation invocation) throws Exception {
          // suspend any transaction supplied by the client
          Transaction oldTransaction = suspend();
          InvocationResult result;
          try {
              NoTxExecutionContext noTxContext = new NoTxExecutionContext();
              ExecutionContext.push(noTxContext);
              try {
                  try {
                      result = getNext().invoke(invocation);
                  } finally {
                      checkStatelessCompletion(noTxContext, invocation);
                  }
              } catch (Error e) {
                  ExecutionContext.pop(noTxContext);
                  noTxContext.abnormalTermination(e);
                  throw e;
              } catch (RuntimeException e) {
                  ExecutionContext.pop(noTxContext);
                  noTxContext.abnormalTermination(e);
                  throw e;
              } catch (RemoteException e) {
                  ExecutionContext.pop(noTxContext);
                  noTxContext.abnormalTermination(e);
                  throw e;
              } catch (Exception e) {
                  ExecutionContext.pop(noTxContext);
                  noTxContext.normalTermination();
                  throw e;
              }
              ExecutionContext.pop(noTxContext);
              noTxContext.normalTermination();
              return result;
          } finally {
              if (oldTransaction != null) {
                  // resume original transaction from client
                  resume(oldTransaction);
              }
          }
      }
  
      /**
       * Check that there was no transaction associated when the bean returned.
       * If one was, roll it back and throw the appropriate Exception
       * @param noTxContext the outer context (used for assertion)
       * @param invocation the invocation (used to determine which interface was called)
       * @throws Exception a RemoteException or EJBException reporting the error
       */
      private void checkStatelessCompletion(ExecutionContext noTxContext, Invocation invocation) throws Exception {
          int status;
          try {
              status = tm.getStatus();
          } catch (SystemException e) {
              throw new EJBTransactionException("Unable to determine transaction status", e);
          }
  
          if (status == Status.STATUS_NO_TRANSACTION) {
              return;
          }
  
          try {
              tm.rollback();
          } catch (Exception e) {
              log.error("Unable to roll back transaction", e);
          }
  
          Exception e;
          String msg = "Stateless EJB " + ejbName + " exited with associated transaction - rolling back";
          if (InvocationType.getType(invocation).isLocalInvocation()) {
              e = new EJBException(msg);
          } else {
              e = new RemoteException(msg);
          }
  
          // pop the TxExecutionContext added when they started the transaction
          ExecutionContext context = ExecutionContext.getContext();
          if (context instanceof TxExecutionContext) {
              ExecutionContext.pop(context);
              assert (ExecutionContext.getContext() == noTxContext);
              context.abnormalTermination(e);
          }
  
          throw e;
      }
  }
  
  
  
  1.1                  incubator-geronimo/modules/core/src/java/org/apache/geronimo/ejb/context/TransactionInterceptor.java
  
  Index: TransactionInterceptor.java
  ===================================================================
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2003 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Apache" and "Apache Software Foundation" and
   *    "Apache Geronimo" must not be used to endorse or promote products
   *    derived from this software without prior written permission. For
   *    written permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    "Apache Geronimo", nor may "Apache" appear in their name, without
   *    prior written permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   * ====================================================================
   */
  package org.apache.geronimo.ejb.context;
  
  import org.apache.geronimo.common.AbstractInterceptor;
  import org.apache.geronimo.common.InvocationResult;
  import org.apache.geronimo.common.Invocation;
  import org.apache.geronimo.common.State;
  import org.apache.geronimo.common.Interceptor;
  import org.apache.geronimo.common.Container;
  import org.apache.geronimo.ejb.container.EJBPlugins;
  import org.apache.geronimo.ejb.metadata.EJBMetadata;
  
  /**
   * 
   * 
   *
   * @version $Revision: 1.1 $ $Date: 2003/08/10 20:51:54 $
   */
  public class TransactionInterceptor implements Interceptor {
      private Interceptor transactionInterceptor;
      private Container container;
      private Interceptor nextInterceptor;
  
      public State getState() {
          return transactionInterceptor.getState();
      }
  
      public final Container getContainer() {
          return container;
      }
  
      public final void setContainer(Container container) {
          this.container = container;
      }
  
      public final Interceptor getNext() {
          return nextInterceptor;
      }
  
      public final void setNext(Interceptor nextInterceptor) {
          this.nextInterceptor = nextInterceptor;
      }
  
      public void create() throws Exception {
          EJBMetadata ejbMetadata = EJBPlugins.getEJBMetadata(container);
          if(ejbMetadata.getTransactionDemarcation().isContainer()) {
              transactionInterceptor = new CMTInterceptor();
          } else {
              transactionInterceptor = new StatelessBMTInterceptor();
          }
          transactionInterceptor.setContainer(container);
          transactionInterceptor.setNext(nextInterceptor);
          transactionInterceptor.create();
      }
  
      public void start() throws Exception {
          transactionInterceptor.start();
      }
  
      public void stop() {
          transactionInterceptor.stop();
      }
  
      public void destroy() {
          transactionInterceptor.destroy();
          transactionInterceptor.setContainer(null);
          transactionInterceptor = null;
      }
  
      public InvocationResult invoke(Invocation invocation) throws Exception {
          return transactionInterceptor.invoke(invocation);
      }
  }
  
  
  
  1.1                  incubator-geronimo/modules/core/src/java/org/apache/geronimo/ejb/context/TxExecutionContext.java
  
  Index: TxExecutionContext.java
  ===================================================================
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2003 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Apache" and "Apache Software Foundation" and
   *    "Apache Geronimo" must not be used to endorse or promote products
   *    derived from this software without prior written permission. For
   *    written permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    "Apache Geronimo", nor may "Apache" appear in their name, without
   *    prior written permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   * ====================================================================
   */
  package org.apache.geronimo.ejb.context;
  
  import java.util.HashMap;
  import java.util.Map;
  import javax.transaction.NotSupportedException;
  import javax.transaction.RollbackException;
  import javax.transaction.Synchronization;
  import javax.transaction.SystemException;
  import javax.transaction.Transaction;
  import javax.transaction.TransactionManager;
  
  import org.apache.geronimo.lock.TxLockContext;
  
  /**
   *
   *
   * @version $Revision: 1.1 $ $Date: 2003/08/10 20:51:54 $
   */
  public class TxExecutionContext extends ExecutionContext implements Synchronization {
      private static final Map contextsByTx = new HashMap();
  
      private final TransactionManager tm;
      private Transaction tx;
  
      public TxExecutionContext(TransactionManager tm) {
          super(new TxLockContext());
          this.tm = tm;
      }
  
      public TxExecutionContext(TransactionManager tm, Transaction tx) throws SystemException, RollbackException {
          super(new TxLockContext());
          this.tm = tm;
          this.tx = tx;
          registerWithTransaction();
      }
  
      public static TxExecutionContext getContext(Transaction tx) {
          synchronized (contextsByTx) {
              return (TxExecutionContext) contextsByTx.get(tx);
          }
      }
  
      public Transaction getTransaction() {
          return tx;
      }
  
      public Transaction startTransaction() throws SystemException, NotSupportedException, RollbackException {
          assert (tx == null);
          tm.begin();
          tx = tm.getTransaction();
          registerWithTransaction();
          return tx;
      }
  
      private void registerWithTransaction() throws RollbackException, SystemException {
          synchronized (contextsByTx) {
              contextsByTx.put(tx, this);
              tx.registerSynchronization(this);
          }
      }
  
      public void beforeCompletion() {
          runBeforeCompletion();
      }
  
      public void afterCompletion(int status) {
          assert tx != null;
          runAfterCompletion(status);
          synchronized (contextsByTx) {
              contextsByTx.remove(tx);
          }
      }
  }
  
  
  
  1.1                  incubator-geronimo/modules/core/src/java/org/apache/geronimo/ejb/metadata/CommitOption.java
  
  Index: CommitOption.java
  ===================================================================
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2003 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Apache" and "Apache Software Foundation" and
   *    "Apache Geronimo" must not be used to endorse or promote products
   *    derived from this software without prior written permission. For
   *    written permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    "Apache Geronimo", nor may "Apache" appear in their name, without
   *    prior written permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   * ====================================================================
   */
  package org.apache.geronimo.ejb.metadata;
  
  
  /**
   *
   *
   *
   * @version $Revision: 1.1 $ $Date: 2003/08/10 20:51:54 $
   */
  public final class CommitOption {
      public static final CommitOption A = new CommitOption('A');
      public static final CommitOption B = new CommitOption('B');
      public static final CommitOption C = new CommitOption('C');
      public static final CommitOption D = new CommitOption('D');
  
      private final char option;
      private final String name;
  
      private CommitOption(char option) {
          this.option = option;
          name = "COMMIT_OPTION_" + option;
      }
  
      public String toString() {
          return name;
      }
  }
  
  
  
  1.1                  incubator-geronimo/modules/core/src/java/org/apache/geronimo/ejb/metadata/EJBMetadata.java
  
  Index: EJBMetadata.java
  ===================================================================
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2003 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Apache" and "Apache Software Foundation" and
   *    "Apache Geronimo" must not be used to endorse or promote products
   *    derived from this software without prior written permission. For
   *    written permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    "Apache Geronimo", nor may "Apache" appear in their name, without
   *    prior written permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   * ====================================================================
   */
  package org.apache.geronimo.ejb.metadata;
  
  import java.lang.reflect.Method;
  
  /**
   *
   *
   *
   * @version $Revision: 1.1 $ $Date: 2003/08/10 20:51:54 $
   */
  public interface EJBMetadata {
      String getName();
  
      ClassLoader getClassLoader();
  
      Class getBeanClass();
  
      Class getHomeInterface();
  
      Class getLocalHomeInterface();
  
      Class getRemoteInterface();
  
      Class getLocalInterface();
  
      boolean isReentrant();
  
      CommitOption getCommitOption();
  
      TransactionDemarcation getTransactionDemarcation();
  
      MethodMetadata getMethodMetadata(Method method);
  }
  
  
  
  1.1                  incubator-geronimo/modules/core/src/java/org/apache/geronimo/ejb/metadata/EJBMetadataImpl.java
  
  Index: EJBMetadataImpl.java
  ===================================================================
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2003 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Apache" and "Apache Software Foundation" and
   *    "Apache Geronimo" must not be used to endorse or promote products
   *    derived from this software without prior written permission. For
   *    written permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    "Apache Geronimo", nor may "Apache" appear in their name, without
   *    prior written permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   * ====================================================================
   */
  package org.apache.geronimo.ejb.metadata;
  
  import java.util.Map;
  import java.util.HashMap;
  import java.lang.reflect.Method;
  
  /**
   * 
   * 
   *
   * @version $Revision: 1.1 $ $Date: 2003/08/10 20:51:54 $
   */
  public final class EJBMetadataImpl implements EJBMetadata {
      private String name;
      private ClassLoader classLoader;
      private Class beanClass;
      private Class homeInterface;
      private Class remoteInterface;
      private Class localHomeInterface;
      private Class localInterface;
      private boolean reentrant;
      private CommitOption commitOption;
      private TransactionDemarcation transactionDemarcation;
      private Map methodMetadataMap = new HashMap();
  
      public String getName() {
          return name;
      }
  
      public void setName(String name) {
          this.name = name;
      }
  
      public ClassLoader getClassLoader() {
          return classLoader;
      }
  
      public void setClassLoader(ClassLoader classLoader) {
          this.classLoader = classLoader;
      }
  
      public Class getBeanClass() {
          return beanClass;
      }
  
      public void setBeanClass(Class beanClass) {
          this.beanClass = beanClass;
      }
  
      public Class getHomeInterface() {
          return homeInterface;
      }
  
      public void setHomeInterface(Class homeInterface) {
          this.homeInterface = homeInterface;
      }
  
      public Class getRemoteInterface() {
          return remoteInterface;
      }
  
      public void setRemoteInterface(Class remoteInterface) {
          this.remoteInterface = remoteInterface;
      }
  
      public Class getLocalHomeInterface() {
          return localHomeInterface;
      }
  
      public void setLocalHomeInterface(Class localHomeInterface) {
          this.localHomeInterface = localHomeInterface;
      }
  
      public Class getLocalInterface() {
          return localInterface;
      }
  
      public void setLocalInterface(Class localInterface) {
          this.localInterface = localInterface;
      }
  
      public boolean isReentrant() {
          return reentrant;
      }
  
      public void setReentrant(boolean reentrant) {
          this.reentrant = reentrant;
      }
  
      public CommitOption getCommitOption() {
          return commitOption;
      }
  
      public void setCommitOption(CommitOption commitOption) {
          this.commitOption = commitOption;
      }
  
      public TransactionDemarcation getTransactionDemarcation() {
          return transactionDemarcation;
      }
  
      public void setTransactionDemarcation(TransactionDemarcation transactionDemarcation) {
          this.transactionDemarcation = transactionDemarcation;
      }
  
      public MethodMetadata getMethodMetadata(Method method) {
          return (MethodMetadata) methodMetadataMap.get(method);
      }
  
      public void putMethodMetadata(Method method, MethodMetadata methodMetadata) {
          methodMetadataMap.put(method, methodMetadata);
      }
  }
  
  
  
  1.1                  incubator-geronimo/modules/core/src/java/org/apache/geronimo/ejb/metadata/MethodMetadata.java
  
  Index: MethodMetadata.java
  ===================================================================
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2003 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Apache" and "Apache Software Foundation" and
   *    "Apache Geronimo" must not be used to endorse or promote products
   *    derived from this software without prior written permission. For
   *    written permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    "Apache Geronimo", nor may "Apache" appear in their name, without
   *    prior written permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   * ====================================================================
   */
  package org.apache.geronimo.ejb.metadata;
  
  import java.lang.reflect.Method;
  import java.util.Set;
  
  /**
   *
   *
   *
   * @version $Revision: 1.1 $ $Date: 2003/08/10 20:51:54 $
   */
  public interface MethodMetadata {
      Method getInterfaceMethod();
      Method getCallbackMethod();
      TransactionAttribute getTransactionAttribute();
      Set getAllowedRoles();
      boolean isUnchecked();
      boolean isExcluded();
  }
  
  
  
  1.1                  incubator-geronimo/modules/core/src/java/org/apache/geronimo/ejb/metadata/MethodMetadataImpl.java
  
  Index: MethodMetadataImpl.java
  ===================================================================
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2003 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Apache" and "Apache Software Foundation" and
   *    "Apache Geronimo" must not be used to endorse or promote products
   *    derived from this software without prior written permission. For
   *    written permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    "Apache Geronimo", nor may "Apache" appear in their name, without
   *    prior written permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   * ====================================================================
   */
  package org.apache.geronimo.ejb.metadata;
  
  import java.lang.reflect.Method;
  import java.util.Set;
  
  /**
   * 
   * 
   *
   * @version $Revision: 1.1 $ $Date: 2003/08/10 20:51:54 $ 
   */
  public class MethodMetadataImpl implements MethodMetadata {
      private Method interfaceMethod;
      private Method callbackMethod;
      private TransactionAttribute transactionAttribute;
      private Set allowedRoles;
      private boolean excluded;
      private boolean unchecked;
  
      public Method getInterfaceMethod() {
          return interfaceMethod;
      }
  
      public void setInterfaceMethod(Method interfaceMethod) {
          this.interfaceMethod = interfaceMethod;
      }
  
      public Method getCallbackMethod() {
          return callbackMethod;
      }
  
      public void setCallbackMethod(Method callbackMethod) {
          this.callbackMethod = callbackMethod;
      }
  
      public TransactionAttribute getTransactionAttribute() {
          return transactionAttribute;
      }
  
      public void setTransactionAttribute(TransactionAttribute transactionAttribute) {
          this.transactionAttribute = transactionAttribute;
      }
  
      public Set getAllowedRoles() {
          return allowedRoles;
      }
  
      public void setAllowedRoles(Set allowedRoles) {
          this.allowedRoles = allowedRoles;
      }
  
      public boolean isExcluded() {
          return excluded;
      }
  
      public void setExcluded(boolean excluded) {
          this.excluded = excluded;
      }
  
      public boolean isUnchecked() {
          return unchecked;
      }
  
      public void setUnchecked(boolean unchecked) {
          this.unchecked = unchecked;
      }
  }
  
  
  
  1.1                  incubator-geronimo/modules/core/src/java/org/apache/geronimo/ejb/metadata/TransactionAttribute.java
  
  Index: TransactionAttribute.java
  ===================================================================
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2003 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Apache" and "Apache Software Foundation" and
   *    "Apache Geronimo" must not be used to endorse or promote products
   *    derived from this software without prior written permission. For
   *    written permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    "Apache Geronimo", nor may "Apache" appear in their name, without
   *    prior written permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   * ====================================================================
   */
  package org.apache.geronimo.ejb.metadata;
  
  /**
   *
   *
   *
   * @version $Revision: 1.1 $ $Date: 2003/08/10 20:51:54 $
   */
  public final class TransactionAttribute {
      public static final TransactionAttribute UNSPECIFIED = new TransactionAttribute("Unspecified");
      public static final TransactionAttribute NOT_SUPPORTED = new TransactionAttribute("NotSupported");
      public static final TransactionAttribute SUPPORTS = new TransactionAttribute("Supports");
      public static final TransactionAttribute REQUIRED = new TransactionAttribute("Required");
      public static final TransactionAttribute REQUIRES_NEW = new TransactionAttribute("RequiresNew");
      public static final TransactionAttribute MANDATORY = new TransactionAttribute("Mandatory");
      public static final TransactionAttribute NEVER = new TransactionAttribute("Never");
  
      private final String name;
  
      private TransactionAttribute(String name) {
          this.name = name;
      }
  
      public String toString() {
          return name;
      }
  }
  
  
  
  1.1                  incubator-geronimo/modules/core/src/java/org/apache/geronimo/ejb/metadata/TransactionDemarcation.java
  
  Index: TransactionDemarcation.java
  ===================================================================
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2003 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Apache" and "Apache Software Foundation" and
   *    "Apache Geronimo" must not be used to endorse or promote products
   *    derived from this software without prior written permission. For
   *    written permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    "Apache Geronimo", nor may "Apache" appear in their name, without
   *    prior written permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   * ====================================================================
   */
  package org.apache.geronimo.ejb.metadata;
  
  /**
   * 
   * 
   *
   * @version $Revision: 1.1 $ $Date: 2003/08/10 20:51:54 $
   */
  public final class TransactionDemarcation {
      public static final TransactionDemarcation CONTAINER = new TransactionDemarcation("Container Managed Transctions");
      public static final TransactionDemarcation BEAN = new TransactionDemarcation("Bean Managed Transactions");
  
      private final String name;
  
      private TransactionDemarcation(String name) {
          this.name = name;
      }
  
      public boolean isContainer() {
          return this == CONTAINER;
      }
  
      public boolean isBean() {
          return this == BEAN;
      }
  
      public String toString() {
          return name;
      }
  
  }
  
  
  

Mime
View raw message