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

cvs commit: jakarta-tomcat/src/share/org/apache/tomcat/loader AdaptiveClassLoader.java AdaptiveClassLoader12.java

marcsaeg    01/07/23 14:49:08

  Modified:    src/share/org/apache/tomcat/loader Tag: tomcat_32
                        AdaptiveClassLoader.java AdaptiveClassLoader12.java
  Log:
  Added findResource() and findResources() per the JDk 1.2 class loader.
  These methods only appear in AdaptiveClassLoader12 as they are only
  supported in the 1.2 JDK.  The actual implementation of these methods
  resides in AdaptiveClassLoader to avoid duplicating code.
  
  Obtained from:  David Haraburda [david@haraburda.com]
  
  Revision  Changes    Path
  No                   revision
  
  
  No                   revision
  
  
  1.9.2.4   +81 -61    jakarta-tomcat/src/share/org/apache/tomcat/loader/Attic/AdaptiveClassLoader.java
  
  Index: AdaptiveClassLoader.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/loader/Attic/AdaptiveClassLoader.java,v
  retrieving revision 1.9.2.3
  retrieving revision 1.9.2.4
  diff -u -r1.9.2.3 -r1.9.2.4
  --- AdaptiveClassLoader.java	2001/03/04 03:47:58	1.9.2.3
  +++ AdaptiveClassLoader.java	2001/07/23 21:49:08	1.9.2.4
  @@ -15,24 +15,24 @@
    *
    * 3. All advertising materials mentioning features or use of this
    *    software must display the following acknowledgment:
  - *    "This product includes software developed by the Java Apache 
  + *    "This product includes software developed by the Java Apache
    *    Project for use in the Apache JServ servlet engine project
    *    <http://java.apache.org/>."
    *
  - * 4. The names "Apache JServ", "Apache JServ Servlet Engine" and 
  - *    "Java Apache Project" must not be used to endorse or promote products 
  + * 4. The names "Apache JServ", "Apache JServ Servlet Engine" and
  + *    "Java Apache Project" must not be used to endorse or promote products
    *    derived from this software without prior written permission.
    *
    * 5. Products derived from this software may not be called "Apache JServ"
  - *    nor may "Apache" nor "Apache JServ" appear in their names without 
  + *    nor may "Apache" nor "Apache JServ" appear in their names without
    *    prior written permission of the Java Apache Project.
    *
    * 6. Redistributions of any form whatsoever must retain the following
    *    acknowledgment:
  - *    "This product includes software developed by the Java Apache 
  + *    "This product includes software developed by the Java Apache
    *    Project for use in the Apache JServ servlet engine project
    *    <http://java.apache.org/>."
  - *    
  + *
    * THIS SOFTWARE IS PROVIDED BY THE JAVA APACHE PROJECT "AS IS" AND ANY
    * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
    * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  @@ -118,12 +118,12 @@
    * @author Martin Pool
    * @author Jim Heintz
    * @author <a href="mailto:stefano@apache.org">Stefano Mazzocchi</a>
  - * @version $Revision: 1.9.2.3 $ $Date: 2001/03/04 03:47:58 $
  + * @version $Revision: 1.9.2.4 $ $Date: 2001/07/23 21:49:08 $
    * @see java.lang.ClassLoader
    */
   public class AdaptiveClassLoader extends ClassLoader {
       private static final int debug=0;
  -    
  +
       /**
        * Instance of the SecurityManager installed.
        */
  @@ -163,7 +163,7 @@
        * compatibility, we'll duplicate the 1.2 private member var.
        */
       protected ClassLoader parent;
  -    
  +
       /**
        * Private class used to maintain information about the classes that
        * we loaded.
  @@ -194,7 +194,7 @@
               return origin == null;
           }
       }
  -    
  +
       //------------------------------------------------------- Constructors
   
       /**
  @@ -215,7 +215,7 @@
   	cache = new Hashtable();
       }
   
  -    public void setRepository( Vector classRepository ) 
  +    public void setRepository( Vector classRepository )
   	throws IllegalArgumentException
       {
   	// Verify that all the repository are valid.
  @@ -275,7 +275,7 @@
       void log( String s ) {
   	System.out.println("AdaptiveClassLoader: " + s );
       }
  -    
  +
       //------------------------------------------------------- Methods
   
       /**
  @@ -326,7 +326,7 @@
               return false;
           } else {
               return (entry.origin.lastModified() != entry.lastModified);
  -        
  +
           }
       }
   
  @@ -348,7 +348,7 @@
   	    if( debug>5 )
   		log( "cache entry: " + entry.loadedClass.getName());
   	    if (entry.isSystemClass()) continue;
  -	    
  +
               // XXX: Because we want the classloader to be an accurate
               // reflection of the contents of the repository, we also
               // reload if a class origin file is now missing.  This
  @@ -381,7 +381,7 @@
        */
       public AdaptiveClassLoader reinstantiate() {
           AdaptiveClassLoader cl=new AdaptiveClassLoader();
  -	cl.setParent(parent); 
  +	cl.setParent(parent);
   	cl.setRepository(repository);
   	return cl;
       }
  @@ -435,7 +435,7 @@
           if (sm != null) {
               int i = name.lastIndexOf('.');
               if (i >= 0) {
  -                sm.checkPackageAccess(name.substring(0,i)); 
  +                sm.checkPackageAccess(name.substring(0,i));
                   sm.checkPackageDefinition(name.substring(0,i));
   	    }
   	}
  @@ -502,10 +502,10 @@
                   classCache.lastModified = classCache.origin.lastModified();
   		if( debug>0) log( "Add to cache() " + name + " " + classCache);
   		cache.put(name, classCache);
  -		
  +
   		if( debug>0) log( "Before define class " + name);
   		try {
  -		    classCache.loadedClass = 
  +		    classCache.loadedClass =
   			doDefineClass(name, classData,
   				      cp.getProtectionDomain());
   		} catch(Throwable t ) {
  @@ -529,7 +529,7 @@
       {
   	return  defineClass(name, classData, 0, classData.length);
       }
  -    
  +
       /**
        * Load a class using the system classloader.
        *
  @@ -782,54 +782,74 @@
           }
   
           // Third, check our own repositories
  -        Enumeration repEnum = repository.elements();
  -        while (repEnum.hasMoreElements()) {
  -            ClassRepository cp = (ClassRepository) repEnum.nextElement();
  -            File file = cp.getFile();
  -            // Construct a file://-URL if the repository is a directory
  -            if (file.isDirectory()) {
  -                String fileName = name.replace('/', File.separatorChar);
  -                File resFile = new File(file, fileName);
  -                if (resFile.exists()) {
  -                    // Build a file:// URL form the file name
  -                    try {
  -                        return new URL("file", null, resFile.getAbsolutePath());                    	
  -                    } catch(java.net.MalformedURLException badurl) {
  -                        badurl.printStackTrace();
  -                        return null;
  -                    }
  -                }
  -            }
  -            else {
  -                // a jar:-URL *could* change even between minor releases, but
  -                // didn't between JVM's 1.1.6 and 1.3beta. Tested on JVM's from
  -                // IBM, Blackdown, Microsoft, Sun @ Windows and Sun @ Solaris
  -                try {
  -                    ZipFile zf = new ZipFile(file.getAbsolutePath());
  -                    ZipEntry ze = zf.getEntry(name);
  -                    zf.close();
  -
  -                    if (ze != null) {
  -                        try {
  -                            return new URL("jar:file:" + file.getAbsolutePath() + "!/" + name);
  -                        } catch(java.net.MalformedURLException badurl) {
  -                            badurl.printStackTrace();
  -                            return null;
  -                        }
  -                    }
  -                } catch (IOException ioe) {
  -                    ioe.printStackTrace();
  -                    return null;
  -                }
  -            }   
  +        u = findResourceInternal(name);
  +        if ( u != null ) {
  +            return u;
           }
  -
           // Not found
           return null;
       }
   
  +    protected URL findResourceInternal(String name) {
  +      try {
  +        return (URL) findResourcesInternal(name, true).elementAt(0);
  +      } catch( IOException e ) {
  +        return null;
  +      } catch(ArrayIndexOutOfBoundsException e){
  +          return null;
  +      }
  +    }
  +
  +    protected Vector findResourcesInternal(String name, boolean justOne) throws IOException {
  +      Vector urls = new Vector( repository.size() );
  +      Enumeration repEnum = repository.elements();
  +      while (repEnum.hasMoreElements()) {
  +          ClassRepository cp = (ClassRepository) repEnum.nextElement();
  +          File file = cp.getFile();
  +          // Construct a file://-URL if the repository is a directory
  +          if (file.isDirectory()) {
  +              String fileName = name.replace('/', File.separatorChar);
  +              File resFile = new File(file, fileName);
  +              if (resFile.exists()) {
  +                  // Build a file:// URL form the file name
  +                  try {
  +                      urls.add( new URL("file", null, resFile.getAbsolutePath()) );
  +                      if(justOne) return urls;
  +                  } catch(java.net.MalformedURLException badurl) {
  +                      badurl.printStackTrace();
  +                      return null;
  +                  }
  +              }
  +          }
  +          else {
  +              // a jar:-URL *could* change even between minor releases, but
  +              // didn't between JVM's 1.1.6 and 1.3beta. Tested on JVM's from
  +              // IBM, Blackdown, Microsoft, Sun @ Windows and Sun @ Solaris
  +              try {
  +                  ZipFile zf = new ZipFile(file.getAbsolutePath());
  +                  ZipEntry ze = zf.getEntry(name);
  +                  zf.close();
  +
  +                  if (ze != null) {
  +                      try {
  +                          urls.add( new URL("jar:file:" + file.getAbsolutePath() + "!/" + name) );
  +                          if(justOne) return urls;
  +                      } catch(java.net.MalformedURLException badurl) {
  +                          badurl.printStackTrace();
  +                          return null;
  +                      }
  +                  }
  +              } catch (IOException ioe) {
  +                  ioe.printStackTrace();
  +                  return null;
  +              }
  +          }
  +      }
  +      return urls;
  +    }
  +
       public String toString() {
   	return "AdaptiveClassLoader(  )";
       }
   
  -}
  +}
  \ No newline at end of file
  
  
  
  1.3.2.1   +10 -0     jakarta-tomcat/src/share/org/apache/tomcat/loader/Attic/AdaptiveClassLoader12.java
  
  Index: AdaptiveClassLoader12.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/loader/Attic/AdaptiveClassLoader12.java,v
  retrieving revision 1.3
  retrieving revision 1.3.2.1
  diff -u -r1.3 -r1.3.2.1
  --- AdaptiveClassLoader12.java	2000/06/19 21:53:14	1.3
  +++ AdaptiveClassLoader12.java	2001/07/23 21:49:08	1.3.2.1
  @@ -98,6 +98,16 @@
   	// 	}
       }
   
  +    protected URL findResource(String name)
  +    {
  +        return findResourceInternal(name);
  +    }
  +
  +    protected Enumeration findResources(String name) throws IOException
  +    {
  +      return findResourcesInternal(name, false).elements();
  +    }
  +
       public boolean shouldReload( String classname ) {
   	final String classnameF=classname;
   	Boolean b = (Boolean)AccessController.doPrivileged(new