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 04 : Exclusive Choice
024: * Author : Jordi Anguela
025: * Date : 2006/03/01
026: --------------------------------------------------------------------------
027: * Example
028: * Activity evaluate_claim is followed by either pay_damage or
029: * contact_customer.
030: --------------------------------------------------------------------------
031: */package hero.client.samples.patterns.src;
032:
033: import hero.client.test.SimpleCallbackHandler;
034: import hero.interfaces.ProjectSession;
035: import hero.interfaces.ProjectSessionHome;
036: import hero.interfaces.ProjectSessionUtil;
037:
038: import javax.security.auth.login.LoginContext;
039:
040: public class Pattern04ExclusiveChoice {
041:
042: public static void main(String[] args) {
043: try {
044: // User Admin login
045: char[] password = { 't', 'o', 't', 'o' };
046: SimpleCallbackHandler handler = new SimpleCallbackHandler(
047: "admin", password);
048: LoginContext lc = new LoginContext("TestClient", handler);
049: lc.login();
050:
051: // Project Session Bean creation
052: ProjectSessionHome prjHome = (ProjectSessionHome) ProjectSessionUtil
053: .getHome();
054: ProjectSession prjSession = prjHome.create();
055:
056: // Model creation
057: System.out.print("\n Pattern 04 - Exclusive Choice");
058: prjSession.initModel("Pattern 04 - Exclusive Choice");
059:
060: // Add activities and set them to Non anticipable
061: prjSession.addNode("evaluate_claim",
062: hero.interfaces.Constants.Nd.AND_JOIN_NODE);
063: prjSession.addNode("pay_damage",
064: hero.interfaces.Constants.Nd.AND_JOIN_NODE);
065: prjSession.addNode("contact_customer",
066: hero.interfaces.Constants.Nd.AND_JOIN_NODE);
067: prjSession.setNodeTraditional("evaluate_claim");
068: prjSession.setNodeTraditional("pay_damage");
069: prjSession.setNodeTraditional("contact_customer");
070:
071: // Add transitions between activities
072: String fromEvaluateToPay = prjSession.addEdge(
073: "evaluate_claim", "pay_damage");
074: String fromEvaluateToContact = prjSession.addEdge(
075: "evaluate_claim", "contact_customer");
076:
077: // Add a node property and set transition conditions
078: prjSession.setNodeProperty("evaluate_claim", "pay", "true",
079: false);
080: prjSession.setEdgeCondition(fromEvaluateToPay,
081: "pay.equals(\"true\")");
082: prjSession.setEdgeCondition(fromEvaluateToContact,
083: "pay.equals(\"false\")");
084:
085: // Add and set a role for the user admin to execute the activities
086: prjSession.addRole("Executor",
087: "Rol that enables to execute the activities");
088: prjSession.setUserRole("admin", "Executor");
089: prjSession.setNodeRole("evaluate_claim", "Executor");
090: prjSession.setNodeRole("pay_damage", "Executor");
091: prjSession.setNodeRole("contact_customer", "Executor");
092:
093: // Check model definition
094: prjSession.checkModelDefinition();
095:
096: System.out.println(" [ OK ]");
097: } catch (Exception e) {
098: System.out.println("\n\n [ ERROR ] : " + e);
099: e.printStackTrace();
100: } // Maybe something is wrong
101: }
102: }
|