User: docodan 
  Date: 01/06/03 10:11:03

  Modified:    src/main/org/jboss/ejb/plugins/local
                        BaseLocalContainerInvoker.java LocalProxy.java
  Added:       src/main/org/jboss/ejb/plugins/local LocalHomeProxy.java
  Log:
  Added home local proxy (already had component local proxy).
  
  Revision  Changes    Path
  1.2       +82 -7     
jboss/src/main/org/jboss/ejb/plugins/local/BaseLocalContainerInvoker.java
  
  Index: BaseLocalContainerInvoker.java
  ===================================================================
  RCS file: 
/cvsroot/jboss/jboss/src/main/org/jboss/ejb/plugins/local/BaseLocalContainerInvoker.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- BaseLocalContainerInvoker.java    2001/06/03 16:28:48     1.1
  +++ BaseLocalContainerInvoker.java    2001/06/03 17:11:02     1.2
  @@ -136,7 +136,10 @@
      // ContainerInvoker implementation -------------------------------
      public EJBLocalHome getEJBLocalHome()
      {
  -      throw new UnsupportedOperationException();
  +      ContainerInvokerContainer cic = (ContainerInvokerContainer) container;
  +      return (EJBLocalHome) Proxy.newProxyInstance( 
  +         cic.getLocalHomeClass().getClassLoader(),
  +         new Class[]{cic.getLocalHomeClass()}, new HomeProxy() );
      }
   
      public EJBLocalObject getStatelessSessionEJBLocalObject()
  @@ -177,8 +180,7 @@
      /**
       *  Invoke a Home interface method.
       */
  -   public Object invokeHome(Method m, Object[] args, Transaction tx,
  -      Principal identity, Object credential)
  +   public Object invokeHome(Method m, Object[] args)
      throws Exception
      {
         // Set the right context classloader
  @@ -187,8 +189,8 @@
   
         try
         {
  -         return container.invokeHome(new MethodInvocation(null, m, args, tx,
  -            identity, credential));
  +         return container.invokeHome(new MethodInvocation(null, m, args, 
  +            getTransaction(), getPrincipal(), getCredential()));
         } finally
         {
            Thread.currentThread().setContextClassLoader(oldCl);
  @@ -242,6 +244,47 @@
            Thread.currentThread().setContextClassLoader(oldCl);
         }
      }
  +   
  +    
  +   class HomeProxy extends LocalHomeProxy
  +      implements InvocationHandler
  +   {
  +       protected String getJndiName()
  +       {
  +           return jndiName;
  +       }
  +       
  +       protected Object getId()
  +       {
  +           return jndiName;
  +       }
  +
  +       public final Object invoke(final Object proxy,
  +                               final Method m,
  +                               Object[] args)
  +        throws Throwable
  +       {
  +          if (args == null)
  +              args = EMPTY_ARGS;
  +          
  +          Object retValue = super.invoke( proxy, m, args );
  +          if (retValue != null)
  +             return retValue;
  +          
  +        else if (m.equals(REMOVE_BY_PRIMARY_KEY)) {
  +            // The trick is simple we trick the container in believe it
  +            // is a remove() on the instance
  +            Object id = new CacheKey(args[0]);
  +            return BaseLocalContainerInvoker.this.invoke(
  +               id, REMOVE_OBJECT, EMPTY_ARGS);
  +        }
  +          // If not taken care of, go on and call the container
  +          else {
  +              return BaseLocalContainerInvoker.this.invokeHome(
  +               m, args);
  +          }
  +       }
  +   }
   
      class EntityProxy extends LocalProxy 
         implements InvocationHandler
  @@ -255,6 +298,17 @@
            cacheKey = (CacheKey) id;
         }
         
  +       protected String getJndiName()
  +       {
  +           return jndiName;
  +       }
  +       
  +       protected Object getId()
  +       {
  +           return cacheKey.id;
  +       }
  +      
  +      
         public final Object invoke(final Object proxy,
                                  final Method m,
                                  Object[] args)
  @@ -263,7 +317,7 @@
             if (args == null)
                 args = EMPTY_ARGS;
             
  -          Object retValue = super.invoke( proxy, m, args, jndiName, cacheKey.id );
  +          Object retValue = super.invoke( proxy, m, args );
             if (retValue != null)
                return retValue;
             // If not taken care of, go on and call the container
  @@ -284,6 +338,16 @@
         {
            this.id = id;
         }
  +
  +       protected String getJndiName()
  +       {
  +           return jndiName;
  +       }
  +       
  +       protected Object getId()
  +       {
  +           return id;
  +       }  
         
         public final Object invoke(final Object proxy,
                                  final Method m,
  @@ -293,7 +357,7 @@
             if (args == null)
                 args = EMPTY_ARGS;
             
  -          Object retValue = super.invoke( proxy, m, args, jndiName, id );
  +          Object retValue = super.invoke( proxy, m, args );
             if (retValue != null)
                return retValue;
             // If not taken care of, go on and call the container
  @@ -307,6 +371,17 @@
      class StatelessSessionProxy extends LocalProxy 
         implements InvocationHandler
      {
  +       protected String getJndiName()
  +       {
  +           return jndiName;
  +       }
  +       
  +       protected Object getId()
  +       {
  +           return jndiName;
  +       }
  +      
  +      
         public final Object invoke(final Object proxy,
                                  final Method m,
                                  Object[] args)
  
  
  
  1.2       +9 -5      jboss/src/main/org/jboss/ejb/plugins/local/LocalProxy.java
  
  Index: LocalProxy.java
  ===================================================================
  RCS file: /cvsroot/jboss/jboss/src/main/org/jboss/ejb/plugins/local/LocalProxy.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- LocalProxy.java   2001/06/03 16:28:48     1.1
  +++ LocalProxy.java   2001/06/03 17:11:02     1.2
  @@ -59,6 +59,9 @@
   
       /** {@link EJBObject#isIdentical} method reference. */
       protected static final Method IS_IDENTICAL;
  +    
  +    protected abstract String getJndiName();
  +    protected abstract Object getId();
   
       /**
        * Initialize {@link EJBObject} method references.
  @@ -113,19 +116,20 @@
           return new Boolean(pk.equals(b));
       }
   
  -      public final Object invoke(final Object proxy,
  +      public Object invoke(final Object proxy,
                                  final Method m,
  -                               Object[] args,
  -                               String jndiName,
  -                               Object id)
  +                               Object[] args)
           throws Throwable
          {
  +          Object id = getId();
  +          String jndiName = getJndiName();
  +          
             // Implement local methods
             if (m.equals(TO_STRING)) {
                 return jndiName + ":" + id.toString();
             }
             else if (m.equals(EQUALS)) {
  -              return invoke(proxy, IS_IDENTICAL, args, jndiName, id );
  +              return invoke(proxy, IS_IDENTICAL, args );
             }
             else if (m.equals(HASH_CODE)) {
               return new Integer(id.hashCode());
  
  
  
  1.1                  jboss/src/main/org/jboss/ejb/plugins/local/LocalHomeProxy.java
  
  Index: LocalHomeProxy.java
  ===================================================================
  /*
   * JBoss, the OpenSource EJB server
   *
   * Distributable under LGPL license.
   * See terms of license at gnu.org.
   */
  package org.jboss.ejb.plugins.local;
  
  
  import java.lang.reflect.Method;
  import java.rmi.MarshalledObject;
  
  import javax.naming.Name;
  
  import javax.ejb.EJBLocalHome;
  import javax.ejb.EJBLocalObject;
  import javax.ejb.Handle;
  import javax.ejb.HomeHandle;
  import javax.ejb.EJBMetaData;
  
  import org.jboss.ejb.CacheKey;
  
  /**
   * The client-side proxy for an EJB Home object.
   *      
   * @author  Daniel OConnor ([EMAIL PROTECTED])
   */
  public abstract class LocalHomeProxy
      extends LocalProxy
  {
      
      // Static --------------------------------------------------------
  
      /** {@link EJBHome#remove(Object)} method reference. */
      protected static final Method REMOVE_BY_PRIMARY_KEY;
  
      /** {@link EJBObject#remove} method reference. */
      protected static final Method REMOVE_OBJECT;
      
      /**
       * Initialize {@link EJBHome} and {@link EJBObject} method references.
       */
      static {
          try {
              final Class empty[] = {};
              final Class type = EJBLocalHome.class;
  
              REMOVE_BY_PRIMARY_KEY = type.getMethod("remove", new Class[] { 
                  Object.class 
              });
  
              // Get the "remove" method from the EJBObject
              REMOVE_OBJECT = EJBLocalObject.class.getMethod("remove", empty);
          }
          catch (Exception e) {
              e.printStackTrace();
              throw new ExceptionInInitializerError(e);            
          }
      }
      
      
      /**
       * InvocationHandler implementation.
       *
       * @param proxy   The proxy object.
       * @param m       The method being invoked.
       * @param args    The arguments for the method.
       *
       * @throws Throwable    Any exception or error thrown while processing.
       */
      public Object invoke(final Object proxy,
                           final Method m,
                           Object[] args)
          throws Throwable
      {       
         String jndiName = getJndiName();
          // Implement local methods
          if (m.equals(TO_STRING)) {
              return jndiName + "Home";
          }
          else if (m.equals(EQUALS)) {
              // equality of the proxy home is based on names...
              Object temp = invoke(proxy, TO_STRING, args);
              return new Boolean(temp.equals(jndiName + "Home"));
          }
          else if (m.equals(HASH_CODE)) {
              return new Integer(this.hashCode());
          }
          
          // Implement local EJB calls
         return null;
      }
  }
  
  
  
  

_______________________________________________
Jboss-development mailing list
[EMAIL PROTECTED]
http://lists.sourceforge.net/lists/listinfo/jboss-development

Reply via email to