org/objectweb/proactive/core/classloader/ProActiveClassLoaderHelper.java

00001 /* 
00002  * ################################################################
00003  * 
00004  * ProActive: The Java(TM) library for Parallel, Distributed, 
00005  *            Concurrent computing with Security and Mobility
00006  * 
00007  * Copyright (C) 1997-2007 INRIA/University of Nice-Sophia Antipolis
00008  * Contact: proactive@objectweb.org
00009  * 
00010  * This library is free software; you can redistribute it and/or
00011  * modify it under the terms of the GNU Lesser General Public
00012  * License as published by the Free Software Foundation; either
00013  * version 2.1 of the License, or any later version.
00014  *  
00015  * This library is distributed in the hope that it will be useful,
00016  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00017  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00018  * Lesser General Public License for more details.
00019  * 
00020  * You should have received a copy of the GNU Lesser General Public
00021  * License along with this library; if not, write to the Free Software
00022  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
00023  * USA
00024  *  
00025  *  Initial developer(s):               The ProActive Team
00026  *                        http://www.inria.fr/oasis/ProActive/contacts.html
00027  *  Contributor(s): 
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         // 1. look in class cache
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         // 2. look in runtime parents
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             // continue
00092         }
00093 
00094         // 3. standard proactive stub?
00095         if (Utils.isStubClassName(className)) {
00096             // do not use directly MOP methods
00097             logger.info("Generating class : " + className);
00098             //    e.printStackTrace();
00099             String classname = Utils.convertStubClassNameToClassName(className);
00100 
00101             //ASM is now the default bytecode manipulator
00102 //            if (MOPClassLoader.BYTE_CODE_MANIPULATOR.equals("ASM")) {
00103 //                ASMBytecodeStubBuilder bsb = new ASMBytecodeStubBuilder(classname);
00104 //                class_data = bsb.create();
00105 //            } else 
00106                 if (MOPClassLoader.BYTE_CODE_MANIPULATOR.equals("javassist")) {
00107                 class_data = JavassistByteCodeStubBuilder.create(classname, null);
00108             } else {
00109                 // that shouldn't happen, unless someone manually sets the BYTE_CODE_MANIPULATOR static variable
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         // component-generated?
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 }

Generated on Mon Jan 22 15:16:06 2007 for ProActive by  doxygen 1.5.1