remm        01/03/19 17:21:07

  Modified:    catalina/src/share/org/apache/naming/factory EjbFactory.java
  Log:
  - Use the specified ejb-link to resolve the EJB reference.
  - Will do a JNDI lookup using the URL specified.
  - Will also check the type of the bean returned, and check if it implements
    the home interface specified in the reference.
  
  Revision  Changes    Path
  1.3       +27 -3     
jakarta-tomcat-4.0/catalina/src/share/org/apache/naming/factory/EjbFactory.java
  
  Index: EjbFactory.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/naming/factory/EjbFactory.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- EjbFactory.java   2001/01/23 03:43:53     1.2
  +++ EjbFactory.java   2001/03/20 01:21:05     1.3
  @@ -1,7 +1,7 @@
   /*
  - * $Header: 
/home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/naming/factory/EjbFactory.java,v
 1.2 2001/01/23 03:43:53 remm Exp $
  - * $Revision: 1.2 $
  - * $Date: 2001/01/23 03:43:53 $
  + * $Header: 
/home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/naming/factory/EjbFactory.java,v
 1.3 2001/03/20 01:21:05 remm Exp $
  + * $Revision: 1.3 $
  + * $Date: 2001/03/20 01:21:05 $
    *
    * ====================================================================
    *
  @@ -67,6 +67,7 @@
   import java.util.Hashtable;
   import javax.naming.Name;
   import javax.naming.Context;
  +import javax.naming.InitialContext;
   import javax.naming.NamingException;
   import javax.naming.Reference;
   import javax.naming.RefAddr;
  @@ -77,7 +78,7 @@
    * Object factory for EJBs.
    * 
    * @author Remy Maucherat
  - * @version $Revision: 1.2 $ $Date: 2001/01/23 03:43:53 $
  + * @version $Revision: 1.3 $ $Date: 2001/03/20 01:21:05 $
    */
   
   public class EjbFactory
  @@ -110,6 +111,27 @@
           
           if (obj instanceof EjbRef) {
               Reference ref = (Reference) obj;
  +
  +            // If ejb-link has been specified, resolving the link using JNDI
  +            RefAddr linkRefAddr = ref.get(EjbRef.LINK);
  +            if (linkRefAddr != null) {
  +                // Retrieving the EJB link
  +                String ejbLink = linkRefAddr.getContent().toString();
  +                Object beanObj = (new InitialContext()).lookup(ejbLink);
  +                // Load home interface and checking if bean correctly
  +                // implements specified home interface
  +                String homeClassName = ref.getClassName();
  +                Class home = Class.forName(homeClassName);
  +                if (home.isInstance(beanObj)) {
  +                    return beanObj;
  +                } else {
  +                    throw new NamingException
  +                        ("Bean of type " + beanObj.getClass().getName() 
  +                         + " doesn't implement home interface " 
  +                         + home.getName());
  +                }
  +            }
  +            
               ObjectFactory factory = null;
               RefAddr factoryRefAddr = ref.get(Constants.FACTORY);
               if (factoryRefAddr != null) {
  @@ -138,6 +160,7 @@
                       }
                   }
               }
  +
               // Note: No defaults here
               if (factory != null) {
                   return factory.getObjectInstance
  @@ -146,6 +169,7 @@
                   throw new NamingException
                       ("Cannot create resource instance");
               }
  +
           }
   
           return null;
  
  
  

Reply via email to