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 07 : Synchronizing Merge
024: * Author : Jordi Anguela
025: * Date : 2006/03/01
026: --------------------------------------------------------------------------
027: * Example
028: * The idea of this simple example is create a new activity (contact_both)
029: * that executes both contact_fire_department and contact_insurance
030: * activities.
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 Pattern07SynchronizingMerge {
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 07 - Synchronizing Merge");
059: prjSession.initModel("Pattern 07 - Synchronizing Merge");
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_insurance",
067: hero.interfaces.Constants.Nd.AND_JOIN_NODE);
068: prjSession.addNode("contact_both",
069: hero.interfaces.Constants.Nd.AND_JOIN_NODE);
070: prjSession.addNode("submit_report",
071: hero.interfaces.Constants.Nd.OR_JOIN_NODE);
072: prjSession.setNodeTraditional("evaluate_damage");
073: prjSession.setNodeTraditional("contact_fire_department");
074: prjSession.setNodeTraditional("contact_insurance");
075: prjSession.setNodeTraditional("contact_both");
076: prjSession.setNodeTraditional("submit_report");
077:
078: // Add transitions between activities
079: String toFireDep = prjSession.addEdge("evaluate_damage",
080: "contact_fire_department");
081: String toInsurance = prjSession.addEdge("evaluate_damage",
082: "contact_insurance");
083: String toBoth = prjSession.addEdge("evaluate_damage",
084: "contact_both");
085: prjSession.addEdge("contact_fire_department",
086: "submit_report");
087: prjSession.addEdge("contact_insurance", "submit_report");
088: prjSession.addEdge("contact_both", "submit_report");
089:
090: // Add Project Properties and set transition conditions
091: prjSession.setProperty("call_fire_department", "true");
092: prjSession.setProperty("call_insurance", "true");
093: prjSession
094: .setEdgeCondition(toFireDep,
095: "(call_fire_department.equals(\"true\") && call_insurance.equals(\"false\"))");
096: prjSession
097: .setEdgeCondition(toInsurance,
098: "(call_insurance.equals(\"true\") && call_fire_department.equals(\"false\"))");
099: prjSession
100: .setEdgeCondition(toBoth,
101: "(call_insurance.equals(\"true\") && call_fire_department.equals(\"true\"))");
102:
103: // Add and set a role for the user admin to execute the activities
104: prjSession.addRole("Executor",
105: "Rol that enables to execute the activities");
106: prjSession.setUserRole("admin", "Executor");
107: prjSession.setNodeRole("evaluate_damage", "Executor");
108: prjSession.setNodeRole("contact_fire_department",
109: "Executor");
110: prjSession.setNodeRole("contact_insurance", "Executor");
111: prjSession.setNodeRole("contact_both", "Executor");
112: prjSession.setNodeRole("submit_report", "Executor");
113:
114: // Check model definition
115: prjSession.checkModelDefinition();
116:
117: System.out.println(" [ OK ]");
118: } catch (Exception e) {
119: System.out.println("\n\n [ ERROR ] : " + e);
120: e.printStackTrace();
121: } // Maybe something is wrong
122: }
123: }
|