1 package org.jbpm.instantiation; 2 3 import java.io.IOException ; 4 import java.io.InputStream ; 5 import java.util.Properties ; 6 7 import org.jbpm.graph.def.ProcessDefinition; 8 9 12 public class ClassLoaderUtil { 13 14 public static Class loadClass(String className) { 15 try { 16 return getClassLoader().loadClass(className); 17 } catch (ClassNotFoundException e) { 18 throw new RuntimeException ("class not found '"+className+"'", e); 19 } 20 } 21 22 public static ClassLoader getClassLoader() { 23 return ClassLoaderUtil.class.getClassLoader(); 29 } 30 31 public static InputStream getStream(String resource) { 32 return getClassLoader().getResourceAsStream(resource); 33 } 34 35 39 public static InputStream getStream(String resource, String directory) { 40 InputStream is = getClassLoader().getResourceAsStream(resource); 41 if (is==null) { 42 is = getClassLoader().getResourceAsStream(directory+"/"+resource); 43 } 44 return is; 45 } 46 47 public static Properties getProperties(String resource, String directory) { 48 Properties properties = new Properties (); 49 try { 50 properties.load(getStream(resource, directory)); 51 } catch (IOException e) { 52 throw new RuntimeException ("couldn't load properties file '"+resource+"'", e); 53 } 54 return properties; 55 } 56 57 public static ClassLoader getProcessClassLoader(ProcessDefinition processDefinition) { 58 return new ProcessClassLoader(ClassLoaderUtil.class.getClassLoader(), processDefinition); 59 } 60 61 } 62 | Popular Tags |