You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by re...@apache.org on 2001/01/23 23:26:54 UTC

cvs commit: jakarta-tomcat-4.0/catalina/src/share/org/apache/naming/resources DirContextURLStreamHandler.java DirContextURLStreamHandlerFactory.java

remm        01/01/23 14:26:54

  Modified:    catalina/src/share/org/apache/naming/resources
                        DirContextURLStreamHandler.java
                        DirContextURLStreamHandlerFactory.java
  Log:
  - Added classloader binding.
    Will make resolving URLs like :
    jar:jndi:/WEB-INF/lib/tld_resource.jar!/META-INF/taglib.tld
    possible.
  
  Revision  Changes    Path
  1.2       +80 -4     jakarta-tomcat-4.0/catalina/src/share/org/apache/naming/resources/DirContextURLStreamHandler.java
  
  Index: DirContextURLStreamHandler.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/naming/resources/DirContextURLStreamHandler.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- DirContextURLStreamHandler.java	2001/01/23 03:41:29	1.1
  +++ DirContextURLStreamHandler.java	2001/01/23 22:26:50	1.2
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/naming/resources/DirContextURLStreamHandler.java,v 1.1 2001/01/23 03:41:29 remm Exp $
  - * $Revision: 1.1 $
  - * $Date: 2001/01/23 03:41:29 $
  + * $Header: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/naming/resources/DirContextURLStreamHandler.java,v 1.2 2001/01/23 22:26:50 remm Exp $
  + * $Revision: 1.2 $
  + * $Date: 2001/01/23 22:26:50 $
    *
    * ====================================================================
    *
  @@ -67,6 +67,7 @@
   import java.net.URLConnection;
   import java.net.URLStreamHandler;
   import java.io.IOException;
  +import java.util.Hashtable;
   import javax.naming.NamingException;
   import javax.naming.directory.DirContext;
   
  @@ -74,7 +75,7 @@
    * Stream handler to a JNDI directory context.
    * 
    * @author <a href="mailto:remm@apache.org">Remy Maucherat</a>
  - * @version $Revision: 1.1 $
  + * @version $Revision: 1.2 $
    */
   public class DirContextURLStreamHandler 
       extends URLStreamHandler {
  @@ -83,18 +84,31 @@
       // ----------------------------------------------------------- Constructors
       
       
  +    public DirContextURLStreamHandler() {
  +    }
  +    
  +    
       public DirContextURLStreamHandler(DirContext context) {
           this.context = context;
       }
       
       
  +    // -------------------------------------------------------------- Variables
  +    
  +    
  +    /**
  +     * Bindings class loader - directory context. Keyed by CL id.
  +     */
  +    private static Hashtable clBindings = new Hashtable();
  +    
  +    
       // ----------------------------------------------------- Instance Variables
       
       
       /**
        * Directory context.
        */
  -    protected DirContext context;
  +    protected DirContext context = null;
       
       
       // ------------------------------------------------------------- Properties
  @@ -109,7 +123,69 @@
        */
       protected URLConnection openConnection(URL u) 
           throws IOException {
  -        return new DirContextURLConnection(context, u);
  +        DirContext currentContext = this.context;
  +        if (currentContext == null)
  +            currentContext = get();
  +        return new DirContextURLConnection(currentContext, u);
  +    }
  +    
  +    
  +    // --------------------------------------------------------- Public Methods
  +    
  +    
  +    /**
  +     * Binds a directory context to a class loader.
  +     */
  +    public static void bind(DirContext dirContext) {
  +        ClassLoader currentCL = 
  +            Thread.currentThread().getContextClassLoader();
  +        if (currentCL != null)
  +            clBindings.put(currentCL, dirContext);
  +    }
  +    
  +    
  +    /**
  +     * Unbinds a directory context to a class loader.
  +     */
  +    public static void unbind() {
  +        ClassLoader currentCL = 
  +            Thread.currentThread().getContextClassLoader();
  +        if (currentCL != null)
  +            clBindings.remove(currentCL);
  +    }
  +    
  +    
  +    /**
  +     * Get the bound context.
  +     */
  +    public static DirContext get() {
  +        ClassLoader currentCL = 
  +            Thread.currentThread().getContextClassLoader();
  +        return (DirContext) clBindings.get(currentCL);
  +    }
  +    
  +    
  +    /**
  +     * Binds a directory context to a class loader.
  +     */
  +    public static void bind(ClassLoader cl, DirContext dirContext) {
  +        clBindings.put(cl, dirContext);
  +    }
  +    
  +    
  +    /**
  +     * Unbinds a directory context to a class loader.
  +     */
  +    public static void unbind(ClassLoader cl) {
  +        clBindings.remove(cl);
  +    }
  +    
  +    
  +    /**
  +     * Get the bound context.
  +     */
  +    public static DirContext get(ClassLoader cl) {
  +        return (DirContext) clBindings.get(cl);
       }
       
       
  
  
  
  1.2       +5 -11     jakarta-tomcat-4.0/catalina/src/share/org/apache/naming/resources/DirContextURLStreamHandlerFactory.java
  
  Index: DirContextURLStreamHandlerFactory.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/naming/resources/DirContextURLStreamHandlerFactory.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- DirContextURLStreamHandlerFactory.java	2001/01/23 03:41:29	1.1
  +++ DirContextURLStreamHandlerFactory.java	2001/01/23 22:26:51	1.2
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/naming/resources/DirContextURLStreamHandlerFactory.java,v 1.1 2001/01/23 03:41:29 remm Exp $
  - * $Revision: 1.1 $
  - * $Date: 2001/01/23 03:41:29 $
  + * $Header: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/naming/resources/DirContextURLStreamHandlerFactory.java,v 1.2 2001/01/23 22:26:51 remm Exp $
  + * $Revision: 1.2 $
  + * $Date: 2001/01/23 22:26:51 $
    *
    * ====================================================================
    *
  @@ -63,6 +63,7 @@
   
   package org.apache.naming.resources;
   
  +import java.util.Hashtable;
   import java.net.URLStreamHandler;
   import java.net.URLStreamHandlerFactory;
   import java.io.IOException;
  @@ -73,7 +74,7 @@
    * Factory for Stream handlers to a JNDI directory context.
    * 
    * @author <a href="mailto:remm@apache.org">Remy Maucherat</a>
  - * @version $Revision: 1.1 $
  + * @version $Revision: 1.2 $
    */
   public class DirContextURLStreamHandlerFactory 
       implements URLStreamHandlerFactory {
  @@ -82,20 +83,13 @@
       // ----------------------------------------------------------- Constructors
       
       
  -    public DirContextURLStreamHandlerFactory(DirContext context) {
  -        this.context = context;
  +    public DirContextURLStreamHandlerFactory() {
       }
       
       
       // ----------------------------------------------------- Instance Variables
       
       
  -    /**
  -     * Directory context.
  -     */
  -    protected DirContext context;
  -    
  -    
       // ------------------------------------------------------------- Properties
       
       
  @@ -112,7 +106,7 @@
        */
       public URLStreamHandler createURLStreamHandler(String protocol) {
           if (protocol.equals("jndi")) {
  -            return new DirContextURLStreamHandler(context);
  +            return new DirContextURLStreamHandler();
           } else {
               return null;
           }