KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jbpm > context > exe > JbpmType


1 package org.jbpm.context.exe;
2
3 import java.io.BufferedReader JavaDoc;
4 import java.io.IOException JavaDoc;
5 import java.io.InputStream JavaDoc;
6 import java.io.InputStreamReader JavaDoc;
7 import java.util.ArrayList JavaDoc;
8 import java.util.List JavaDoc;
9 import java.util.StringTokenizer JavaDoc;
10
11 import org.jbpm.db.hibernate.Converters;
12 import org.jbpm.instantiation.ClassLoaderUtil;
13
14 /**
15  * specifies for one java-type how jbpm is able to persist objects of that type in the database.
16  */

17 public class JbpmType {
18   
19   private static List JavaDoc jbpmTypes = null;
20   
21   public String JavaDoc variableClassName = null;
22   public Class JavaDoc variableClass = null;
23   public Converter converter = null;
24   public Class JavaDoc variableInstanceClass = null;
25
26   public JbpmType(String JavaDoc line) {
27     // parse the line
28
List JavaDoc stringTokens = new ArrayList JavaDoc();
29     StringTokenizer JavaDoc tokenizer = new StringTokenizer JavaDoc(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 JavaDoc("invalid format in jbpm.varmapping.properties of line '"+line+"'");
37     }
38     this.variableClassName = (String JavaDoc) stringTokens.get(0);
39     
40     // if this class represents an array or a collection of classes
41
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 JavaDoc) stringTokens.get(1));
48     } else {
49       this.converter = getConverter((String JavaDoc) stringTokens.get(1));
50       this.variableInstanceClass = getVariableInstanceClass((String JavaDoc) stringTokens.get(2));
51     }
52   }
53
54   private Converter getConverter(String JavaDoc converterClassName) {
55     return Converters.getConverterByClassName(converterClassName);
56   }
57
58   private Class JavaDoc getVariableInstanceClass(String JavaDoc variableInstanceClassName) {
59     return ClassLoaderUtil.loadClass(variableInstanceClassName);
60   }
61
62   public static List JavaDoc getJbpmTypes() {
63     if (jbpmTypes==null) {
64       jbpmTypes = new ArrayList JavaDoc();
65       InputStream JavaDoc is = ClassLoaderUtil.getStream("jbpm.varmapping.properties", "org/jbpm/context/exe");
66       try {
67         BufferedReader JavaDoc bufferedReader = new BufferedReader JavaDoc(new InputStreamReader JavaDoc(is));
68         String JavaDoc 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 JavaDoc e) {
78         throw new RuntimeException JavaDoc("couldn't parse the jbpm.varmapping.properties", e);
79       } finally {
80         try {
81           is.close();
82         } catch (IOException JavaDoc e) {
83           e.printStackTrace();
84         }
85       }
86     }
87     return jbpmTypes;
88   }
89 }
90
Popular Tags