User: starksm 
  Date: 02/04/04 11:06:27

  Modified:    src/main/org/jboss/web Tag: Branch_2_4
                        AbstractWebContainer.java
  Log:
  Add support for ejb-local-ref values to web apps.
  
  Revision  Changes    Path
  No                   revision
  
  
  No                   revision
  
  
  1.4.4.11  +115 -45   jboss/src/main/org/jboss/web/AbstractWebContainer.java
  
  Index: AbstractWebContainer.java
  ===================================================================
  RCS file: /cvsroot/jboss/jboss/src/main/org/jboss/web/AbstractWebContainer.java,v
  retrieving revision 1.4.4.10
  retrieving revision 1.4.4.11
  diff -u -r1.4.4.10 -r1.4.4.11
  --- AbstractWebContainer.java 4 Apr 2002 08:26:20 -0000       1.4.4.10
  +++ AbstractWebContainer.java 4 Apr 2002 19:06:27 -0000       1.4.4.11
  @@ -5,10 +5,12 @@
   import java.io.File;
   import java.io.FileInputStream;
   import java.io.InputStream;
  +import java.lang.reflect.Method;
   import java.net.MalformedURLException;
   import java.net.URL;
   import java.net.URLClassLoader;
   import java.util.HashMap;
  +import java.util.HashSet;
   import java.util.Iterator;
   import javax.naming.Context;
   import javax.naming.InitialContext;
  @@ -21,6 +23,7 @@
   import org.w3c.dom.Element;
   
   import org.jboss.deployment.DeploymentException;
  +import org.jboss.metadata.EjbLocalRefMetaData;
   import org.jboss.metadata.EjbRefMetaData;
   import org.jboss.metadata.EnvEntryMetaData;
   import org.jboss.metadata.ResourceEnvRefMetaData;
  @@ -121,7 +124,7 @@
   @see org.jboss.security.SecurityAssociation;
   
   @author  [EMAIL PROTECTED]
  -@version $Revision: 1.4.4.10 $
  +@version $Revision: 1.4.4.11 $
   */
   public abstract class AbstractWebContainer extends ServiceMBeanSupport implements 
