cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From blorit...@locus.apache.org
Subject cvs commit: xml-cocoon/src/org/apache/cocoon/components/classloader RepositoryClassLoader.java
Date Wed, 13 Dec 2000 14:44:17 GMT
bloritsch    00/12/13 06:44:17

  Modified:    src/org/apache/cocoon/components/classloader Tag:
                        xml-cocoon2 RepositoryClassLoader.java
  Log:
  Change the logging on RepositoryClassLoader to be more accurate about
  what is going on.  Also, made the File take advantage of the url base.
  
  I can't help but think extending or wrapping URLClassLoader would be easier!
  
  Revision  Changes    Path
  No                   revision
  
  
  No                   revision
  
  
  1.1.2.11  +57 -48    xml-cocoon/src/org/apache/cocoon/components/classloader/Attic/RepositoryClassLoader.java
  
  Index: RepositoryClassLoader.java
  ===================================================================
  RCS file: /home/cvs/xml-cocoon/src/org/apache/cocoon/components/classloader/Attic/RepositoryClassLoader.java,v
  retrieving revision 1.1.2.10
  retrieving revision 1.1.2.11
  diff -u -r1.1.2.10 -r1.1.2.11
  --- RepositoryClassLoader.java	2000/12/11 17:09:37	1.1.2.10
  +++ RepositoryClassLoader.java	2000/12/13 14:44:16	1.1.2.11
  @@ -24,7 +24,7 @@
    * A class loader with a growable list of path search directories
    *
    * @author <a href="mailto:ricardo@apache.org">Ricardo Rocha</a>
  - * @version CVS $Revision: 1.1.2.10 $ $Date: 2000/12/11 17:09:37 $
  + * @version CVS $Revision: 1.1.2.11 $ $Date: 2000/12/13 14:44:16 $
    */
   class RepositoryClassLoader extends ClassLoader {
     /**
  @@ -118,7 +118,7 @@
         try {
           c = findSystemClass(name);
         } catch (ClassNotFoundException e) {
  -        log.warn("Could not load class", e);
  +        log.debug("Could not load class " + name + "trying to load from the repository");
           byte[] bits = this.loadClassData (name);
   
           if (bits == null) {
  @@ -144,51 +144,62 @@
       return c;
     }
   
  -  /**
  -   * Load class from a file contained in a repository.
  -   *
  -   * @param className The class name
  -   * @return An array of byes containing the class data or <code>null</code>
if
  -   * not founfd
  -   */
  -  protected byte[] loadClassData (String className) {
  -    int count = this.repositories.size();
  -    for (int i = 0; i < count; i++) {
  -      File repository = (File) this.repositories.elementAt(i);
  -      File file = new File(this.getClassFilename(className, repository));
  -
  -      if (file.exists() && file.isFile() && file.canRead()) {
  -        byte[] buffer = null;
  -        FileInputStream in = null;
  -
  -        int n = 0;
  -        int pos = 0;
  -        buffer = new byte [(int) file.length ()];
  -
  -        try {
  -          in = new FileInputStream(file);
  -
  -          while (
  -            pos < buffer.length &&
  -            (n = in.read (buffer, pos, buffer.length - pos)) != -1
  -          ) {
  -            pos += n;
  -          }
  +    /**
  +    * Load class from a file contained in a repository.
  +    *
  +    * @param className The class name
  +    * @return An array of byes containing the class data or <code>null</code>
if
  +    * not founfd
  +    */
  +    protected byte[] loadClassData (String className) {
  +        int count = this.repositories.size();
  +        for (int i = 0; i < count; i++) {
  +            File repository = (File) this.repositories.elementAt(i);
  +            File file = new File(repository, this.getClassFilename(className));
   
  -      return buffer;
  -    } catch (IOException e) {
  -      log.warn("RepositoryClassLoader.IOException", e);
  -        } finally {
  -          if (in != null) {
  -            try { in.close(); }
  -            catch (IOException e) { log.warn("Could not close stream", e); }
  -          }
  +            if (file.exists() && file.isFile() && file.canRead()) {
  +                byte[] buffer = null;
  +                FileInputStream in = null;
  +
  +                int n = 0;
  +                int pos = 0;
  +                buffer = new byte [(int) file.length ()];
  +
  +                try {
  +                    boolean process = true;
  +                    log.debug("Loading file: " + file.getCanonicalPath());
  +
  +                    in = new FileInputStream(file);
  +
  +                    while (process) {
  +                        if (pos < buffer.length) {
  +                            n = in.read (buffer, pos, buffer.length - pos));
  +                            if (n != -1) {
  +                                pos += n;
  +                            } else {
  +                                process = false;
  +                            }
  +                        } else {
  +                            process = false;
  +                        }
  +                    }
  +
  +                    log.debug(n + " Bytes read.");
  +
  +                    return buffer;
  +                } catch (IOException e) {
  +                    log.warn("RepositoryClassLoader.IOException", e);
  +                } finally {
  +                    if (in != null) {
  +                        try { in.close(); }
  +                        catch (IOException e) { log.warn("Could not close stream", e);
}
  +                    }
  +                }
  +            }
           }
  -      }
  -    }
   
  -    return null;
  -  }
  +        return null;
  +    }
   
     /**
      * Return the filename associated with a given class name in a given
  @@ -199,9 +210,7 @@
      * @return The filename associated with a given class name in a given
      * directory
      */
  -  protected String getClassFilename(String className, File repository) {
  -    return
  -      repository.getAbsolutePath() + File.separator +
  -      className.replace('.', File.separatorChar) + ".class";
  +  protected String getClassFilename(String className) {
  +    return className.replace('.', File.separatorChar) + ".class";
     }
   }
  
  
  

Mime
View raw message