ASMClassFileLoaderpublic class ASMClassFileLoader extends Object implements ClassFileLoader*This is a factory for {@link ASMClassFile}. This is not a public class, as
I expect users to use {@link ClassFileLoaderFactory} interface. This class
internally uses the the standard Java ClassLoader to load the resource and
construct ASMClassFile object out of it. |
Fields Summary |
---|
private ClassLoader | cl | private static String | resourceBundleName | private static Logger | logger | private static final String | myClassName | private Map | loadedClassesCache |
Constructors Summary |
---|
public ASMClassFileLoader(String cp)Creates a new instance of ASMClassFileLoader.
ArrayList<URL> urls = new ArrayList<URL>();
for (StringTokenizer st = new StringTokenizer(cp, File.pathSeparator);
st.hasMoreTokens();) {
String entry = st.nextToken();
try {
urls.add(new File(entry).toURI().toURL());
} catch (MalformedURLException e) {
logger.logp(Level.WARNING, myClassName, "init<>", getClass().getName() + ".exception1", new Object[]{entry});
logger.log(Level.WARNING, "", e);
}
}
//We do not want system class loader or even extension class loadera s our parent.
//We want only boot class loader as our parent. Boot class loader is represented as null.
cl = new URLClassLoader((URL[]) urls.toArray(new URL[0]), null);
| public ASMClassFileLoader(ClassLoader cl)Creates a new instance of ASMClassFileLoader.
this.cl = cl;
|
Methods Summary |
---|
public ClassFile | load(java.lang.String externalClassName)
logger.entering("ASMClassFileLoader", "load", externalClassName); // NOI18N
WeakReference<ClassFile> cachedCF = loadedClassesCache.get(externalClassName);
if(cachedCF!=null){
ClassFile cf = cachedCF.get();
if(cf!=null){
return cf;
} else {
logger.logp(Level.FINE, "ASMClassFileLoader", "load", // NOI18N
"{0} has been garbage collected from cache!", externalClassName); // NOI18N
}
}
return load0(externalClassName);
| private ClassFile | load0(java.lang.String externalClassName)
//URLClassLoader library expects me to pass in internal form.
String internalClassName = externalClassName.replace('.", '/");
InputStream is = cl.getResourceAsStream(internalClassName + ".class");
//URLClassLoader returns null if resource is not found.
if (is == null) throw new IOException(
"Not able to load " + internalClassName + ".class");
try {
ClassFile cf = new ASMClassFile(is);
matchClassSignature(cf, externalClassName);
loadedClassesCache.put(externalClassName,
new WeakReference<ClassFile>(cf));
return cf;
} finally {
is.close();
}
| private void | matchClassSignature(ClassFile cf, java.lang.String externalClassName)
String nameOfLoadedClass = cf.getName();
if (!nameOfLoadedClass.equals(externalClassName)) {
throw new IOException(externalClassName + ".class represents " +
cf.getName() +
". Perhaps your package name is incorrect or you passed the " +
"name using internal form instead of using external form.");
}
|
|