AbstractWebContainerMBean
   {
  @@ -302,53 +305,56 @@
       {
       }
   
  -    /** This method is invoked from within subclass performDeploy() method
  -     implementations when they invoke WebDescriptorParser.parseWebAppDescriptors().
  +   /** This method is invoked from within subclass performDeploy() method
  +   implementations when they invoke WebDescriptorParser.parseWebAppDescriptors().
   
  -    @param loader, the ClassLoader for the web application. May not be null.
  -    @param webApp, the root element of thw web-app.xml descriptor. May not be null.
  -    @param jbossWeb, the root element of thw jboss-web.xml descriptor. May be null
  -        to indicate that no jboss-web.xml descriptor exists.
  -    */
  -    protected void parseWebAppDescriptors(ClassLoader loader, WebMetaData metaData) 
throws Exception
  -    {
  -        log.debug("AbstractWebContainer.parseWebAppDescriptors, Begin");
  +   @param loader, the ClassLoader for the web application. May not be null.
  +   @param webApp, the root element of thw web-app.xml descriptor. May not be null.
  +   @param jbossWeb, the root element of thw jboss-web.xml descriptor. May be null
  +     to indicate that no jboss-web.xml descriptor exists.
  +   */
  +   protected void parseWebAppDescriptors(ClassLoader loader, WebMetaData metaData) 
throws Exception
  +   {
  +      log.debug("AbstractWebContainer.parseWebAppDescriptors, Begin");
   
  -        InitialContext iniCtx = new InitialContext();
  -        Context envCtx = null;
  -        ClassLoader currentLoader = Thread.currentThread().getContextClassLoader();
  -        try
  -        {
  -            // Create a java:comp/env environment unique for the web application
  -            Thread.currentThread().setContextClassLoader(loader);
  -            envCtx = (Context) iniCtx.lookup("java:comp");
  -            // Add a link to the global transaction manager
  -            envCtx.bind("UserTransaction", new LinkRef("UserTransaction"));
  -            log.debug("Linking java:comp/UserTransaction to JNDI name: 
UserTransaction");
  -            envCtx = envCtx.createSubcontext("env");
  -        }
  -        finally
  -        {
  -            Thread.currentThread().setContextClassLoader(currentLoader);
  -        }
  +      InitialContext iniCtx = new InitialContext();
  +      Context envCtx = null;
  +      ClassLoader currentLoader = Thread.currentThread().getContextClassLoader();
  +      try
  +      {
  +         // Create a java:comp/env environment unique for the web application
  +         Thread.currentThread().setContextClassLoader(loader);
  +         envCtx = (Context) iniCtx.lookup("java:comp");
  +         // Add a link to the global transaction manager
  +         envCtx.bind("UserTransaction", new LinkRef("UserTransaction"));
  +         log.debug("Linking java:comp/UserTransaction to JNDI name: 
UserTransaction");
  +         envCtx = envCtx.createSubcontext("env");
  +      }
  +      finally
  +      {
  +         Thread.currentThread().setContextClassLoader(currentLoader);
  +      }
   
  -        Iterator envEntries = metaData.getEnvironmentEntries();
  -        log.debug("addEnvEntries");
  -        addEnvEntries(envEntries, envCtx);
  -        Iterator resourceEnvRefs = metaData.getResourceEnvReferences();
  -        log.debug("linkResourceEnvRefs");
  -        linkResourceEnvRefs(resourceEnvRefs, envCtx);
  -        Iterator resourceRefs = metaData.getResourceReferences();
  -        log.debug("linkResourceRefs");
  -        linkResourceRefs(resourceRefs, envCtx);
  -        Iterator ejbRefs = metaData.getEjbReferences();
  -        log.debug("linkEjbRefs");
  -        linkEjbRefs(ejbRefs, envCtx);
  -        String securityDomain = metaData.getSecurityDomain();
  -        log.debug("linkSecurityDomain");
  -        linkSecurityDomain(securityDomain, envCtx);
  -        log.debug("AbstractWebContainer.parseWebAppDescriptors, End");
  -    }
  +      Iterator envEntries = metaData.getEnvironmentEntries();
  +      log.debug("addEnvEntries");
  +      addEnvEntries(envEntries, envCtx);
  +      Iterator resourceEnvRefs = metaData.getResourceEnvReferences();
  +      log.debug("linkResourceEnvRefs");
  +      linkResourceEnvRefs(resourceEnvRefs, envCtx);
  +      Iterator resourceRefs = metaData.getResourceReferences();
  +      log.debug("linkResourceRefs");
  +      linkResourceRefs(resourceRefs, envCtx);
  +      Iterator ejbRefs = metaData.getEjbReferences();
  +      log.debug("linkEjbRefs");
  +      linkEjbRefs(ejbRefs, envCtx);
  +      Iterator ejbLocalRefs = metaData.getEjbLocalReferences();
  +      log.debug("linkEjbLocalRefs");
  +      linkEjbLocalRefs(ejbLocalRefs, envCtx);
  +      String securityDomain = metaData.getSecurityDomain();
  +      log.debug("linkSecurityDomain");
  +      linkSecurityDomain(securityDomain, envCtx);
  +      log.debug("AbstractWebContainer.parseWebAppDescriptors, End");
  +   }
   
       protected void addEnvEntries(Iterator envEntries, Context envCtx)
           throws ClassNotFoundException, NamingException
  @@ -437,6 +443,22 @@
           }
       }
   
  +   protected void linkEjbLocalRefs(Iterator ejbRefs, Context envCtx)
  +      throws NamingException
  +   {
  +      while( ejbRefs.hasNext() )
  +      {
  +         EjbLocalRefMetaData ejb = (EjbLocalRefMetaData) ejbRefs.next();
  +         String name = ejb.getName();
  +         String jndiName = ejb.getLink();
  +
  +         if( jndiName == null )
  +            throw new NamingException("ejb-local-ref: "+name+", target not found, 
add valid ejb-link");
  +         log.debug("Linking ejb-local-ref: "+name+" to JNDI name: "+jndiName);
  +         Util.bind(envCtx, name, new LinkRef(jndiName));
  +      }
  +   }
  +
       /** This creates a java:comp/env/security context that contains a
           securityMgr binding pointing to an AuthenticationManager implementation
           and a realmMapping binding pointing to a RealmMapping implementation.
  @@ -467,6 +489,54 @@
               Util.bind(envCtx, "security/subject", new 
LinkRef(securityDomain+"/subject"));
           }
       }
  +
  +   /** A utility method that walks up the ClassLoader chain starting at
  +    the given loader and queries each ClassLoader for a 'URL[] getURLs()'
  +    method from which a complete classpath of URL strings is built.
  +    */
  +   public String[] getCompileClasspath(ClassLoader loader)
  +   {
  +      HashSet tmp = new HashSet();
  +      ClassLoader cl = loader;
  +      while( cl != null )
  +      {
  +         URL[] urls = getClassLoaderURLs(cl);
  +         for(int u = 0; u < urls.length; u ++)
  +         {
  +            URL url = urls[u];
  +            tmp.add(url.toExternalForm());
  +         }
  +         cl = cl.getParent();
  +      }
  +
  +      log.trace("JSP CompileClasspath: " + tmp);
  +      String[] cp = new String[tmp.size()];
  +      tmp.toArray(cp);
  +      return cp;
  +   }
  +
  +   /** Use reflection to access a URL[] getURLs method so that non-URLClassLoader
  +    *class loaders that support this method can provide info.
  +    */
  +   private URL[] getClassLoaderURLs(ClassLoader cl)
  +   {
  +      URL[] urls = {};
  +      try
  +      {
  +         Class returnType = urls.getClass();
  +         Class[] parameterTypes = {};
  +         Method getURLs = cl.getClass().getMethod("getURLs", parameterTypes);
  +         if( returnType.isAssignableFrom(getURLs.getReturnType()) )
  +         {
  +            Object[] args = {};
  +            urls = (URL[]) getURLs.invoke(cl, args);
  +         }
  +      }
  +      catch(Exception ignore)
  +      {
  +      }
  +      return urls;
  +   }
   
      /** This method creates a context-root string from either the
         WEB-INF/jboss-web.xml context-root element is one exists, or the
  
  
  

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

Reply via email to