001: /*
002: * Created on 21 avr. 2004
003: *
004: * This class creates a Bonita process instance
005: * thanks to the process parameters given in a XML file
006: *
007: */
008: package mc.formgenerator.bonita;
009:
010: import java.io.File;
011: import java.io.IOException;
012: import java.net.MalformedURLException;
013: import java.util.HashMap;
014: import java.util.Hashtable;
015: import java.util.Iterator;
016: import java.util.Collection;
017: import java.util.Set;
018: import java.util.Vector;
019:
020: import org.apache.xerces.parsers.DOMParser;
021: import org.w3c.dom.Document;
022: import org.xml.sax.SAXException;
023:
024: import hero.interfaces.*;
025: import hero.util.HeroException;
026:
027: /**
028: * Given instance document with properties, initializes a project
029: */
030: public class BonitaProjectExecutor {
031:
032: /**
033: * Default class constructor
034: *
035: */
036: public BonitaProjectExecutor() {
037: }
038:
039: /**
040: * Instanciate a process thanks to its data which are in a XML file.
041: * @param fichier XML file with the process information.
042: * @throws MalformedURLException
043: * @throws SAXException
044: * @throws IOException
045: * @throws LoginException
046: */
047: public void startBonitaProject(File fichier, Vector req_parameters,
048: boolean formsExists, String version)
049: throws MalformedURLException, SAXException, IOException,
050: Exception {
051:
052: //**********************************************************************
053: // FILE --> DOCUMENT
054: //**********************************************************************
055:
056: //A parser is needed to read an XML file
057: DOMParser parser = new DOMParser();
058:
059: //the parser parse the XML file
060: parser.parse(fichier.toURL().toString());
061:
062: //get a Document which represents the File. It's to normalyse the data manipulated
063: Document document = parser.getDocument();
064:
065: //'parse' transforms a Document into a DataProcess
066: DocumentParser parse = new DocumentParser();
067:
068: DataProject data = parse.parseProject(document, req_parameters,
069: formsExists);
070:
071: //wants the process name
072: String name = data.getProjectName();
073:
074: //wants the process properties
075: HashMap table = data.getProjectProperties();
076:
077: //start the process
078: instanciateProject(name, version, table);
079:
080: }
081:
082: /**
083: * Instanciate a process thanks to its data which are in a Document.
084: * @param document Document with the process information.
085: * @throws MalformedURLException
086: * @throws SAXException
087: * @throws IOException
088: * @throws LoginException
089: */
090: public String startBonitaProject(Document document,
091: Vector req_parameters, boolean formsExists, String version)
092: throws MalformedURLException, SAXException, IOException,
093: Exception {
094:
095: String instance = null;
096:
097: //'parse' transforms a Document into a DataProcess
098: DocumentParser parse = new DocumentParser();
099:
100: DataProject data = parse.parseProject(document, req_parameters,
101: formsExists);
102:
103: //get the process name & version
104: String name = data.getProjectName();
105:
106: //get the process properties
107: HashMap table = data.getProjectProperties();
108:
109: //start the process thanks to its name, version and properties
110: instance = instanciateProject(name, version, table);
111: return instance;
112: }
113:
114: /**
115: * Instanciate the process thanks to its name and its parameters which are in a XML file
116: * @param processName Name of the process to instanciate.
117: * @param table HashMap with 'key value' representing the process properties. 'Key' is the property name and 'Value' is its value.
118: * @throws LoginException
119: */
120: private String instanciateProject(String processName,
121: String processVersion, HashMap table) throws Exception {
122:
123: //The local home
124: ProjectSessionHome projecth = null;
125:
126: //The bean
127: ProjectSession project = null;
128:
129: //The instance name
130: String instance = null;
131:
132: try {
133:
134: //**************************************************************************
135: // INSTANCIATE THE PROCESS
136: //**************************************************************************
137:
138: //Getting local home by using JNDI
139: projecth = ProjectSessionUtil.getHome();
140:
141: //Creation of the project
142: project = projecth.create();
143:
144: //Project instanciation
145: if (processVersion == null)
146: instance = project.instantiateProject(processName,
147: new Hashtable(table));
148: else
149: instance = project.instantiateProject(processName,
150: processVersion, new Hashtable(table));
151: //project.initProject(processName);
152:
153: project.remove();
154:
155: } catch (Exception e) {
156: try {
157: if (project != null)
158: project.remove();
159: } catch (Exception re) {
160: System.out.println(re + " " + e.getMessage());
161: }
162: //System.out.println(e.getMessage());
163: throw new Exception(e.getMessage());
164: }
165: return instance;
166: }
167:
168: }
|