1 package org.jbpm.context.exe; 2 3 import java.io.BufferedReader ; 4 import java.io.IOException ; 5 import java.io.InputStream ; 6 import java.io.InputStreamReader ; 7 import java.util.ArrayList ; 8 import java.util.List ; 9 import java.util.StringTokenizer ; 10 11 import org.jbpm.db.hibernate.Converters; 12 import org.jbpm.instantiation.ClassLoaderUtil; 13 14 17 public class JbpmType { 18 19 private static List jbpmTypes = null; 20 21 public String variableClassName = null; 22 public Class variableClass = null; 23 public Converter converter = null; 24 public Class variableInstanceClass = null; 25 26 public JbpmType(String line) { 27 List stringTokens = new ArrayList (); 29 StringTokenizer tokenizer = new StringTokenizer (line, " "); 30 while (tokenizer.hasMoreTokens()) { 31 stringTokens.add(tokenizer.nextToken().trim()); 32 } 33 34 if ( (stringTokens.size()<2) 35 || (stringTokens.size()>3) ) { 36 throw new RuntimeException ("invalid format in jbpm.varmapping.properties of line '"+line+"'"); 37 } 38 this.variableClassName = (String ) stringTokens.get(0); 39 40 if ( (! this.variableClassName.startsWith("[")) 42 && (! this.variableClassName.startsWith("{")) ) { 43 this.variableClass = ClassLoaderUtil.loadClass(variableClassName); 44 } 45 46 if (stringTokens.size()==2) { 47 this.variableInstanceClass = getVariableInstanceClass((String ) stringTokens.get(1)); 48 } else { 49 this.converter = getConverter((String ) stringTokens.get(1)); 50 this.variableInstanceClass = getVariableInstanceClass((String ) stringTokens.get(2)); 51 } 52 } 53 54 private Converter getConverter(String converterClassName) { 55 return Converters.getConverterByClassName(converterClassName); 56 } 57 58 private Class getVariableInstanceClass(String variableInstanceClassName) { 59 return ClassLoaderUtil.loadClass(variableInstanceClassName); 60 } 61 62 public static List getJbpmTypes() { 63 if (jbpmTypes==null) { 64 jbpmTypes = new ArrayList (); 65 InputStream is = ClassLoaderUtil.getStream("jbpm.varmapping.properties", "org/jbpm/context/exe"); 66 try { 67 BufferedReader bufferedReader = new BufferedReader (new InputStreamReader (is)); 68 String line = bufferedReader.readLine(); 69 while(line!=null) { 70 line = line.trim(); 71 if ( !line.startsWith("#") 72 && (line.length()!=0)) { 73 jbpmTypes.add(new JbpmType(line)); 74 } 75 line = bufferedReader.readLine(); 76 } 77 } catch (IOException e) { 78 throw new RuntimeException ("couldn't parse the jbpm.varmapping.properties", e); 79 } finally { 80 try { 81 is.close(); 82 } catch (IOException e) { 83 e.printStackTrace(); 84 } 85 } 86 } 87 return jbpmTypes; 88 } 89 } 90 | Popular Tags |