djencks     2004/07/07 18:17:32

  Added:       modules/core/src/java/org/openejb/dispatch
                        AbstractSpecificMethodOperation.java
                        SystemMethodIndices.java
  Log:

  A lot more work to route system lifecycle calls through a partial interceptor stack 
(OPENEJB-5).  All that is left is ejbCreate methods when called by the container (slsb 
and mdb)
  
  Revision  Changes    Path
  1.1                  
openejb/modules/core/src/java/org/openejb/dispatch/AbstractSpecificMethodOperation.java
  
  Index: AbstractSpecificMethodOperation.java
  ===================================================================
  /* ====================================================================
   * Redistribution and use of this software and associated documentation
   * ("Software"), with or without modification, are permitted provided
   * that the following conditions are met:
   *
   * 1. Redistributions of source code must retain copyright
   *    statements and notices.  Redistributions must also contain a
   *    copy of this document.
   *
   * 2. Redistributions in binary form must reproduce this list of
   *    conditions and the following disclaimer in the documentation
   *    and/or other materials provided with the distribution.
   *
   * 3. The name "OpenEJB" must not be used to endorse or promote
   *    products derived from this Software without prior written
   *    permission of The OpenEJB Group.  For written permission,
   *    please contact [EMAIL PROTECTED]
   *
   * 4. Products derived from this Software may not be called "OpenEJB"
   *    nor may "OpenEJB" appear in their names without prior written
   *    permission of The OpenEJB Group. OpenEJB is a registered
   *    trademark of The OpenEJB Group.
   *
   * 5. Due credit should be given to the OpenEJB Project
   *    (http://openejb.org/).
   *
   * THIS SOFTWARE IS PROVIDED BY THE OPENEJB GROUP AND CONTRIBUTORS
   * ``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 OPENEJB GROUP 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 OpenEJB Project.  For more information
   * please see <http://openejb.org/>.
   *
   * ====================================================================
   */
  package org.openejb.dispatch;
  
  import java.io.IOException;
  import java.io.ObjectInputStream;
  import java.io.Serializable;
  import java.lang.reflect.InvocationTargetException;
  import java.lang.reflect.Method;
  
  import javax.ejb.EnterpriseBean;
  
  import org.apache.geronimo.core.service.InvocationResult;
  import org.apache.geronimo.core.service.SimpleInvocationResult;
  
  import net.sf.cglib.reflect.FastClass;
  
  import org.openejb.EJBInstanceContext;
  import org.openejb.EJBInvocation;
  import org.openejb.EJBOperation;
  
  /**
   *
   *
   * @version $Revision: 1.1 $ $Date: 2004/07/07 22:17:32 $
   */
  public abstract class AbstractSpecificMethodOperation implements VirtualOperation, 
Serializable {
  
      protected InvocationResult invoke(EJBInvocation invocation, EJBOperation 
operation) throws Throwable {
          EJBInstanceContext ctx = invocation.getEJBInstanceContext();
          try {
              ctx.setOperation(operation);
              try {
                  return new SimpleInvocationResult(true, 
doOperation(ctx.getInstance(), invocation.getArguments()));
              } catch (Throwable t) {
                  if (t instanceof Exception && t instanceof RuntimeException == 
false) {
                      // checked exception - which we simply include in the result
                      return new SimpleInvocationResult(false, t);
                  } else {
                      // unchecked Exception - just throw it to indicate an abnormal 
completion
                      throw t;
                  }
              }
          } finally {
              ctx.setOperation(EJBOperation.INACTIVE);
          }
      }
  
      protected abstract Object doOperation(EnterpriseBean instance, Object[] 
arguments) throws Throwable;
  
  }
  
  
  
  1.1                  
