
org.ow2.bonita.runtime.PackageClassLoader Maven / Gradle / Ivy
/**
* Copyright (C) 2006 Bull S. A. S.
* Bull, Rue Jean Jaures, B.P.68, 78340, Les Clayes-sous-Bois
* This library is free software; you can redistribute it and/or modify it under the terms
* of the GNU Lesser General Public License as published by the Free Software Foundation
* version 2.1 of the License.
* This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU Lesser General Public License for more details.
* You should have received a copy of the GNU Lesser General Public License along with this
* program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
* Floor, Boston, MA 02110-1301, USA.
**/
package org.ow2.bonita.runtime;
import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;
public class PackageClassLoader extends ClassLoader {
private static final Logger LOG = Logger.getLogger(PackageClassLoader.class.getName());
protected Map classDatas = null;
private PackageClassLoader() {
super(VirtualCommonClassLoader.get());
}
public PackageClassLoader(Map classDatas) {
this();
if (LOG.isLoggable(Level.FINE)) {
LOG.fine("Creating a new BonitaClassLoader... classDatas = " + classDatas);
}
this.classDatas = classDatas;
if (LOG.isLoggable(Level.FINE)) {
String availableClasses = "no class";
if (classDatas != null) {
availableClasses = "";
for (String className : classDatas.keySet()) {
availableClasses += className + ", ";
}
}
LOG.fine("BonitaClassLoader: " + this + " created. Datas are available for classDatas : " + availableClasses);
}
}
public Class< ? > findClass(String name) {
if (LOG.isLoggable(Level.FINE)) {
LOG.fine("Looking for class " + name + "... ");
}
if (classDatas != null && classDatas.containsKey(name)) {
byte[] classData = classDatas.get(name);
return defineClass(name, classData, 0, classData.length);
}
if (LOG.isLoggable(Level.FINE)) {
LOG.fine("class " + name + " not found.");
}
return null;
}
protected synchronized Class< ? > loadClass(String name, boolean resolve) throws ClassNotFoundException {
if (LOG.isLoggable(Level.FINE)) {
LOG.fine("Looking for class " + name + "... ");
}
Class< ? > c = findLoadedClass(name);
if (LOG.isLoggable(Level.FINE) && c != null) {
LOG.fine("Class " + name + " found in loaded classes. ");
}
if (c == null) {
// Check if the class is available but not yet loaded
c = findClass(name);
if (LOG.isLoggable(Level.FINE) && c != null) {
LOG.fine("Class " + name + " found in current classLoader. ");
}
}
if (c == null) {
c = getParent().loadClass(name);
if (LOG.isLoggable(Level.FINE) && c != null) {
LOG.fine("Class " + name + " found in parent. ");
}
}
if (LOG.isLoggable(Level.FINE) && c == null) {
LOG.fine("Class " + name + " not found. ");
}
if (resolve) {
resolveClass(c);
}
if (LOG.isLoggable(Level.FINE)) {
LOG.fine("loadClass: " + name + ", result: " + c);
}
return c;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy