1 package org.jbpm.instantiation; 2 3 import java.io.*; 4 import org.jbpm.file.def.*; 5 import org.jbpm.graph.def.*; 6 7 public class ProcessClassLoader extends ClassLoader { 8 9 private ProcessDefinition processDefinition = null; 10 11 public ProcessClassLoader( ClassLoader parent, ProcessDefinition processDefinition ) { 12 super(parent); 13 this.processDefinition = processDefinition; 14 } 15 16 public InputStream getResourceAsStream(String name) { 17 InputStream inputStream = null; 18 FileDefinition fileDefinition = processDefinition.getFileDefinition(); 19 if (fileDefinition!=null) { 20 byte[] bytes = fileDefinition.getBytes(name); 21 if (bytes!=null) { 22 inputStream = new ByteArrayInputStream(bytes); 23 } 24 } 25 return inputStream; 26 } 27 28 public Class findClass(String name) throws ClassNotFoundException { 29 Class clazz = null; 30 31 FileDefinition fileDefinition = processDefinition.getFileDefinition(); 32 if (fileDefinition!=null) { 33 String fileName = "classes/" + name.replace( '.', '/' ) + ".class"; 34 byte[] classBytes = fileDefinition.getBytes(fileName); 35 clazz = defineClass(name, classBytes, 0, classBytes.length); 36 } 37 38 if (clazz==null) { 39 throw new ClassNotFoundException ("class '"+name+"' could not be found by the process classloader"); 40 } 41 42 return clazz; 43 } 44 } 45 | Popular Tags |