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 18 : Milestone
024: * Author : Jordi Anguela
025: * Date : 2006/03/01
026: --------------------------------------------------------------------------
027: * Example
028: * In this case we have 3 activities: 'A', 'B' and 'C'. A is only enabled
029: * only if 'B' has been executed and 'C' has not been executed yet.
030: * A trasition from 'B' to 'A' is used to enable 'A' when 'B' is finnishes
031: * its execution
032: * 'C' has a hook that cancels 'A' if it is still ready to disable it.
033: --------------------------------------------------------------------------
034: */package hero.client.samples.patterns.src;
035:
036: import hero.client.test.SimpleCallbackHandler;
037: import hero.interfaces.ProjectSession;
038: import hero.interfaces.ProjectSessionHome;
039: import hero.interfaces.ProjectSessionUtil;
040:
041: import javax.security.auth.login.LoginContext;
042:
043: public class Pattern18Milestone {
044:
045: public static void main(String[] args) {
046: try {
047: // User Admin login
048: char[] password = { 't', 'o', 't', 'o' };
049: SimpleCallbackHandler handler = new SimpleCallbackHandler(
050: "admin", password);
051: LoginContext lc = new LoginContext("TestClient", handler);
052: lc.login();
053:
054: // Project Session Bean creation
055: ProjectSessionHome prjHome = (ProjectSessionHome) ProjectSessionUtil
056: .getHome();
057: ProjectSession prjSession = prjHome.create();
058:
059: // Model creation
060: System.out.print("\n Pattern 18 - Milestone");
061: prjSession.initModel("Pattern 18 - Milestone");
062:
063: // Add activities and set them to Non anticipable
064: prjSession.addNode("B",
065: hero.interfaces.Constants.Nd.AND_JOIN_NODE);
066: prjSession.addNode("A",
067: hero.interfaces.Constants.Nd.AND_JOIN_NODE);
068: prjSession.addNode("C",
069: hero.interfaces.Constants.Nd.AND_JOIN_NODE);
070: prjSession.setNodeTraditional("B");
071: prjSession.setNodeTraditional("A");
072: prjSession.setNodeTraditional("C");
073:
074: // Add transitions between activities
075: prjSession.addEdge("B", "C");
076: prjSession.addEdge("B", "A");
077:
078: // Add Hook to 'C' to cancel the 'A' if it has not executed yet
079: String cancelScript = "import hero.interfaces.*; \n"
080: + "beforeStart(Object engine, Object currentNode) { \n"
081: + " hero.interfaces.ProjectSessionHome pHome = (hero.interfaces.ProjectSessionHome) hero.interfaces.ProjectSessionUtil.getHome(); \n"
082: + " hero.interfaces.ProjectSession prjSession = pHome.create(); \n"
083: + " prjSession.initModel(currentNode.getBnProject().getName()); \n"
084: + " if (prjSession.getNodeState(\"A\") == hero.interfaces.Constants.Nd.READY) { \n"
085: + " UserSessionHome userHome = UserSessionUtil.getHome(); \n"
086: + " UserSession userSession = userHome.create(); \n"
087: + " userSession.cancelActivity(currentNode.getBnProject().getName(), \"A\"); \n "
088: + " } \n" + "}";
089: prjSession.addNodeInterHook("C", "C Hook",
090: hero.interfaces.Constants.Nd.BEFORESTART,
091: hero.interfaces.Constants.Hook.BSINTERACTIVE,
092: cancelScript);
093:
094: // Add and set a role for the user admin to execute the activities
095: prjSession.addRole("Executor",
096: "Rol that enables to execute the activities");
097: prjSession.setUserRole("admin", "Executor");
098: prjSession.setNodeRole("B", "Executor");
099: prjSession.setNodeRole("A", "Executor");
100: prjSession.setNodeRole("C", "Executor");
101:
102: // Check model definition
103: prjSession.checkModelDefinition();
104:
105: System.out.println(" [ OK ]");
106: } catch (Exception e) {
107: System.out.println("\n\n [ ERROR ] : " + e);
108: e.printStackTrace();
109: } // Maybe something is wrong
110: }
111: }
|