User: docodan 
  Date: 01/06/03 13:59:40

  Modified:    src/main/org/jboss/ejb Application.java Container.java
  Added:       src/main/org/jboss/ejb LocalHomeObjectFactory.java
  Log:
  Code to bind home interfaces to local bean references
  
  Revision  Changes    Path
  1.10      +6 -1      jboss/src/main/org/jboss/ejb/Application.java
  
  Index: Application.java
  ===================================================================
  RCS file: /cvsroot/jboss/jboss/src/main/org/jboss/ejb/Application.java,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- Application.java  2001/06/03 18:48:12     1.9
  +++ Application.java  2001/06/03 20:59:40     1.10
  @@ -22,7 +22,7 @@
    *   @see Container
    *   @see ContainerFactory
    *   @author Rickard �berg ([EMAIL PROTECTED])
  - *   @version $Revision: 1.9 $
  + *   @version $Revision: 1.10 $
    */
   public class Application
        implements Service
  @@ -79,6 +79,11 @@
      public void removeLocalHome( Container con )
      {
         localHomes.remove( con.getBeanMetaData().getEjbName() );
  +   }
  +   
  +   public EJBLocalHome getLocalHome( Container con )
  +   {
  +      return (EJBLocalHome) localHomes.get( con.getBeanMetaData().getEjbName() );
      }
      
   
  
  
  
  1.42      +37 -1     jboss/src/main/org/jboss/ejb/Container.java
  
  Index: Container.java
  ===================================================================
  RCS file: /cvsroot/jboss/jboss/src/main/org/jboss/ejb/Container.java,v
  retrieving revision 1.41
  retrieving revision 1.42
  diff -u -r1.41 -r1.42
  --- Container.java    2001/06/03 19:28:36     1.41
  +++ Container.java    2001/06/03 20:59:40     1.42
  @@ -33,6 +33,7 @@
   import javax.naming.NamingEnumeration;
   import javax.naming.NameClassPair;
   import javax.naming.NamingException;
  +import javax.naming.StringRefAddr;
   import javax.naming.RefAddr;
   import javax.naming.NameNotFoundException;
   import javax.naming.spi.ObjectFactory;
  @@ -46,6 +47,7 @@
   import org.jboss.metadata.BeanMetaData;
   import org.jboss.metadata.EnvEntryMetaData;
   import org.jboss.metadata.EjbRefMetaData;
  +import org.jboss.metadata.EjbLocalRefMetaData;
   import org.jboss.metadata.ResourceRefMetaData;
   import org.jboss.metadata.ApplicationMetaData;
   
  @@ -69,7 +71,7 @@
    *   @see ContainerFactory
    *   @author Rickard �berg ([EMAIL PROTECTED])
    *   @author <a href="[EMAIL PROTECTED]">Marc Fleury</a>
  - *   @version $Revision: 1.41 $
  + *   @version $Revision: 1.42 $
    */
   public abstract class Container
   {
  @@ -488,6 +490,40 @@
               }
            }
           
  +         // Bind Local EJB references
  +         {
  +            Iterator enum = getBeanMetaData().getEjbLocalReferences();
  +            // unique key name
  +            String uniqueKey = Long.toString( (new java.util.Date()).getTime() );
  +            while(enum.hasNext())
  +            {
  +
  +               EjbLocalRefMetaData ref = (EjbLocalRefMetaData)enum.next();
  +               Logger.debug("Binding an EJBLocalReference "+ref.getName());
  +
  +               if (ref.getLink() != null)
  +               {
  +                  // Internal link
  +                  Logger.debug("Binding "+ref.getName()+" to bean source: 
"+ref.getLink());
  +                  if (getApplication().getContainer(ref.getLink()) == null)
  +                     throw new DeploymentException ("Bean "+ref.getLink()+" not 
found within this application.");
  +                  // get local home
  +                  // bind it into the local namespace
  +                  LocalHomeObjectFactory.rebind( uniqueKey + ref.getName(), 
  +                     getApplication(), getApplication().getContainer(ref.getLink()) 
);
  +                  StringRefAddr refAddr = new StringRefAddr("nns", 
uniqueKey+ref.getName() );
  +                  Reference jndiRef = new Reference(ref.getLocalHome(),
  +                     refAddr, LocalHomeObjectFactory.class.getName(), null );
  +                  bind(ctx, ref.getName(), jndiRef );
  +
  +               }
  +               else
  +               {
  +                  throw new DeploymentException( "Local references currently 
require ejb-link" );
  +               }
  +            }
  +         }
  +
            // Bind resource references
            {
               Iterator enum = getBeanMetaData().getResourceReferences();
  
  
  
  1.1                  jboss/src/main/org/jboss/ejb/LocalHomeObjectFactory.java
  
  Index: LocalHomeObjectFactory.java
  ===================================================================
  /*
   * JBoss, the OpenSource EJB server
   *
   * Distributable under LGPL license.
   * See terms of license at gnu.org.
   */
  package org.jboss.ejb;
  
  import java.util.Collections;
  import java.util.HashMap;
  import java.util.Hashtable;
  import java.util.Map;
  import javax.naming.Context;
  import javax.naming.Name;
  import javax.naming.NameAlreadyBoundException;
  import javax.naming.NameNotFoundException;
  import javax.naming.NamingException;
  import javax.naming.Reference;
  import javax.naming.RefAddr;
  import javax.naming.StringRefAddr;
  import javax.naming.spi.ObjectFactory;
  
  /** Based on Scott Stark's NonSerializableObjectFactory:
   *
   *  @author [EMAIL PROTECTED]
   *  @author Daniel OConnor ([EMAIL PROTECTED]
   */
  public class LocalHomeObjectFactory implements ObjectFactory
  {
      private static Map applicationMap = Collections.synchronizedMap(new HashMap());
      private static Map containerMap = Collections.synchronizedMap(new HashMap());
  
  
      /** Place an object into the NonSerializableFactory namespace for subsequent
      access by getObject.
  
      @param key, the name to bind target under. This should typically be the
      name that will be used to bind target in the JNDI namespace, but it does
      not have to be.
      @param target, the non-Serializable object to bind.
      */
      public static synchronized void rebind(String key, Application application,
        Container container )
      {
          applicationMap.put(key, application);
          containerMap.put( key, container ); 
      }
      /** Place or replace an object in the NonSerializableFactory namespce
       for subsequent access by getObject. Any existing binding for key will be
       replaced by target.
  
      /** Remove a binding from the NonSerializableFactory map.
  
      @param key, the key into the NonSerializableFactory map to remove.
      @param target, the non-Serializable object to bind.
      @throws NameNotFoundException, thrown if key does not exist in the
       NonSerializableFactory map
      */
      public static void unbind(String key) throws NameNotFoundException
      {
          if( applicationMap.remove(key) == null )
              throw new NameNotFoundException(key+" was not found in the 
NonSerializableFactory map");
          containerMap.remove(key);
      }
  
      /** Lookup a value from the NonSerializableFactory map.
      @return the object bound to key is one exists, null otherwise.
      */
      public static Object lookup(String key)
      {
          Application app = (Application) applicationMap.get(key);
          Container container = (Container) containerMap.get(key);
          return app.getLocalHome( container );
      }
  
  
      /** Transform the obj Reference bound into the JNDI namespace into the
      actual non-Serializable object.
  
      @param obj, the object bound in the JNDI namespace. This must be an 
implementation
      of javax.naming.Reference with a javax.naming.RefAddr of type "nns" whose
      content is the String key used to location the non-Serializable object in the 
      NonSerializableFactory map.
      @param name, ignored.
      @param nameCtx, ignored.
      @param env, ignored.
  
      @return the non-Serializable object associated with the obj Reference if one
      exists, null if one does not.
      */
      public Object getObjectInstance(Object obj, Name name, Context nameCtx, 
Hashtable env)
          throws Exception
      { // Get the nns value from the Reference obj and use it as the map key
          Reference ref = (Reference) obj;
          RefAddr addr = ref.get("nns");
          String key = (String) addr.getContent();
          Object target = lookup(key);
          return target;
      }
  // --- End ObjectFactory interface methods
  }
  
  
  
  

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

Reply via email to