00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031 package org.objectweb.proactive.core.classloader;
00032
00033 import org.apache.log4j.Logger;
00034 import org.objectweb.proactive.core.mop.JavassistByteCodeStubBuilder;
00035 import org.objectweb.proactive.core.mop.MOPClassLoader;
00036 import org.objectweb.proactive.core.mop.Utils;
00037 import org.objectweb.proactive.core.runtime.ProActiveRuntimeImpl;
00038 import org.objectweb.proactive.core.util.ClassDataCache;
00039 import org.objectweb.proactive.core.util.log.Loggers;
00040 import org.objectweb.proactive.core.util.log.ProActiveLogger;
00041
00042
00054 public class ProActiveClassLoaderHelper {
00055 private static Logger logger = ProActiveLogger.getLogger(Loggers.CLASSLOADING);
00056 private ClassDataCache classCache;
00057
00058 public ProActiveClassLoaderHelper() {
00059 classCache = ClassDataCache.instance();
00060 }
00061
00068 public synchronized byte[] getClassData(String className) throws ClassNotFoundException {
00069 byte[] class_data = null;
00070
00071
00072 debug("looking for " + className + " in class data cache");
00073 class_data = classCache.getClassData(className);
00074 if (class_data != null) {
00075 debug("found " + className + " in class data cache");
00076 return class_data;
00077 }
00078
00079
00080 try {
00081 debug("looking for " + className + " in parent runtimes");
00082
00083 class_data = ProActiveRuntimeImpl.getProActiveRuntime()
00084 .getClassDataFromParentRuntime(className);
00085 if (class_data != null) {
00086 debug("found " + className + " in ancestor runtime");
00087 return class_data;
00088 }
00089 } catch (Exception e) {
00090 e.printStackTrace();
00091
00092 }
00093
00094
00095 if (Utils.isStubClassName(className)) {
00096
00097 logger.info("Generating class : " + className);
00098
00099 String classname = Utils.convertStubClassNameToClassName(className);
00100
00101
00102
00103
00104
00105
00106 if (MOPClassLoader.BYTE_CODE_MANIPULATOR.equals("javassist")) {
00107 class_data = JavassistByteCodeStubBuilder.create(classname, null);
00108 } else {
00109
00110 System.err.println(
00111 "byteCodeManipulator argument is optionnal. If specified, it can only be set to javassist (ASM is no longer supported).");
00112 System.err.println(
00113 "Any other setting will result in the use of javassist, the default bytecode manipulator framework");
00114 }
00115 if (class_data != null) {
00116 classCache.addClassData(className, class_data);
00117 return class_data;
00118 }
00119 }
00120
00121 if (class_data != null) {
00122 return class_data;
00123 }
00124
00125
00126 class_data = org.objectweb.proactive.core.component.gen.Utils.getClassData(className);
00127
00128 if (class_data != null) {
00129 classCache.addClassData(className, class_data);
00130 return class_data;
00131 }
00132
00133 throw new ClassNotFoundException(className);
00134 }
00135
00136 private void debug(String message) {
00137 if (logger.isDebugEnabled()) {
00138 logger.debug(ProActiveRuntimeImpl.getProActiveRuntime().getURL() +
00139 " --> " + message);
00140 }
00141 }
00142 }