
org.ow2.bonita.runtime.ProcessClassLoader 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.io.ByteArrayInputStream;
import java.io.InputStream;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.ow2.bonita.definition.ClassData;
import org.ow2.bonita.facade.uuid.ProcessDefinitionUUID;
import org.ow2.bonita.services.LargeDataRepository;
import org.ow2.bonita.util.EnvTool;
import org.ow2.bonita.util.Misc;
public class ProcessClassLoader extends ClassLoader {
private static final Logger LOG = Logger.getLogger(ProcessClassLoader.class.getName());
protected ProcessDefinitionUUID processUUID;
private ProcessClassLoader() {
super(VirtualCommonClassLoader.get());
}
public ProcessClassLoader(ProcessDefinitionUUID processUUID) {
this();
if (LOG.isLoggable(Level.FINE)) {
LOG.fine("Creating a new BonitaClassLoader... ProcessDefinitionUUID = " + processUUID);
}
this.processUUID = processUUID;
}
public Class< ? > findClass(String name) {
if (LOG.isLoggable(Level.FINE)) {
LOG.fine("Looking for class " + name + "... ");
}
byte[] classData = loadProcessResource(name);
if (classData != null) {
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;
}
@Override
public InputStream getResourceAsStream(String name) {
InputStream is = super.getResourceAsStream(name);
if (is != null) {
return is;
}
//try to load it from the bar
byte[] classData = loadProcessResource(name);
if (classData != null) {
return new ByteArrayInputStream(classData);
}
return null;
}
private byte[] loadProcessResource(String resourceName) {
final LargeDataRepository ldr = EnvTool.getLargeDataRepository();
final ClassData classData = ldr.getData(ClassData.class, Misc.getProcessClassDataCategories(processUUID), resourceName);
if (classData != null) {
return classData.getClassData();
}
return null;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy