cvs commit: jakarta-bcel/src/java/org/apache/bcel/util SyntheticRepository.java

[email protected]
Newsgroups gmane.comp.jakarta.bcel.devel
Message-ID <[email protected]>
mdahm       2003/08/18 00:18:55

  Modified:    src/java/org/apache/bcel/util SyntheticRepository.java
  Log:
  find classes in repository first, then in CLASSPATH
  
  Revision  Changes    Path
  1.8       +31 -10    jakarta-bcel/src/java/org/apache/bcel/util/SyntheticRepository.java
  
  Index: SyntheticRepository.java
  ===================================================================
  RCS file: /home/cvs/jakarta-bcel/src/java/org/apache/bcel/util/SyntheticRepository.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- SyntheticRepository.java	23 May 2003 07:54:07 -0000	1.7
  +++ SyntheticRepository.java	18 Aug 2003 07:18:55 -0000	1.8
  @@ -132,8 +132,15 @@
     }
   
     /**
  -   * Load a JavaClass object for the given class name using
  -   * the CLASSPATH environment variable.
  +   * Find a JavaClass object by name.
  +   * If it is already in this Repository, the Repository version
  +   * is returned.  Otherwise, the Repository's classpath is searched for
  +   * the class (and it is added to the Repository if found).
  +   *
  +   * @param className the name of the class
  +   * @return the JavaClass object
  +   * @throws ClassNotFoundException if the class is not in the
  +   *   Repository, and could not be found on the classpath
      */
     public JavaClass loadClass(String className) throws ClassNotFoundException {
       if (className == null || className.equals("")) {
  @@ -142,6 +149,11 @@
   
       className = className.replace('/', '.'); // Just in case, canonical form
   
  +    JavaClass clazz = findClass(className);
  +    if (clazz != null) {
  +      return clazz;
  +    }
  +
       try {
         return loadClass(_path.getInputStream(className), className);
       } catch (IOException e) {
  @@ -151,12 +163,26 @@
     }
   
     /**
  -   * Try to find class source via getResourceAsStream().
  +   * Find the JavaClass object for a runtime Class object.
  +   * If a class with the same name is already in this Repository,
  +   * the Repository version is returned.  Otherwise, getResourceAsStream()
  +   * is called on the Class object to find the class's representation.
  +   * If the representation is found, it is added to the Repository.
  +   *
      * @see Class
  +   * @param clazz the runtime Class object
      * @return JavaClass object for given runtime class
  +   * @throws ClassNotFoundException if the class is not in the
  +   *   Repository, and its representation could not be found
      */
     public JavaClass loadClass(Class clazz) throws ClassNotFoundException {
       String className = clazz.getName();
  +
  +    JavaClass repositoryClass = findClass(className);
  +    if (repositoryClass != null) {
  +      return repositoryClass;
  +    }
  +
       String name = className;
       int i = name.lastIndexOf('.');
   
  @@ -169,16 +195,11 @@
   
     private JavaClass loadClass(InputStream is, String className)
       throws ClassNotFoundException {
  -    JavaClass clazz = findClass(className);
  -
  -    if (clazz != null) {
  -      return clazz;
  -    }
   
       try {
         if (is != null) {
           ClassParser parser = new ClassParser(is, className);
  -        clazz = parser.parse();
  +        JavaClass clazz = parser.parse();
   
           storeClass(clazz);
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.