001: /*
002: * This file is part of the WfMOpen project.
003: * Copyright (C) 2001-2003 Danet GmbH (www.danet.de), GS-AN.
004: * All rights reserved.
005: *
006: * This program is free software; you can redistribute it and/or modify
007: * it under the terms of the GNU General Public License as published by
008: * the Free Software Foundation; either version 2 of the License, or
009: * (at your option) any later version.
010: *
011: * This program is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
014: * GNU General Public License for more details.
015: *
016: * You should have received a copy of the GNU General Public License
017: * along with this program; if not, write to the Free Software
018: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
019: *
020: * $Id: TypicalProcess.java,v 1.2 2006/09/29 12:32:07 drmlipp Exp $
021: */
022: package load;
023:
024: import java.io.BufferedReader;
025: import java.io.InputStream;
026: import java.io.InputStreamReader;
027: import java.rmi.RemoteException;
028:
029: import javax.security.auth.login.LoginException;
030:
031: import de.danet.an.workflow.api.DefaultRequester;
032: import de.danet.an.workflow.api.FactoryConfigurationError;
033: import de.danet.an.workflow.api.Process;
034: import de.danet.an.workflow.api.ProcessDefinitionDirectory;
035: import de.danet.an.workflow.api.ProcessMgr;
036: import de.danet.an.workflow.api.WorkflowService;
037: import de.danet.an.workflow.api.WorkflowServiceFactory;
038: import de.danet.an.workflow.omgcore.WfRequester;
039: import de.danet.an.workflow.omgcore.ProcessData;
040: import de.danet.an.workflow.api.DefaultProcessData;
041:
042: import common.STProjectLoginContext;
043:
044: import junit.framework.TestCase;
045:
046: /**
047: * This class creates, initializes and starts the process P0 of package
048: * TypicalProcess in file TypicalProcess.xml. Furthermore it delives a
049: * corresponding test case for such a process.
050: *
051: * @author <a href="weidauer@danet.de">Christian Weidauer</a>
052: * @version $Revision: 1.2 $
053: */
054:
055: public class TypicalProcess {
056:
057: private static STProjectLoginContext plc = null;
058: static {
059: try {
060: plc = new STProjectLoginContext();
061: plc.login();
062: } catch (LoginException e) {
063: throw new IllegalStateException(e.getMessage());
064: }
065: try {
066: prepareForCreateProcess();
067: } catch (Exception e) {
068: throw new IllegalStateException(e.getMessage());
069: }
070: }
071:
072: private static WorkflowService wfsCache = null;
073:
074: protected static WorkflowService workflowService() {
075: if (wfsCache == null) {
076: try {
077: WorkflowServiceFactory wfsf = WorkflowServiceFactory
078: .newInstance();
079: wfsCache = wfsf.newWorkflowService();
080: } catch (FactoryConfigurationError e) {
081: throw new IllegalStateException(e.getMessage());
082: }
083: }
084: return wfsCache;
085: }
086:
087: private static WfRequester defReqCache = null;
088:
089: protected static WfRequester defaultRequester()
090: throws RemoteException {
091: if (defReqCache == null) {
092: defReqCache = new DefaultRequester(workflowService());
093: }
094: return defReqCache;
095: }
096:
097: private static ProcessMgr processManager = null;
098:
099: public static final String PACKAGE_ID = "TypicalProcess";
100: public static final String IRRELEVANT = "irrelvant";
101: public static final String PATH1 = "Path 1";
102: public static final String PATH2 = "Path 2";
103: private static final String PATH3 = "Path 3";
104:
105: private ProcessData initialProcessData = new DefaultProcessData();
106: private Process process = null;
107:
108: public TypicalProcess(int durationBE1_3) throws Exception {
109: this (PATH1, IRRELEVANT, durationBE1_3, 0, 0, 0, 0, 0, 0);
110: }
111:
112: public TypicalProcess(String decision2, int durationBE2_1,
113: int durationBE2_3_1, int initialLoopCounter2)
114: throws Exception {
115: this (PATH2, decision2, 0, durationBE2_1, durationBE2_3_1, 0, 0,
116: initialLoopCounter2, 0);
117: }
118:
119: public TypicalProcess(int durationBE2_1, int initialLoopCounter2)
120: throws Exception {
121: this (PATH2, PATH2, 0, durationBE2_1, 0, 0, 0,
122: initialLoopCounter2, 0);
123: }
124:
125: public TypicalProcess(int durationBE3_2_1, int durationBE3_2_2,
126: int initialLoopCounter3) throws Exception {
127: this (PATH3, IRRELEVANT, 0, 0, 0, durationBE3_2_2,
128: durationBE3_2_2, 0, initialLoopCounter3);
129: }
130:
131: public TypicalProcess(int durationBE1_3,
132: boolean initializeAndCreate, boolean start)
133: throws Exception {
134: this (PATH1, IRRELEVANT, durationBE1_3, 0, 0, 0, 0, 0, 0,
135: initializeAndCreate, start);
136: }
137:
138: public TypicalProcess(String decision2, int durationBE2_1,
139: int durationBE2_3_1, int initialLoopCounter2,
140: boolean initializeAndCreate, boolean start)
141: throws Exception {
142: this (PATH2, decision2, 0, durationBE2_1, durationBE2_3_1, 0, 0,
143: initialLoopCounter2, 0, initializeAndCreate, start);
144: }
145:
146: public TypicalProcess(int durationBE2_1, int initialLoopCounter2,
147: boolean initializeAndCreate, boolean start)
148: throws Exception {
149: this (PATH2, PATH2, 0, durationBE2_1, 0, 0, 0,
150: initialLoopCounter2, 0, initializeAndCreate, start);
151: }
152:
153: public TypicalProcess(int durationBE3_2_1, int durationBE3_2_2,
154: int initialLoopCounter3, boolean initializeAndCreate,
155: boolean start) throws Exception {
156: this (PATH3, IRRELEVANT, 0, 0, 0, durationBE3_2_2,
157: durationBE3_2_2, 0, initialLoopCounter3,
158: initializeAndCreate, start);
159: }
160:
161: public TypicalProcess(String decision0, String decision2,
162: int durationBE1_3, int durationBE2_1, int durationBE2_3_1,
163: int durationBE3_2_1, int durationBE3_2_2,
164: int initialLoopCounter2, int initialLoopCounter3)
165: throws Exception {
166: this (decision0, decision2, durationBE1_3, durationBE2_1,
167: durationBE2_3_1, durationBE3_2_1, durationBE3_2_2,
168: initialLoopCounter2, initialLoopCounter3, false, false);
169: }
170:
171: public TypicalProcess(String decision0, String decision2,
172: int durationBE1_3, int durationBE2_1, int durationBE2_3_1,
173: int durationBE3_2_1, int durationBE3_2_2,
174: int initialLoopCounter2, int initialLoopCounter3,
175: boolean initializeAndCreate, boolean start)
176: throws Exception {
177: initialProcessData.put("BE1_3_Duration", new Integer(
178: durationBE1_3));
179: initialProcessData.put("BE2_1_Duration", new Integer(
180: durationBE2_1));
181: initialProcessData.put("BE2_3_1_Duration", new Integer(
182: durationBE2_3_1));
183: initialProcessData.put("BE3_2_1_Duration", new Integer(
184: durationBE3_2_1));
185: initialProcessData.put("BE3_2_2_Duration", new Integer(
186: durationBE3_2_2));
187: initialProcessData.put("counterLoop2", new Integer(
188: initialLoopCounter2));
189: initialProcessData.put("counterLoop3", new Integer(
190: initialLoopCounter3));
191: initialProcessData.put("decision0", decision0);
192: initialProcessData.put("decision2", decision2);
193: if (initializeAndCreate) {
194: process = createAndInitialize();
195: if (start) {
196: process.start();
197: }
198: }
199: }
200:
201: public TypicalProcess(ProcessData initialProcessData,
202: boolean initializeAndCreate, boolean start)
203: throws Exception {
204: this .initialProcessData = initialProcessData;
205: //System.out.println("Typical Process init: " + initialProcessData);
206: if (initializeAndCreate) {
207: process = createAndInitialize();
208: if (start) {
209: process.start();
210: }
211: }
212: }
213:
214: /**
215: * Prepare for creating a process.
216: * @exception Exception if an error occurs
217: */
218: public static void prepareForCreateProcess() throws Exception {
219:
220: // import the process definitions from the XPDL file
221: ProcessDefinitionDirectory pdd = workflowService()
222: .processDefinitionDirectory();
223: InputStream is = TypicalProcess.class
224: .getResourceAsStream("/load/" + PACKAGE_ID + ".xml");
225: BufferedReader br = new BufferedReader(new InputStreamReader(
226: is, "ISO-8859-1"));
227: StringBuffer sb = new StringBuffer();
228: String st;
229: while ((st = br.readLine()) != null) {
230: sb.append(st + "\n");
231: }
232: pdd.importProcessDefinitions(sb.toString());
233:
234: // prepare the creation of process packageID/"P0"
235: try {
236: processManager = pdd.processMgr(PACKAGE_ID, "P0");
237: defReqCache = defaultRequester();
238: } catch (Exception e) {
239: e.printStackTrace();
240: }
241: }
242:
243: /**
244: * Create and start the process of id="P0".
245: * @return created process
246: * @exception Exception if an error occurs
247: */
248: public Process createAndInitialize() throws Exception {
249: process = createProcess(PACKAGE_ID, "P0");
250: process.setProcessContext(initialProcessData);
251: return process;
252: }
253:
254: /**
255: * Describe <code>createProcess</code> method here.
256: *
257: * @param pkgId a <code>String</code> value
258: * @param prcId a <code>String</code> value
259: * @return a <code>Process</code> value
260: * @exception Exception if an error occurs
261: */
262: protected Process createProcess(String pkgId, String prcId)
263: throws Exception {
264: ProcessDefinitionDirectory pdd = workflowService()
265: .processDefinitionDirectory();
266: ProcessMgr pmgr = pdd.processMgr(pkgId, prcId);
267: Process process = (Process) pmgr
268: .createProcess(defaultRequester());
269: return process;
270: }
271:
272: public void start() throws Exception {
273: process.start();
274: }
275:
276: public ProcessData initialProcessData() {
277: return initialProcessData;
278: }
279:
280: public static String packageId() {
281: return PACKAGE_ID;
282: }
283:
284: public TestCase createInitStartTest() {
285: return new GenericTest("createStartAndInitializeProcess",
286: PACKAGE_ID, initialProcessData);
287: }
288: }
|