org.apache.bcel.util
Class SyntheticRepository

java.lang.Object
  extended by org.apache.bcel.util.SyntheticRepository
All Implemented Interfaces:
java.io.Serializable, Repository

public class SyntheticRepository
extends java.lang.Object
implements Repository

This repository is used in situations where a Class is created outside the realm of a ClassLoader. Classes are loaded from the file systems using the paths specified in the given class path. By default, this is the value returned by ClassPath.getClassPath().
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.setRepository method.

Version:
$Id: SyntheticRepository.java 386056 2006-03-15 11:31:56Z tcurdt $
Author:
M. Dahm, David Dixon-Peugh
See Also:
Repository, Serialized Form

Field Summary
private static java.util.Map _instances
           
private  java.util.Map _loadedClasses
           
private  ClassPath _path
           
private static java.lang.String DEFAULT_PATH
           
 
Constructor Summary
private SyntheticRepository(ClassPath path)
           
 
Method Summary
 void clear()
          Clear all entries from cache.
 JavaClass findClass(java.lang.String className)
          Find an already defined (cached) JavaClass object by name.
 ClassPath getClassPath()
          ClassPath associated with the Repository.
static SyntheticRepository getInstance()
           
static SyntheticRepository getInstance(ClassPath classPath)
           
 JavaClass loadClass(java.lang.Class clazz)
          Find the JavaClass object for a runtime Class object.
private  JavaClass loadClass(java.io.InputStream is, java.lang.String className)
           
 JavaClass loadClass(java.lang.String className)
          Find a JavaClass object by name.
 void removeClass(JavaClass clazz)
          Remove class from repository
 void storeClass(JavaClass clazz)
          Store a new JavaClass instance into this Repository.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_PATH

private static final java.lang.String DEFAULT_PATH

_instances

private static java.util.Map _instances

_path

private ClassPath _path

_loadedClasses

private java.util.Map _loadedClasses
Constructor Detail

SyntheticRepository

private SyntheticRepository(ClassPath path)
Method Detail

getInstance

public static SyntheticRepository getInstance()

getInstance

public static SyntheticRepository getInstance(ClassPath classPath)

storeClass

public void storeClass(JavaClass clazz)
Store a new JavaClass instance into this Repository.

Specified by:
storeClass in interface Repository

removeClass

public void removeClass(JavaClass clazz)
Remove class from repository

Specified by:
removeClass in interface Repository

findClass

public JavaClass findClass(java.lang.String className)
Find an already defined (cached) JavaClass object by name.

Specified by:
findClass in interface Repository

loadClass

public JavaClass loadClass(java.lang.String className)
                    throws java.lang.ClassNotFoundException
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).

Specified by:
loadClass in interface Repository
Parameters:
className - the name of the class
Returns:
the JavaClass object
Throws:
java.lang.ClassNotFoundException - if the class is not in the Repository, and could not be found on the classpath

loadClass

public JavaClass loadClass(java.lang.Class clazz)
                    throws java.lang.ClassNotFoundException
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.

Specified by:
loadClass in interface Repository
Parameters:
clazz - the runtime Class object
Returns:
JavaClass object for given runtime class
Throws:
java.lang.ClassNotFoundException - if the class is not in the Repository, and its representation could not be found
See Also:
Class

loadClass

private JavaClass loadClass(java.io.InputStream is,
                            java.lang.String className)
                     throws java.lang.ClassNotFoundException
Throws:
java.lang.ClassNotFoundException

getClassPath

public ClassPath getClassPath()
ClassPath associated with the Repository.

Specified by:
getClassPath in interface Repository

clear

public void clear()
Clear all entries from cache.

Specified by:
clear in interface Repository