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: --------------------------------------------------------------------------
025: * $Id: Sample1CreateProcessModel.java,v 1.3 2004/11/10 17:10:50 mvaldes Exp $
026: *
027: --------------------------------------------------------------------------
028: */package hero.client.samples;
029:
030: import javax.security.auth.login.LoginContext;
031: import hero.client.test.SimpleCallbackHandler;
032:
033: import hero.interfaces.ProjectSession;
034: import hero.interfaces.ProjectSessionHome;
035: import hero.interfaces.ProjectSessionUtil;
036:
037: import hero.interfaces.Constants;
038:
039: public class Sample1CreateProcessModel {
040:
041: static public void main(String[] args) throws Exception {
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: // Creation of Bonita Project "Order Processing "
050:
051: // Collaboration Project Session Bean Creation using Remote Interface
052: ProjectSessionHome prjHome = (ProjectSessionHome) ProjectSessionUtil
053: .getHome();
054: ProjectSession prjSession = prjHome.create();
055:
056: // Order Service project creation
057:
058: prjSession.initModel("Order Processing");
059:
060: //Process Model creation by user admin
061: // Activities creation : non anticipative : traditional execution mode)
062:
063: // First activity is created : Receive Order
064: prjSession.addNode("Receive Order", Constants.Nd.AND_JOIN_NODE);
065: prjSession.setNodeTraditional("Receive Order");
066:
067: // Set node properties : customer_name, product_name, items
068: prjSession.setNodeProperty("Receive Order", "once_more", "OK",
069: true);
070: prjSession.setNodeProperty("Receive Order", "customer_name",
071: "", true);
072: prjSession.setNodeProperty("Receive Order", "product_name", "",
073: true);
074: prjSession.setNodeProperty("Receive Order", "items", "", true);
075:
076: // Second Activity creation : Check Stock AutomaticAndJoin activity
077: prjSession.addNode("Check Stock",
078: Constants.Nd.AND_JOIN_AUTOMATIC_NODE);
079: prjSession.setNodeTraditional("Check Stock");
080:
081: // Activities connection : Set edges between nodes
082: prjSession.addEdge("Receive Order", "Check Stock");
083:
084: // Set node hook
085: // This hook (Check Stock Hook)verifies if the user has sent a correct order and set a new property "stock_status" with the value ok or nok
086: String scriptHook = "import hero.interfaces.*;\n"
087: + "import hero.interfaces.BnNodeLocal;\n"
088: + "beforeTerminate (Object b,Object n) {\n"
089: + "hero.interfaces.ProjectSessionLocalHome pHome = (hero.interfaces.ProjectSessionLocalHome) hero.interfaces.ProjectSessionUtil.getLocalHome(); \n"
090: + "hero.interfaces.ProjectSessionLocal subProcess = pHome.create(); \n"
091: + "subProcess.initModel(n.getBnProject().getName()); \n"
092: + "if (customer_name != null && product_name != null && items != null) \n"
093: + "{ System.out.println(\"(Order Processing : Check Stock) Stock Status = OK\"); \n"
094: + " subProcess.setNodeProperty(n.getName(), \"stock_status\",\"ok\",true);\n "
095: + " }\n"
096: + " else \n"
097: + "{ System.out.println(\"(Order Processing : Check Stock) Stock Status = NOK\");\n "
098: + "subProcess.setNodeProperty(n.getName(), \"stock_status\",\"nok\",true); \n"
099: + " }\n" + "}";
100:
101: prjSession.addNodeInterHook("Check Stock", "Check Stock Hook",
102: Constants.Nd.BEFORETERMINATE,
103: Constants.Hook.BSINTERACTIVE, scriptHook);
104:
105: // "Accept Order" subProcess activity creation, attached to "Customer Service" project
106: prjSession
107: .addNodeSubProcess("Accept Order", "Customer Service");
108:
109: // Adds Edge between "Check Stock" and "Accept Order"
110: // and adds a condition to this new edge
111: String edgeStockOrder = prjSession.addEdge("Check Stock",
112: "Accept Order");
113: String condition = "stock_status.equals(\"ok\")";
114: prjSession.setEdgeCondition(edgeStockOrder, condition);
115:
116: // Add two activities connected with "Accept Order", once selected depending on the edge conditions
117: // First
118: prjSession.addNode("Ship & Report",
119: Constants.Nd.AND_JOIN_AUTOMATIC_NODE);
120: prjSession.setNodeTraditional("Ship & Report");
121:
122: // Set node hook
123: // This hook (Ship & Report Hook)just print a message
124: String scriptHookSR = "import hero.interfaces.*;\n"
125: + "import hero.interfaces.BnNodeLocal;\n"
126: + "beforeTerminate (Object b,Object n) {\n"
127: + "hero.interfaces.ProjectSessionLocalHome pHome = (hero.interfaces.ProjectSessionLocalHome) hero.interfaces.ProjectSessionUtil.getLocalHome(); \n"
128: + "hero.interfaces.ProjectSessionLocal subProcess = pHome.create(); \n"
129: + "subProcess.initModel(n.getBnProject().getName()); \n"
130: + "System.out.println(\"(Order Processing : Ship & Report) That's OK\"); \n"
131: + "}";
132:
133: prjSession.addNodeInterHook("Ship & Report",
134: "Ship Report Hook", Constants.Nd.BEFORETERMINATE,
135: Constants.Hook.BSINTERACTIVE, scriptHookSR);
136:
137: String edgeOrderReport = prjSession.addEdge("Accept Order",
138: "Ship & Report");
139: String condition1 = "partial_sales_status.equals(\"ok\")";
140: prjSession.setEdgeCondition(edgeOrderReport, condition1);
141:
142: // second
143: prjSession.addNode("Cancel Order",
144: Constants.Nd.AND_JOIN_AUTOMATIC_NODE);
145: prjSession.setNodeTraditional("Cancel Order");
146:
147: // Set node hook
148: // This hook (Cancel Order Hook)just print a message
149: String scriptHookCO = "import hero.interfaces.*;\n"
150: + "import hero.interfaces.BnNodeLocal;\n"
151: + "beforeTerminate (Object b,Object n) {\n"
152: + "hero.interfaces.ProjectSessionLocalHome pHome = (hero.interfaces.ProjectSessionLocalHome) hero.interfaces.ProjectSessionUtil.getLocalHome(); \n"
153: + "hero.interfaces.ProjectSessionLocal subProcess = pHome.create(); \n"
154: + "subProcess.initModel(n.getBnProject().getName()); \n"
155: + "System.out.println(\"(Order Processing : Cancel Order) That's NOT OK\"); \n"
156: + "}";
157:
158: prjSession.addNodeInterHook("Cancel Order",
159: "Cancel Order Hook", Constants.Nd.BEFORETERMINATE,
160: Constants.Hook.BSINTERACTIVE, scriptHookCO);
161:
162: String edgeOrderCancel = prjSession.addEdge("Accept Order",
163: "Cancel Order");
164: String condition2 = "partial_sales_status.equals(\"nok\")";
165: prjSession.setEdgeCondition(edgeOrderCancel, condition2);
166:
167: // Creates two roles for this process : agent and customer
168: prjSession.addRole("agent", "Customer Service agent");
169: prjSession.addRole("customer", "Sales order customer");
170:
171: // set roles for activities
172: prjSession.setNodeRole("Accept Order", "agent");
173: prjSession.setNodeRole("Check Stock", "agent");
174: prjSession.setNodeRole("Ship & Report", "agent");
175: prjSession.setNodeRole("Cancel Order", "agent");
176: prjSession.setNodeRole("Receive Order", "customer");
177:
178: // Adding iteration from Receive Order and Ship & report
179: // note : this is just as a sample : it is not a good design
180: // when an iteration includes nodes
181: // with many output nodes, as Accept Order is
182: String iterCondition = "once_more.equals(\"OK\")";
183: prjSession.addIteration("Ship & Report", "Receive Order",
184: iterCondition);
185: }
186:
187: }
|