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 Extra 2 : Cancel Path
024: * Author : Jordi Anguela
025: * Date : 2006/03/01
026: --------------------------------------------------------------------------
027: * Example
028: * This example shows a cancel in cascade. A hook is lunched before
029: * terminating 'split' activity cancelling 'A1'. Then, activities 'A2'
030: * and 'A3' are automaticaly cancelled due to they are reachable.
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 PatternExtra2CancelPath {
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 Extra 2 - Cancel Path");
059: prjSession.initModel("Pattern Extra 2 - Cancel Path");
060:
061: // Add activities and set them to Non anticipable
062: prjSession.addNode("split",
063: hero.interfaces.Constants.Nd.AND_JOIN_NODE);
064: prjSession.addNode("A1",
065: hero.interfaces.Constants.Nd.AND_JOIN_NODE);
066: prjSession.addNode("A2",
067: hero.interfaces.Constants.Nd.AND_JOIN_NODE);
068: prjSession.addNode("A3",
069: hero.interfaces.Constants.Nd.AND_JOIN_NODE);
070: prjSession.addNode("B1",
071: hero.interfaces.Constants.Nd.AND_JOIN_NODE);
072: prjSession.setNodeTraditional("split");
073: prjSession.setNodeTraditional("A1");
074: prjSession.setNodeTraditional("A2");
075: prjSession.setNodeTraditional("A3");
076: prjSession.setNodeTraditional("B1");
077:
078: // Add transitions between activities
079: prjSession.addEdge("split", "A1");
080: prjSession.addEdge("A1", "A2");
081: prjSession.addEdge("A2", "A3");
082: prjSession.addEdge("split", "B1");
083:
084: // Add Hook to 'split' to cancel the 'A1'. 'A2' and 'A3' activities will be cancelled automaticaly
085: String cancelScript = "import hero.interfaces.*; \n"
086: + "afterTerminate(Object engine, Object currentNode) { \n"
087: + " UserSessionHome userHome = UserSessionUtil.getHome(); \n"
088: + " UserSession userSession = userHome.create(); \n"
089: + " userSession.cancelActivity(currentNode.getBnProject().getName(), \"A1\"); \n "
090: + "}";
091: prjSession.addNodeInterHook("split", "split Hook",
092: hero.interfaces.Constants.Nd.AFTERTERMINATE,
093: hero.interfaces.Constants.Hook.BSINTERACTIVE,
094: cancelScript);
095:
096: // Add and set a role for the user admin to execute the activities
097: prjSession.addRole("Executor",
098: "Rol that enables to execute the activities");
099: prjSession.setUserRole("admin", "Executor");
100: prjSession.setNodeRole("split", "Executor");
101: prjSession.setNodeRole("A1", "Executor");
102: prjSession.setNodeRole("A2", "Executor");
103: prjSession.setNodeRole("A3", "Executor");
104: prjSession.setNodeRole("B1", "Executor");
105:
106: // Check model definition
107: prjSession.checkModelDefinition();
108:
109: System.out.println(" [ OK ]");
110: } catch (Exception e) {
111: System.out.println("\n\n [ ERROR ] : " + e);
112: e.printStackTrace();
113: } // Maybe something is wrong
114: }
115: }
|