KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > mc > formgenerator > bonita > BonitaProjectExecutor


1 /*
2  * Created on 21 avr. 2004
3  *
4  * This class creates a Bonita process instance
5  * thanks to the process parameters given in a XML file
6  *
7  */

8 package mc.formgenerator.bonita;
9
10 import java.io.File JavaDoc;
11 import java.io.IOException JavaDoc;
12 import java.net.MalformedURLException JavaDoc;
13 import java.util.HashMap JavaDoc;
14 import java.util.Iterator JavaDoc;
15 import java.util.Collection JavaDoc;
16 import java.util.Set JavaDoc;
17
18 import org.apache.xerces.parsers.DOMParser;
19 import org.w3c.dom.Document JavaDoc;
20 import org.xml.sax.SAXException JavaDoc;
21
22 import hero.interfaces.*;
23
24 /**
25  * @author delfourr
26  */

27 public class BonitaProjectExecutor {
28
29
30
31     /**
32      * Default class constructor
33      *
34      */

35     public BonitaProjectExecutor() {
36     }
37
38
39
40     /**
41      * Instanciate a process thanks to its data which are in a XML file.
42      * @param fichier XML file with the process information.
43      * @throws MalformedURLException
44      * @throws SAXException
45      * @throws IOException
46      * @throws LoginException
47      */

48     public void startBonitaProject(File JavaDoc fichier)
49         throws MalformedURLException JavaDoc, SAXException JavaDoc, IOException JavaDoc {
50
51
52         //**********************************************************************
53
// FILE --> DOCUMENT
54
//**********************************************************************
55

56         //A parser is needed to read an XML file
57
DOMParser parser = new DOMParser();
58
59         //the parser parse the XML file
60
parser.parse(fichier.toURL().toString());
61
62         //get a Document which represents the File. It's to normalyse the data manipulated
63
Document JavaDoc document = parser.getDocument();
64
65
66
67         //'parse' transforms a Document into a DataProcess
68
DocumentParser parse = new DocumentParser();
69
70         DataProject data = parse.parseProject(document);
71         
72         //wants the process name
73
String JavaDoc name = data.getProcessName();
74
75         //wants the process properties
76
HashMap JavaDoc table = data.getProcessProperties();
77
78         //start the process
79
instanciateProject(name, table);
80
81     }
82
83
84
85
86
87
88     /**
89      * Instanciate a process thanks to its data which are in a Document.
90      * @param document Document with the process information.
91      * @throws MalformedURLException
92      * @throws SAXException
93      * @throws IOException
94      * @throws LoginException
95      */

96     public void startBonitaProject(Document JavaDoc document)
97         throws MalformedURLException JavaDoc, SAXException JavaDoc, IOException JavaDoc {
98
99
100         //'parse' transforms a Document into a DataProcess
101
DocumentParser parse = new DocumentParser();
102
103         DataProject data = parse.parseProject(document);
104         
105         //get the process name
106
String JavaDoc name = data.getProcessName();
107
108         //get the process properties
109
HashMap JavaDoc table = data.getProcessProperties();
110
111
112         //start the process thanks to its name and properties
113
instanciateProject(name, table);
114
115     }
116
117
118
119
120
121     /**
122      * Instanciate the process thanks to its name and its parameters which are in a XML file
123      * @param processName Name of the process to instanciate.
124      * @param table HashMap with 'key value' representing the process properties. 'Key' is the property name and 'Value' is its value.
125      * @throws LoginException
126      */

127     private void instanciateProject(String JavaDoc processName, HashMap JavaDoc table) {
128
129         //The local home
130
ProjectSessionHome projecth = null;
131
132         //The bean
133
ProjectSession project = null;
134
135         try {
136
137             //**************************************************************************
138
// INSTANCIATE THE PROCESS
139
//**************************************************************************
140

141             //Getting local home by using JNDI
142
projecth = ProjectSessionUtil.getHome();
143
144             //Creation of the project
145
project = projecth.create();
146
147             //Project instanciation
148
project.initProject(processName);
149
150
151             //**************************************************************************
152
// SET THE PROCESS PROPERTIES
153
//**************************************************************************
154

155             //All the keys are saved in a set
156
Set JavaDoc collec = table.keySet();
157
158             //Set properties if they exist
159
if (collec.size() > 0) {
160
161                 //For all the keys we have to retrieve the associated value
162
Iterator JavaDoc it = collec.iterator();
163
164                 //variable which will stock the property name
165
String JavaDoc cle="";
166                 
167                 while (it.hasNext()) {
168
169                     //Getting the values
170
cle = (String JavaDoc) it.next();
171
172                     //Set the current process property
173
project.setProperty(cle, (String JavaDoc) table.get(cle));
174                 }
175             }
176
177
178         } catch (Exception JavaDoc e) {
179             System.out.println(e.getMessage());
180         }
181     }
182
183
184
185 }
186
Popular Tags