BCELClassFileLoaderpublic class BCELClassFileLoader extends Object implements ClassFileLoader*This is a factory for {@link BCELClassFile}. 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 BCELClassFile object out of it. |
Fields Summary |
---|
private ClassLoader | cl | private static String | resourceBundleName | private static Logger | logger | private static final String | myClassName |
Constructors Summary |
---|
public BCELClassFileLoader(String cp)Creates a new instance of BCELClassFileLoader. // NOI18N
ArrayList<URL> urls = new ArrayList<URL>();
for (StringTokenizer st = new StringTokenizer(cp, File.pathSeparator);
st.hasMoreTokens();) {
String entry = st.nextToken();
try {
// toURI().toURL() takes care of all the escape characters
// in the absolutePath. The toURI() method encodes all escape
// characters. Later URLClassLoader decodes and regenerates
// correct escape characters.
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 BCELClassFileLoader(ClassLoader cl)Creates a new instance of BCELClassFileLoader.
this.cl = cl;
|
Methods Summary |
---|
public ClassFile | load(java.lang.String externalClassName)
logger.entering("BCELClassFileLoader", "load", externalClassName); // NOI18N
//URLClassLoader library expects me to pass in internal form.
String internalClassName = externalClassName.replace('.", '/");
URL resource = cl.getResource(internalClassName + ".class");
//URLClassLoader returns null if resource is not found.
if(resource == null)
throw new IOException("Not able to load " + internalClassName + ".class");
URLConnection urlcon = resource.openConnection();
urlcon.setUseCaches(false); // bug 6328564
InputStream is = urlcon.getInputStream();
try {
ClassFile cf = new BCELClassFile(is, internalClassName + ".class"); // NOI18N
matchClassSignature(cf, externalClassName);
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.");
}
|
|