mdahm 2002/10/11 13:34:47
Modified: src/java/org/apache/bcel Repository.java
src/java/org/apache/bcel/util ClassLoaderRepository.java
Repository.java SyntheticRepository.java
Log:
Use generic repository
Revision Changes Path
1.11 +22 -10 jakarta-bcel/src/java/org/apache/bcel/Repository.java
Index: Repository.java
===================================================================
RCS file: /home/cvs/jakarta-bcel/src/java/org/apache/bcel/Repository.java,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -r1.10 -r1.11
--- Repository.java 6 Jul 2002 15:51:34 -0000 1.10
+++ Repository.java 11 Oct 2002 20:34:47 -0000 1.11
@@ -61,16 +61,33 @@
/**
* The repository maintains informations about class interdependencies, e.g.,
* whether a class is a sub-class of another. Delegates actual class loading
- * to SyntheticRepository.
+ * to SyntheticRepository with current class path by default.
+ *
+ * @see org.apache.bcel.util.Repository
+ * @see org.apache.bcel.util.SyntheticRepository
*
* @version $Id$
* @author <A HREF="mailto:[email protected]">M. Dahm</A>
*/
public abstract class Repository {
- private static org.apache.bcel.util.SyntheticRepository _repository =
+ private static org.apache.bcel.util.Repository _repository =
SyntheticRepository.getInstance();
- /** Lookup class somewhere found in your CLASSPATH.
+ /** @return currently used repository instance
+ */
+ public static org.apache.bcel.util.Repository getRepository() {
+ return _repository;
+ }
+
+ /** Set repository instance to be used for class loading
+ */
+ public static void setRepository(org.apache.bcel.util.Repository rep) {
+ _repository = rep;
+ }
+
+ /** Lookup class somewhere found on your CLASSPATH, or whereever the
+ * repository instance looks for it.
+ *
* @return class object for given fully qualified class name, or null
* if the class could not be found or parsed correctly
*/
@@ -136,12 +153,6 @@
_repository.removeClass(clazz);
}
- /*
- private static final JavaClass getSuperClass(JavaClass clazz) {
- return clazz.getSuperClass();
- }
- */
-
/**
* @return list of super classes of clazz in ascending order, i.e.,
* Object is always the last element
@@ -234,3 +245,4 @@
return implementationOf(lookupClass(clazz), inter);
}
}
+
1.4 +65 -49 jakarta-bcel/src/java/org/apache/bcel/util/ClassLoaderRepository.java
Index: ClassLoaderRepository.java
===================================================================
RCS file: /home/cvs/jakarta-bcel/src/java/org/apache/bcel/util/ClassLoaderRepository.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- ClassLoaderRepository.java 31 Jul 2002 18:12:07 -0000 1.3
+++ ClassLoaderRepository.java 11 Oct 2002 20:34:47 -0000 1.4
@@ -67,27 +67,32 @@
*
* It loads its data from the ClassLoader implementation
* passed into its constructor.
+ *
+ * @see org.apache.bcel.Repository
+ *
+ * @version $Id$
+ * @author <A HREF="mailto:[email protected]">M. Dahm</A>
+ * @author David Dixon-Peugh
*/
-
public class ClassLoaderRepository
- implements Repository
+ implements Repository
{
- private java.lang.ClassLoader loader;
- private Map loadedClasses =
- new HashMap(); // CLASSNAME X JAVACLASS
+ private java.lang.ClassLoader loader;
+ private HashMap loadedClasses =
+ new HashMap(); // CLASSNAME X JAVACLASS
- public ClassLoaderRepository( java.lang.ClassLoader loader ) {
- this.loader = loader;
- }
+ public ClassLoaderRepository( java.lang.ClassLoader loader ) {
+ this.loader = loader;
+ }
- /**
- * Store a new JavaClass into this Repository.
- */
- public void storeClass( JavaClass clazz ) {
- loadedClasses.put( clazz.getClassName(),
- clazz );
- clazz.setRepository( this );
- }
+ /**
+ * Store a new JavaClass into this Repository.
+ */
+ public void storeClass( JavaClass clazz ) {
+ loadedClasses.put( clazz.getClassName(),
+ clazz );
+ clazz.setRepository( this );
+ }
/**
* Remove class from repository
@@ -96,44 +101,55 @@
loadedClasses.remove(clazz.getClassName());
}
- /**
- * Find an already defined JavaClass.
- */
- public JavaClass findClass( String className ) {
- if ( loadedClasses.containsKey( className )) {
- return (JavaClass) loadedClasses.get( className );
- } else {
- return null;
- }
+ /**
+ * Find an already defined JavaClass.
+ */
+ public JavaClass findClass( String className ) {
+ if ( loadedClasses.containsKey( className )) {
+ return (JavaClass) loadedClasses.get( className );
+ } else {
+ return null;
}
+ }
- /**
- * Lookup a JavaClass object from the Class Name provided.
- */
- public JavaClass loadClass( String className )
- throws ClassNotFoundException
- {
- String classFile = className.replace('.', '/');
-
- JavaClass RC = findClass( className );
- if (RC != null) { return RC; }
-
- try {
- InputStream is =
- loader.getResourceAsStream( classFile + ".class" );
+ /**
+ * Lookup a JavaClass object from the Class Name provided.
+ */
+ public JavaClass loadClass( String className )
+ throws ClassNotFoundException
+ {
+ String classFile = className.replace('.', '/');
+
+ JavaClass RC = findClass( className );
+ if (RC != null) { return RC; }
+
+ try {
+ InputStream is =
+ loader.getResourceAsStream( classFile + ".class" );
- if(is == null) {
- throw new ClassNotFoundException(className + " not found.");
- }
+ if(is == null) {
+ throw new ClassNotFoundException(className + " not found.");
+ }
- ClassParser parser = new ClassParser( is, className );
- RC = parser.parse();
+ ClassParser parser = new ClassParser( is, className );
+ RC = parser.parse();
- storeClass( RC );
+ storeClass( RC );
- return RC;
- } catch (IOException e) {
- throw new ClassNotFoundException( e.toString() );
- }
+ return RC;
+ } catch (IOException e) {
+ throw new ClassNotFoundException( e.toString() );
}
+ }
+
+ public JavaClass loadClass(Class clazz) throws ClassNotFoundException {
+ return loadClass(clazz.getName());
+ }
+
+ /** Clear all entries from cache.
+ */
+ public void clear() {
+ loadedClasses.clear();
+ }
}
+
1.4 +42 -20 jakarta-bcel/src/java/org/apache/bcel/util/Repository.java
Index: Repository.java
===================================================================
RCS file: /home/cvs/jakarta-bcel/src/java/org/apache/bcel/util/Repository.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- Repository.java 11 Jul 2002 19:39:05 -0000 1.3
+++ Repository.java 11 Oct 2002 20:34:47 -0000 1.4
@@ -56,28 +56,50 @@
import org.apache.bcel.classfile.JavaClass;
+/**
+ * Abstract definition of a class repository. Instances may be used
+ * to load classes from different sources and may be used in the
+ * Repository.setRpeository method.
+ *
+ * @see org.apache.bcel.Repository
+ * @version $Id$
+ * @author <A HREF="mailto:[email protected]">M. Dahm</A>
+ * @author David Dixon-Peugh
+ */
public interface Repository extends java.io.Serializable {
- /**
- * Store the provided class under "clazz.getClassName()"
- */
- public void storeClass( JavaClass clazz );
-
- /**
- * Remove class from repository
- */
- public void removeClass( JavaClass clazz );
+ /**
+ * Store the provided class under "clazz.getClassName()"
+ */
+ public void storeClass(JavaClass clazz);
+
+ /**
+ * Remove class from repository
+ */
+ public void removeClass(JavaClass clazz);
- /**
- * Find the class with the name provided, if the class
- * isn't there, return NULL.
- */
- public JavaClass findClass( String className );
+ /**
+ * Find the class with the name provided, if the class
+ * isn't there, return NULL.
+ */
+ public JavaClass findClass(String className);
+
+ /**
+ * Find the class with the name provided, if the class
+ * isn't there, make an attempt to load it.
+ */
+ public JavaClass loadClass(String className)
+ throws java.lang.ClassNotFoundException;
+ /**
+ * Find the JavaClass instance for the given run-time class object
+ */
+ public JavaClass loadClass(Class clazz)
+ throws java.lang.ClassNotFoundException;
- /**
- * Find the class with the name provided, if the class
- * isn't there, make an attempt to load it.
- */
- public JavaClass loadClass( String className )
- throws java.lang.ClassNotFoundException;
+ /** Clear all entries from cache.
+ */
+ public void clear();
}
+
+
+
1.5 +8 -1 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.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- SyntheticRepository.java 6 Jul 2002 15:51:34 -0000 1.4
+++ SyntheticRepository.java 11 Oct 2002 20:34:47 -0000 1.5
@@ -71,6 +71,13 @@
* It is designed to be used as a singleton, however it
* can also be used with custom classpaths.
*
+/**
+ * Abstract definition of a class repository. Instances may be used
+ * to load classes from different sources and may be used in the
+ * Repository.setRpeository method.
+ *
+ * @see org.apache.bcel.Repository
+ *
* @version $Id$
* @author <A HREF="mailto:[email protected]">M. Dahm</A>
* @author David Dixon-Peugh
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.