KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jbpm > instantiation > ProcessClassLoader


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 JavaDoc {
8   
9   private ProcessDefinition processDefinition = null;
10
11   public ProcessClassLoader( ClassLoader JavaDoc parent, ProcessDefinition processDefinition ) {
12     super(parent);
13     this.processDefinition = processDefinition;
14   }
15
16   public InputStream getResourceAsStream(String JavaDoc 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 JavaDoc findClass(String JavaDoc name) throws ClassNotFoundException JavaDoc {
29     Class JavaDoc clazz = null;
30
31     FileDefinition fileDefinition = processDefinition.getFileDefinition();
32     if (fileDefinition!=null) {
33       String JavaDoc 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 JavaDoc("class '"+name+"' could not be found by the process classloader");
40     }
41
42     return clazz;
43   }
44 }
45
Popular Tags