org.zeroturnaround.javarebel.integration.jboss5.BaseClassLoaderCBP Maven / Gradle / Ivy
package org.zeroturnaround.javarebel.integration.jboss5;
import org.zeroturnaround.bundled.javassist.ClassPool;
import org.zeroturnaround.bundled.javassist.CtClass;
import org.zeroturnaround.bundled.javassist.CtConstructor;
import org.zeroturnaround.bundled.javassist.CtMethod;
import org.zeroturnaround.bundled.javassist.CtNewMethod;
import org.zeroturnaround.javarebel.ClassResourceSource;
import org.zeroturnaround.javarebel.integration.support.JavassistClassBytecodeProcessor;
public class BaseClassLoaderCBP extends JavassistClassBytecodeProcessor {
private static final String insertBefore = " Class result2 = isLoadedClass(name, trace);\n"
+ " if (result2 != null) {\n"
+ " return result2;\n"
+ " }"
+ " result2 = "
+ " org.zeroturnaround.javarebel.IntegrationFactory.getInstance()"
+ " .findReloadableClass($0, $1);"
+ " if (result2 != null) {"
+ " $0.loadedClasses.put($1, $1);"
+ " return result2;"
+ "}";
public void process(ClassPool cp, ClassLoader cl, CtClass ctClass) throws Exception {
ctClass.addInterface(cp.get(ClassResourceSource.class.getName()));
CtConstructor[] constructors = ctClass.getConstructors();
for (int i = 0; i < constructors.length; i++) {
CtConstructor constructor = constructors[i];
constructor.insertAfter("org.zeroturnaround.javarebel.IntegrationFactory.getInstance().registerClassLoader("
+ "$0, "
+ "(org.zeroturnaround.javarebel.ClassResourceSource)$0);");
}
CtMethod m = ctClass.getMethod("loadClassLocally", "(Ljava/lang/String;Z)Ljava/lang/Class;");
m.insertBefore(insertBefore);
ctClass.addMethod(CtNewMethod.make("public org.zeroturnaround.javarebel.ClassResource getClassResource(String className) {"
+ "final String resourcePath = org.jboss.classloader.plugins.ClassLoaderUtils.classNameToPath(className);"
+ " java.net.URL url = policy.getResource(resourcePath);"
+ " if (url == null) return null;\n"
+ " if (url.getProtocol().equals(\"vfsfile\")) {"
+ " return new org.zeroturnaround.javarebel.support.FileClassResource((new java.io.File(url.getPath()).toURI().toURL()));"
+ " }"
+ " else if (url.getProtocol().equals(\"jar\") || url.getProtocol().equals(\"zip\") || url.getProtocol().equals(\"code-source\")) {"
+ " return new org.zeroturnaround.javarebel.support.JarClassResource(url);"
+ " }"
+ " else {"
+ " return new org.zeroturnaround.javarebel.support.FallbackClassResource(url);"
+ " }\n}", ctClass));
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy