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 06 : Multi Choice
024: * Author : Jordi Anguela
025: * Date : 2006/03/01
026: --------------------------------------------------------------------------
027: * Example
028: * After executing the activity evaluate_damage the activity more than one
029: * activity can be executed. In this example activities contact_police and
030: * contact_hospital are chosen.
031: --------------------------------------------------------------------------
032: */package hero.client.samples.patterns.src;
033:
034: import hero.client.test.SimpleCallbackHandler;
035: import hero.interfaces.ProjectSession;
036: import hero.interfaces.ProjectSessionHome;
037: import hero.interfaces.ProjectSessionUtil;
038:
039: import javax.security.auth.login.LoginContext;
040:
041: public class Pattern06MultiChoice {
042:
043: public static void main(String[] args) {
044: try {
045: // User Admin login
046: char[] password = { 't', 'o', 't', 'o' };
047: SimpleCallbackHandler handler = new SimpleCallbackHandler(
048: "admin", password);
049: LoginContext lc = new LoginContext("TestClient", handler);
050: lc.login();
051:
052: // Project Session Bean creation
053: ProjectSessionHome prjHome = (ProjectSessionHome) ProjectSessionUtil
054: .getHome();
055: ProjectSession prjSession = prjHome.create();
056:
057: // Model creation
058: System.out.print("\n Pattern 06 - Multi Choice");
059: prjSession.initModel("Pattern 06 - Multi Choice");
060:
061: // Add activities and set them to Non anticipable
062: prjSession.addNode("evaluate_damage",
063: hero.interfaces.Constants.Nd.AND_JOIN_NODE);
064: prjSession.addNode("contact_fire_department",
065: hero.interfaces.Constants.Nd.AND_JOIN_NODE);
066: prjSession.addNode("contact_police",
067: hero.interfaces.Constants.Nd.AND_JOIN_NODE);
068: prjSession.addNode("contact_hospital",
069: hero.interfaces.Constants.Nd.AND_JOIN_NODE);
070: prjSession.setNodeTraditional("evaluate_damage");
071: prjSession.setNodeTraditional("contact_fire_department");
072: prjSession.setNodeTraditional("contact_police");
073: prjSession.setNodeTraditional("contact_hospital");
074:
075: // Add transitions between activities
076: String toFireDep = prjSession.addEdge("evaluate_damage",
077: "contact_fire_department");
078: String toPolice = prjSession.addEdge("evaluate_damage",
079: "contact_police");
080: String toHospital = prjSession.addEdge("evaluate_damage",
081: "contact_hospital");
082:
083: // Add a Project Property and set transition conditions
084: prjSession.setNodeProperty("evaluate_damage",
085: "call_fire_department", "false", false);
086: prjSession.setNodeProperty("evaluate_damage",
087: "call_police", "true", false);
088: prjSession.setNodeProperty("evaluate_damage",
089: "call_hospital", "true", false);
090: prjSession.setEdgeCondition(toFireDep,
091: "call_fire_department.equals(\"true\")");
092: prjSession.setEdgeCondition(toPolice,
093: "call_police.equals(\"true\")");
094: prjSession.setEdgeCondition(toHospital,
095: "call_hospital.equals(\"true\")");
096:
097: // Add and set a role for the user admin to execute the activities
098: prjSession.addRole("Executor",
099: "Rol that enables to execute the activities");
100: prjSession.setUserRole("admin", "Executor");
101: prjSession.setNodeRole("evaluate_damage", "Executor");
102: prjSession.setNodeRole("contact_fire_department",
103: "Executor");
104: prjSession.setNodeRole("contact_police", "Executor");
105: prjSession.setNodeRole("contact_hospital", "Executor");
106:
107: // Check model definition
108: prjSession.checkModelDefinition();
109:
110: System.out.println(" [ OK ]");
111: } catch (Exception e) {
112: System.out.println("\n\n [ ERROR ] : " + e);
113: e.printStackTrace();
114: } // Maybe something is wrong
115: }
116: }
|