01: /*
02: * Bossa Workflow System
03: *
04: * $Id: WFNetUtil.java,v 1.12 2004/03/03 17:19:03 gdvieira Exp $
05: *
06: * Copyright (C) 2003,2004 OpenBR Sistemas S/C Ltda.
07: *
08: * This file is part of Bossa.
09: *
10: * Bossa is free software; you can redistribute it and/or modify it
11: * under the terms of version 2 of the GNU General Public License as
12: * published by the Free Software Foundation.
13: *
14: * This program is distributed in the hope that it will be useful,
15: * but WITHOUT ANY WARRANTY; without even the implied warranty of
16: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17: * General Public License for more details.
18: *
19: * You should have received a copy of the GNU General Public
20: * License along with this program; if not, write to the
21: * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
22: * Boston, MA 02111-1307, USA.
23: */
24:
25: package com.bigbross.bossa.wfnet;
26:
27: import java.util.Map;
28:
29: import com.bigbross.bossa.BossaException;
30: import com.bigbross.bossa.BossaTestUtil;
31: import com.bigbross.bossa.resource.Resource;
32: import com.bigbross.bossa.resource.ResourceUtil;
33:
34: public class WFNetUtil {
35:
36: static Case createCase() throws Exception {
37: return BossaTestUtil.createCaseType("test").openCaseImpl(null);
38: }
39:
40: static Case createCase(int[] marking) throws Exception {
41: return BossaTestUtil.createCaseType("test", marking)
42: .openCaseImpl(null);
43: }
44:
45: static Case createAutoFireCase() throws BossaException {
46: CaseType caseType = new CaseType("auto-fire");
47: Place A = caseType.registerPlace("A", 1);
48: Place B = caseType.registerPlace("B");
49: Place C = caseType.registerPlace("C");
50: Transition a = caseType.registerTransition("a", "boss");
51: Transition b = caseType.registerTransition("b", "boss", 0);
52: a.input(A, "1");
53: a.output(B, "1");
54: b.input(B, "1");
55: b.output(C, "1");
56: caseType.buildTemplate(null);
57: return caseType.openCaseImpl(null);
58: }
59:
60: static boolean fire(Case caze, String workItemId, Map attributes)
61: throws Exception {
62: return fire(caze, workItemId, attributes, ResourceUtil
63: .createResource("jdoe"));
64: }
65:
66: static boolean fire(Case caze, String workItemId, Map attributes,
67: Resource resource) throws Exception {
68: Activity act = caze
69: .open(caze.getWorkItem(workItemId), resource);
70: if (act != null) {
71: return act.getCase().close(act, attributes);
72: }
73: return false;
74: }
75: }
|