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 10 : Arbitrary Cycles (Extra Entry Point)
024: * Author : Jordi Anguela
025: * Date : 2006/03/01
026: --------------------------------------------------------------------------
027: * Example
028: --------------------------------------------------------------------------
029: */package hero.client.samples.patterns.src;
030:
031: import hero.client.test.SimpleCallbackHandler;
032: import hero.interfaces.ProjectSession;
033: import hero.interfaces.ProjectSessionHome;
034: import hero.interfaces.ProjectSessionUtil;
035:
036: import javax.security.auth.login.LoginContext;
037:
038: public class Pattern10ArbitraryCycles2ExtraEntryPoint {
039:
040: public static void main(String[] args) {
041: try {
042: // User Admin login
043: char[] password = { 't', 'o', 't', 'o' };
044: SimpleCallbackHandler handler = new SimpleCallbackHandler(
045: "admin", password);
046: LoginContext lc = new LoginContext("TestClient", handler);
047: lc.login();
048:
049: // Project Session Bean creation
050: ProjectSessionHome prjHome = (ProjectSessionHome) ProjectSessionUtil
051: .getHome();
052: ProjectSession prjSession = prjHome.create();
053:
054: // Model creation
055: System.out
056: .print("\n Pattern 10 - Arbitrary Cycles (Extra Entry Point)");
057: prjSession
058: .initModel("Pattern 10 - Arbitrary Cycles (Extra Entry Point)");
059:
060: // Add activities and set them to Non anticipable
061: prjSession.addNode("request_demand",
062: hero.interfaces.Constants.Nd.AND_JOIN_NODE);
063: prjSession.addNode("send_possible_options",
064: hero.interfaces.Constants.Nd.AND_JOIN_NODE);
065: prjSession.addNode("approve_demand",
066: hero.interfaces.Constants.Nd.AND_JOIN_NODE);
067: prjSession.addNode("process_demand",
068: hero.interfaces.Constants.Nd.AND_JOIN_NODE);
069: prjSession.setNodeTraditional("request_demand");
070: prjSession.setNodeTraditional("send_possible_options");
071: prjSession.setNodeTraditional("approve_demand");
072: prjSession.setNodeTraditional("process_demand");
073:
074: // Add transitions between activities
075: prjSession.addEdge("request_demand", "approve_demand");
076: prjSession.addEdge("send_possible_options",
077: "approve_demand");
078: String fromApproveToProcess = prjSession.addEdge(
079: "approve_demand", "process_demand");
080:
081: // Add Project Properties and set transition conditions
082: prjSession.setProperty("approved", "false");
083: prjSession.setProperty("iterations", "1");
084: prjSession.setEdgeCondition(fromApproveToProcess,
085: "approved.equals(\"true\")");
086:
087: // Add iteration
088: prjSession.addIteration("approve_demand", "request_demand",
089: "approved.equals(\"false\")");
090:
091: // Add Hook to Approve activity to iterate twice and then accept the demand
092: String approveHookScript = "import hero.interfaces.*;\n"
093: + "beforeTerminate(Object engine, Object currentNode) {\n\n\n"
094: + " hero.interfaces.ProjectSessionHome pHome = (hero.interfaces.ProjectSessionHome) hero.interfaces.ProjectSessionUtil.getHome(); \n"
095: + " hero.interfaces.ProjectSession prjSession = pHome.create(); \n"
096: + " prjSession.initModel(currentNode.getBnProject().getName()); \n"
097: + " BnProjectPropertyValue propIterations = prjSession.getProperty(\"iterations\"); \n"
098: + " int it= Integer.parseInt(propIterations.getTheValue()); \n"
099: + " if ( it > 0 ) { \n"
100: + " it--; \n"
101: + " prjSession.setProperty(\"iterations\", Integer.toString(it)); \n"
102: + " } else { \n "
103: + " prjSession.setProperty(\"approved\", \"true\"); \n"
104: + " } \n" + "}";
105: prjSession.addNodeInterHook("approve_demand",
106: "Approve Hook",
107: hero.interfaces.Constants.Nd.BEFORETERMINATE,
108: hero.interfaces.Constants.Hook.BSINTERACTIVE,
109: approveHookScript);
110:
111: // Add and set a role for the user admin to execute the activities
112: prjSession.addRole("Executor",
113: "Rol that enables to execute the activities");
114: prjSession.setUserRole("admin", "Executor");
115: prjSession.setNodeRole("request_demand", "Executor");
116: prjSession.setNodeRole("send_possible_options", "Executor");
117: prjSession.setNodeRole("approve_demand", "Executor");
118: prjSession.setNodeRole("process_demand", "Executor");
119:
120: // Check model definition
121: prjSession.checkModelDefinition();
122:
123: System.out.println(" [ OK ]");
124: } catch (Exception e) {
125: System.out.println("\n\n [ ERROR ] : " + e);
126: e.printStackTrace();
127: } // Maybe something is wrong
128: }
129: }
|