001: /**
002: * Bonita
003: * Copyright (C) 1999 Bull S.A.
004: * Bull 68 route de versailles 78434 Louveciennes Cedex France
005: * Further information: bonita@objectweb.org
006: *
007: * This library is free software; you can redistribute it and/or
008: * modify it under the terms of the GNU Lesser General Public
009: * License as published by the Free Software Foundation; either
010: * version 2.1 of the License, or any later version.
011: *
012: * This library is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of
014: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015: * Lesser General Public License for more details.
016: *
017: * You should have received a copy of the GNU Lesser General Public
018: * License along with this library; if not, write to the Free Software
019: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
020: * USA
021: --------------------------------------------------------------------------
022: * BONITA Workflow Patterns sample
023: * Pattern 13 : Multiple Instances With a Priori Design Time Knowledge
024: * Author : Jordi Anguela
025: * Date : 2006/03/01
026: --------------------------------------------------------------------------
027: * Example
028: * Similar to pattern12 but now the sub process create are synchronized
029: * with another activity. This example simulates an approval workflow
030: * where three different users are asked for an authorization. After that
031: * 'send_requisition' activity is executed.
032: --------------------------------------------------------------------------
033: */package hero.client.samples.patterns.src;
034:
035: import hero.client.test.SimpleCallbackHandler;
036: import hero.interfaces.Constants;
037: import hero.interfaces.ProjectSession;
038: import hero.interfaces.ProjectSessionHome;
039: import hero.interfaces.ProjectSessionUtil;
040:
041: import javax.security.auth.login.LoginContext;
042:
043: public class Pattern13MultipleInstancesWithDesignTimeKnowledge {
044:
045: public static void main(String[] args) {
046: try {
047: // User Admin login
048: char[] password = { 't', 'o', 't', 'o' };
049: SimpleCallbackHandler handler = new SimpleCallbackHandler(
050: "admin", password);
051: LoginContext lc = new LoginContext("TestClient", handler);
052: lc.login();
053:
054: // Project Session Bean creation
055: ProjectSessionHome prjHome = (ProjectSessionHome) ProjectSessionUtil
056: .getHome();
057: ProjectSession prjSession = prjHome.create();
058:
059: // Model creation
060: System.out
061: .print("\n Pattern 13 - Multiple Instances With a Priori Design Time Knowledge");
062: prjSession
063: .initModel("Pattern 13 - Multiple Instances With a Priori Design Time Knowledge");
064:
065: // Add activities and set them to Non anticipable
066: prjSession.addNode("hazardous_materials_requisition",
067: hero.interfaces.Constants.Nd.AND_JOIN_NODE);
068: prjSession.addNode("send_requesition",
069: hero.interfaces.Constants.Nd.AND_JOIN_NODE);
070: prjSession
071: .setNodeTraditional("hazardous_materials_requisition");
072: prjSession.setNodeTraditional("send_requesition");
073:
074: // Add Project Properties and set transition conditions
075: //prjSession.setProperty("delegate", "3");
076:
077: // SubProcess definition
078: ProjectSession prjSession2 = prjHome.create();
079: prjSession2.initModel("Authorize requisition (SubProcess)");
080: prjSession2
081: .addNode("authorize", Constants.Nd.AND_JOIN_NODE);
082: prjSession2.setNodeTraditional("authorize");
083: prjSession2
084: .addRole("Executor",
085: "Rol that enables to execute the activities inside the SubProcess");
086: prjSession2.setUserRole("admin", "Executor");
087: prjSession2.setNodeRole("authorize", "Executor");
088: prjSession2.remove();
089:
090: // SubProcess instantiation
091: prjSession.addNodeSubProcess("authorization1",
092: "Authorize requisition (SubProcess)");
093: prjSession.addNodeSubProcess("authorization2",
094: "Authorize requisition (SubProcess)");
095: prjSession.addNodeSubProcess("authorization3",
096: "Authorize requisition (SubProcess)");
097: prjSession.addEdge("hazardous_materials_requisition",
098: "authorization1");
099: prjSession.addEdge("hazardous_materials_requisition",
100: "authorization2");
101: prjSession.addEdge("hazardous_materials_requisition",
102: "authorization3");
103: prjSession.addEdge("authorization1", "send_requesition");
104: prjSession.addEdge("authorization2", "send_requesition");
105: prjSession.addEdge("authorization3", "send_requesition");
106:
107: // Add and set a role for the user admin to execute the activities
108: prjSession.addRole("Executor",
109: "Rol that enables to execute the activities");
110: prjSession.setUserRole("admin", "Executor");
111: prjSession.setNodeRole("hazardous_materials_requisition",
112: "Executor");
113: prjSession.setNodeRole("authorization1", "Executor");
114: prjSession.setNodeRole("authorization2", "Executor");
115: prjSession.setNodeRole("authorization3", "Executor");
116: prjSession.setNodeRole("send_requesition", "Executor");
117:
118: // Check model definition
119: prjSession.checkModelDefinition();
120:
121: System.out.println(" [ OK ]");
122: } catch (Exception e) {
123: System.out.println("\n\n [ ERROR ] : " + e);
124: e.printStackTrace();
125: } // Maybe something is wrong
126: }
127: }
|