FileDocCategorySizeDatePackage
SyntheticRepository.javaAPI DocJava SE 6 API6814Tue Jun 10 00:22:24 BST 2008com.sun.org.apache.bcel.internal.util

SyntheticRepository

public class SyntheticRepository extends 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.
see
com.sun.org.apache.bcel.internal.Repository
version
$Id: SyntheticRepository.java,v 1.1.2.1 2005/07/31 23:47:04 jeffsuttor Exp $
author
M. Dahm
author
David Dixon-Peugh

Fields Summary
private static final String
DEFAULT_PATH
private static HashMap
_instances
private ClassPath
_path
private HashMap
_loadedClasses
Constructors Summary
private SyntheticRepository(ClassPath path)

 // CLASSNAME X JAVACLASS

     
    _path = path;
  
Methods Summary
public voidclear()
Clear all entries from cache.

    _loadedClasses.clear();
  
public com.sun.org.apache.bcel.internal.classfile.JavaClassfindClass(java.lang.String className)
Find an already defined (cached) JavaClass object by name.

    return (JavaClass)_loadedClasses.get(className);
  
public static com.sun.org.apache.bcel.internal.util.SyntheticRepositorygetInstance()

    return getInstance(ClassPath.SYSTEM_CLASS_PATH);
  
public static com.sun.org.apache.bcel.internal.util.SyntheticRepositorygetInstance(ClassPath classPath)

    SyntheticRepository rep = (SyntheticRepository)_instances.get(classPath);

    if(rep == null) {
      rep = new SyntheticRepository(classPath);
      _instances.put(classPath, rep);
    }

    return rep;
  
public com.sun.org.apache.bcel.internal.classfile.JavaClassloadClass(java.lang.String className)
Load a JavaClass object for the given class name using the CLASSPATH environment variable.

    if(className == null || className.equals("")) {
      throw new IllegalArgumentException("Invalid class name " + className);
    }

    className = className.replace('/", '."); // Just in case, canonical form

    try {
      return loadClass(_path.getInputStream(className), className);
    } catch(IOException e) {
      throw new ClassNotFoundException("Exception while looking for class " + 
				       className + ": " + e.toString());
    }
  
public com.sun.org.apache.bcel.internal.classfile.JavaClassloadClass(java.lang.Class clazz)
Try to find class source via getResourceAsStream().

see
Class
return
JavaClass object for given runtime class

    String className = clazz.getName();
    String name      = className;
    int    i         = name.lastIndexOf('.");

    if(i > 0) {
      name = name.substring(i + 1);
    }

    return loadClass(clazz.getResourceAsStream(name + ".class"), className);
  
private com.sun.org.apache.bcel.internal.classfile.JavaClassloadClass(java.io.InputStream is, java.lang.String className)

    JavaClass clazz = findClass(className);

    if(clazz != null) { 
      return clazz;
    }

    try {
      if(is != null) {
	ClassParser parser = new ClassParser(is, className);
	clazz = parser.parse();
	
	storeClass(clazz);
	
	return clazz;
      }
    } catch(IOException e) {
      throw new ClassNotFoundException("Exception while looking for class " + 
				       className + ": " + e.toString());
    }

    throw new ClassNotFoundException("SyntheticRepository could not load " +
				     className);    
  
public voidremoveClass(com.sun.org.apache.bcel.internal.classfile.JavaClass clazz)
Remove class from repository

    _loadedClasses.remove(clazz.getClassName());
  
public voidstoreClass(com.sun.org.apache.bcel.internal.classfile.JavaClass clazz)
Store a new JavaClass instance into this Repository.

    _loadedClasses.put(clazz.getClassName(), clazz);
    clazz.setRepository(this);