001: /**
002: *
003: * Bonita
004: * Copyright (C) 1999 Bull S.A.
005: * Bull 68 route de versailles 78434 Louveciennes Cedex France
006: * Further information: bonita@objectweb.org
007: *
008: * This library is free software; you can redistribute it and/or
009: * modify it under the terms of the GNU Lesser General Public
010: * License as published by the Free Software Foundation; either
011: * version 2.1 of the License, or any later version.
012: *
013: * This library is distributed in the hope that it will be useful,
014: * but WITHOUT ANY WARRANTY; without even the implied warranty of
015: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
016: * Lesser General Public License for more details.
017: *
018: * You should have received a copy of the GNU Lesser General Public
019: * License along with this library; if not, write to the Free Software
020: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
021: * USA
022: *
023: --------------------------------------------------------------------------
024: * Class IterationInsideIteration.java created by Jordi Anguela - June 2006
025: --------------------------------------------------------------------------
026: */package hero.client.samples.iterations.src;
027:
028: import hero.client.test.SimpleCallbackHandler;
029: import hero.interfaces.Constants;
030: import hero.interfaces.ProjectSession;
031: import hero.interfaces.ProjectSessionHome;
032: import hero.interfaces.ProjectSessionUtil;
033:
034: import javax.security.auth.login.LoginContext;
035:
036: public class IterationInsideIteration {
037: static public void main(String[] args) throws Exception {
038: try {
039: char[] password = { 't', 'o', 't', 'o' };
040: SimpleCallbackHandler handler = new SimpleCallbackHandler(
041: "admin", password);
042: LoginContext lc = new LoginContext("TestClient", handler);
043: lc.login();
044:
045: ProjectSessionHome projectSessionh = ProjectSessionUtil
046: .getHome();
047: ProjectSession ps = projectSessionh.create();
048: System.out
049: .print("\n Creating IterationInsideIteration model");
050: ps.initModel("IterationInsideIteration");
051:
052: // Set Properties
053: ps.setProperty("condition1", "true");
054: ps.setProperty("condition2", "true");
055: ps.setProperty("repetitions1", "2");
056: ps.setProperty("repetitions2", "2");
057:
058: // Set Nodes
059: ps.addNode("A", hero.interfaces.Constants.Nd.AND_JOIN_NODE);
060: ps.addNode("B", hero.interfaces.Constants.Nd.AND_JOIN_NODE);
061: ps.addNode("C", hero.interfaces.Constants.Nd.AND_JOIN_NODE);
062: ps.addNode("D", hero.interfaces.Constants.Nd.AND_JOIN_NODE);
063:
064: ps.setNodeTraditional("A");
065: ps.setNodeTraditional("B");
066: ps.setNodeTraditional("C");
067: ps.setNodeTraditional("D");
068:
069: // Set Edges
070: ps.addEdge("A", "B");
071: String fromBtoC = ps.addEdge("B", "C");
072: String fromCtoD = ps.addEdge("C", "D");
073: ps.setEdgeCondition(fromBtoC,
074: "condition1.equals(\"false\")");
075: ps.setEdgeCondition(fromCtoD,
076: "condition2.equals(\"false\")");
077:
078: // Set Hooks
079: String repeat1Script = "import hero.interfaces.*;\n"
080: + "beforeTerminate(Object b,Object n) {\n\n\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(n.getBnProject().getName()); \n"
084: + " BnProjectPropertyValue repetitions1Prop = prjSession.getProperty(\"repetitions1\"); \n"
085: + " int repetitions1 = Integer.parseInt(repetitions1Prop.getTheValue()); \n"
086: + " repetitions1--; \n"
087: + " if (repetitions1 == 0) { \n"
088: + " prjSession.setProperty(\"repetitions1\", \"2\"); \n"
089: + " prjSession.setProperty(\"condition1\", \"false\"); \n"
090: + " } else { \n "
091: + " prjSession.setProperty(\"repetitions1\", Integer.toString(repetitions1)); \n"
092: + " } \n" + "} \n";
093: ps.addNodeInterHook("B", "Repeat1 hook",
094: Constants.Nd.BEFORETERMINATE,
095: Constants.Hook.BSINTERACTIVE, repeat1Script);
096: ps.addIteration("B", "B", "condition1.equals(\"true\")");
097:
098: String repeat2Script = "import hero.interfaces.*;\n"
099: + "beforeTerminate(Object b,Object n) {\n\n\n"
100: + " hero.interfaces.ProjectSessionHome pHome = (hero.interfaces.ProjectSessionHome) hero.interfaces.ProjectSessionUtil.getHome(); \n"
101: + " hero.interfaces.ProjectSession prjSession = pHome.create(); \n"
102: + " prjSession.initModel(n.getBnProject().getName()); \n"
103: + " BnProjectPropertyValue repetitions2Prop = prjSession.getProperty(\"repetitions2\"); \n"
104: + " int repetitions2 = Integer.parseInt(repetitions2Prop.getTheValue()); \n"
105: + " repetitions2--; \n"
106: + " if (repetitions2 == 0) { \n"
107: + " prjSession.setProperty(\"condition2\", \"false\"); \n"
108: + " } else { \n "
109: + " prjSession.setProperty(\"repetitions2\", Integer.toString(repetitions2)); \n"
110: + " prjSession.setProperty(\"condition1\", \"true\"); \n"
111: + " } \n" + "} \n";
112: ps.addNodeInterHook("C", "Repeat2 hook",
113: Constants.Nd.BEFORETERMINATE,
114: Constants.Hook.BSINTERACTIVE, repeat2Script);
115:
116: // Set Iteration
117: ps.addIteration("C", "A", "condition2.equals(\"true\")");
118:
119: // Set activity roles
120: ps.addRole("Administrator", "The system administator role");
121: ps.setNodeRole("A", "Administrator");
122: ps.setNodeRole("B", "Administrator");
123: ps.setNodeRole("C", "Administrator");
124: ps.setNodeRole("D", "Administrator");
125:
126: // Set role mapper
127: ps.addRoleMapper("Administrator", "AdministratorMapper",
128: Constants.Mapper.PROPERTIES);
129:
130: // Checks if the model is correctly defined
131: ps.checkModelDefinition();
132:
133: System.out.println(" [ OK ]");
134: } catch (Exception e) {
135: System.out.println("\n\n [ ERROR ] : " + e);
136: e.printStackTrace();
137: }
138: }
139: }
|