openejb/modules/core/src/java/org/openejb/dispatch/SystemMethodIndices.java
  
  Index: SystemMethodIndices.java
  ===================================================================
  /* ====================================================================
   * Redistribution and use of this software and associated documentation
   * ("Software"), with or without modification, are permitted provided
   * that the following conditions are met:
   *
   * 1. Redistributions of source code must retain copyright
   *    statements and notices.  Redistributions must also contain a
   *    copy of this document.
   *
   * 2. Redistributions in binary form must reproduce this list of
   *    conditions and the following disclaimer in the documentation
   *    and/or other materials provided with the distribution.
   *
   * 3. The name "OpenEJB" must not be used to endorse or promote
   *    products derived from this Software without prior written
   *    permission of The OpenEJB Group.  For written permission,
   *    please contact [EMAIL PROTECTED]
   *
   * 4. Products derived from this Software may not be called "OpenEJB"
   *    nor may "OpenEJB" appear in their names without prior written
   *    permission of The OpenEJB Group. OpenEJB is a registered
   *    trademark of The OpenEJB Group.
   *
   * 5. Due credit should be given to the OpenEJB Project
   *    (http://openejb.org/).
   *
   * THIS SOFTWARE IS PROVIDED BY THE OPENEJB GROUP AND CONTRIBUTORS
   * ``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 OPENEJB GROUP 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 OpenEJB Project.  For more information
   * please see <http://openejb.org/>.
   *
   * ====================================================================
   */
  package org.openejb.dispatch;
  
  import org.openejb.EJBInstanceContext;
  import org.openejb.EJBInvocation;
  import org.openejb.EJBInvocationImpl;
  
  /**
   *
   *
   * @version $Revision: 1.1 $ $Date: 2004/07/07 22:17:32 $
   *
   * */
  public final class SystemMethodIndices {
  
      private final int ejbActivate;
      private final int ejbLoad;
      private final int ejbPassivate;
      private final int ejbStore;
      private final int setContext;
      private final int unsetContext;
  
      public static SystemMethodIndices 
createSystemMethodIndices(InterfaceMethodSignature[] signatures, String 
setContextName, String setContextType, String unsetContextName) {
          int ejbActivate = -1;
          int ejbLoad = -1;
          int ejbPassivate = -1;
          int ejbStore = -1;
          int setContext = -1;
          int unsetContext = -1;
          for (int i = 0; i < signatures.length; i++) {
              InterfaceMethodSignature signature = signatures[i];
              if (signature.getMethodName().equals("ejbActivate")) {
                   ejbActivate = i;
              } else if (signature.getMethodName().equals("ejbLoad")) {
                   ejbLoad = i;
              } else if (signature.getMethodName().equals("ejbPassivate")) {
                   ejbPassivate = i;
              } else if (signature.getMethodName().equals("ejbStore")) {
                   ejbStore = i;
              } else if (signature.getMethodName().equals(setContextName) && 
signature.getParameterTypes().length == 1 && 
signature.getParameterTypes()[0].equals(setContextType)) {
                   setContext = i;
              } else if (signature.getMethodName().equals(unsetContextName) && 
signature.getParameterTypes().length == 0) {
                   unsetContext = i;
              }
          }
          return new SystemMethodIndices(ejbActivate, ejbLoad, ejbPassivate, ejbStore, 
setContext, unsetContext);
      }
  
      public SystemMethodIndices(int ejbActivate, int ejbLoad, int ejbPassivate, int 
ejbStore, int setContext, int unsetContext) {
          this.ejbActivate = ejbActivate;
          this.ejbLoad = ejbLoad;
          this.ejbPassivate = ejbPassivate;
          this.ejbStore = ejbStore;
          this.setContext = setContext;
          this.unsetContext = unsetContext;
      }
  
      public EJBInvocation getEjbActivateInvocation(EJBInstanceContext 
instanceContext) {
          return new EJBInvocationImpl(ejbActivate, null, instanceContext);
      }
  
      public EJBInvocation getEjbLoadInvocation(EJBInstanceContext instanceContext) {
          return new EJBInvocationImpl(ejbLoad, null, instanceContext);
      }
  
      public EJBInvocation getEjbPassivateInvocation(EJBInstanceContext 
instanceContext) {
          return new EJBInvocationImpl(ejbPassivate, null, instanceContext);
      }
  
      public EJBInvocation getEjbStoreInvocation(EJBInstanceContext instanceContext) {
          return new EJBInvocationImpl(ejbStore, null, instanceContext);
      }
  
      public EJBInvocation getSetContextInvocation(EJBInstanceContext instanceContext, 
Object context) {
          return new EJBInvocationImpl(setContext, new Object[] {context}, 
instanceContext);
      }
  
      public EJBInvocation getUnsetContextInvocation(EJBInstanceContext 
instanceContext) {
          return new EJBInvocationImpl(unsetContext, null, instanceContext);
      }
  
  }
  
  
  

Reply via email to