KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > hero > client > samples > Sample1CreateProcessModel


1 /**
2  *
3  * Bonita
4  * Copyright (C) 1999 Bull S.A.
5  * Bull 68 route de versailles 78434 Louveciennes Cedex France
6  * Further information: bonita@objectweb.org
7  *
8  * This library is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Lesser General Public
10  * License as published by the Free Software Foundation; either
11  * version 2.1 of the License, or any later version.
12  *
13  * This library is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  * Lesser General Public License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with this library; if not, write to the Free Software
20  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
21  * USA
22  *
23  *
24 --------------------------------------------------------------------------
25  * $Id: Sample1CreateProcessModel.java,v 1.3 2004/11/10 17:10:50 mvaldes Exp $
26  *
27 --------------------------------------------------------------------------
28  */

29
30 package hero.client.samples;
31
32 import javax.security.auth.login.LoginContext JavaDoc;
33 import hero.client.test.SimpleCallbackHandler;
34
35 import hero.interfaces.ProjectSession;
36 import hero.interfaces.ProjectSessionHome;
37 import hero.interfaces.ProjectSessionUtil;
38
39 import hero.interfaces.Constants;
40
41
42 public class Sample1CreateProcessModel {
43     
44     static public void main(String JavaDoc[] args) throws Exception JavaDoc{
45       // User Admin login
46
char[] password={'t','o','t','o'};
47       SimpleCallbackHandler handler = new SimpleCallbackHandler("admin",password);
48       LoginContext JavaDoc lc = new LoginContext JavaDoc("TestClient", handler);
49       lc.login();
50
51       // Creation of Bonita Project "Order Processing "
52

53       // Collaboration Project Session Bean Creation using Remote Interface
54
ProjectSessionHome prjHome= (ProjectSessionHome) ProjectSessionUtil.getHome();
55       ProjectSession prjSession = prjHome.create();
56       
57       // Order Service project creation
58

59       prjSession.initModel("Order Processing");
60       
61       //Process Model creation by user admin
62
// Activities creation : non anticipative : traditional execution mode)
63

64       // First activity is created : Receive Order
65
prjSession.addNode("Receive Order",Constants.Nd.AND_JOIN_NODE);
66       prjSession.setNodeTraditional("Receive Order");
67       
68       // Set node properties : customer_name, product_name, items
69
prjSession.setNodeProperty("Receive Order","once_more","OK",true);
70       prjSession.setNodeProperty("Receive Order","customer_name","",true);
71       prjSession.setNodeProperty("Receive Order","product_name","",true);
72       prjSession.setNodeProperty("Receive Order","items","",true);
73       
74       // Second Activity creation : Check Stock AutomaticAndJoin activity
75
prjSession.addNode("Check Stock",Constants.Nd.AND_JOIN_AUTOMATIC_NODE );
76       prjSession.setNodeTraditional("Check Stock");
77       
78       
79       // Activities connection : Set edges between nodes
80
prjSession.addEdge("Receive Order","Check Stock");
81      
82       // Set node hook
83
// 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
84
String JavaDoc scriptHook =
85               "import hero.interfaces.*;\n"
86                   + "import hero.interfaces.BnNodeLocal;\n"
87                   + "beforeTerminate (Object b,Object n) {\n"
88                   + "hero.interfaces.ProjectSessionLocalHome pHome = (hero.interfaces.ProjectSessionLocalHome) hero.interfaces.ProjectSessionUtil.getLocalHome(); \n"
89                   + "hero.interfaces.ProjectSessionLocal subProcess = pHome.create(); \n"
90                   + "subProcess.initModel(n.getBnProject().getName()); \n"
91                   + "if (customer_name != null && product_name != null && items != null) \n"
92                   + "{ System.out.println(\"(Order Processing : Check Stock) Stock Status = OK\"); \n"
93                   + " subProcess.setNodeProperty(n.getName(), \"stock_status\",\"ok\",true);\n "
94                   + " }\n"
95                   + " else \n"
96                   + "{ System.out.println(\"(Order Processing : Check Stock) Stock Status = NOK\");\n "
97                   + "subProcess.setNodeProperty(n.getName(), \"stock_status\",\"nok\",true); \n"
98                   + " }\n"
99                   + "}";
100             
101       prjSession.addNodeInterHook("Check Stock","Check Stock Hook",Constants.Nd.BEFORETERMINATE,Constants.Hook.BSINTERACTIVE,scriptHook);
102
103     // "Accept Order" subProcess activity creation, attached to "Customer Service" project
104
prjSession.addNodeSubProcess("Accept Order","Customer Service");
105
106     // Adds Edge between "Check Stock" and "Accept Order"
107
// and adds a condition to this new edge
108
String JavaDoc edgeStockOrder = prjSession.addEdge("Check Stock","Accept Order");
109     String JavaDoc condition = "stock_status.equals(\"ok\")";
110     prjSession.setEdgeCondition(edgeStockOrder,condition);
111     
112     // Add two activities connected with "Accept Order", once selected depending on the edge conditions
113
// First
114
prjSession.addNode("Ship & Report",Constants.Nd.AND_JOIN_AUTOMATIC_NODE );
115     prjSession.setNodeTraditional("Ship & Report");
116     
117     // Set node hook
118
// This hook (Ship & Report Hook)just print a message
119
String JavaDoc scriptHookSR =
120               "import hero.interfaces.*;\n"
121                   + "import hero.interfaces.BnNodeLocal;\n"
122                   + "beforeTerminate (Object b,Object n) {\n"
123                   + "hero.interfaces.ProjectSessionLocalHome pHome = (hero.interfaces.ProjectSessionLocalHome) hero.interfaces.ProjectSessionUtil.getLocalHome(); \n"
124                   + "hero.interfaces.ProjectSessionLocal subProcess = pHome.create(); \n"
125                   + "subProcess.initModel(n.getBnProject().getName()); \n"
126                   + "System.out.println(\"(Order Processing : Ship & Report) That's OK\"); \n"
127                   + "}" ;
128                               
129     prjSession.addNodeInterHook("Ship & Report","Ship Report Hook",Constants.Nd.BEFORETERMINATE,Constants.Hook.BSINTERACTIVE,scriptHookSR);
130
131     
132     String JavaDoc edgeOrderReport = prjSession.addEdge("Accept Order","Ship & Report");
133     String JavaDoc condition1 = "partial_sales_status.equals(\"ok\")";
134     prjSession.setEdgeCondition(edgeOrderReport,condition1);
135         
136     // second
137
prjSession.addNode("Cancel Order",Constants.Nd.AND_JOIN_AUTOMATIC_NODE );
138     prjSession.setNodeTraditional("Cancel Order");
139     
140     // Set node hook
141
// This hook (Cancel Order Hook)just print a message
142
String JavaDoc scriptHookCO =
143               "import hero.interfaces.*;\n"
144                   + "import hero.interfaces.BnNodeLocal;\n"
145                   + "beforeTerminate (Object b,Object n) {\n"
146                   + "hero.interfaces.ProjectSessionLocalHome pHome = (hero.interfaces.ProjectSessionLocalHome) hero.interfaces.ProjectSessionUtil.getLocalHome(); \n"
147                   + "hero.interfaces.ProjectSessionLocal subProcess = pHome.create(); \n"
148                   + "subProcess.initModel(n.getBnProject().getName()); \n"
149                   + "System.out.println(\"(Order Processing : Cancel Order) That's NOT OK\"); \n"
150                   + "}" ;
151             
152     prjSession.addNodeInterHook("Cancel Order","Cancel Order Hook",Constants.Nd.BEFORETERMINATE,Constants.Hook.BSINTERACTIVE,scriptHookCO);
153
154     
155     
156     
157     
158     String JavaDoc edgeOrderCancel = prjSession.addEdge("Accept Order","Cancel Order");
159     String JavaDoc condition2 = "partial_sales_status.equals(\"nok\")";
160     prjSession.setEdgeCondition(edgeOrderCancel,condition2);
161     
162       // Creates two roles for this process : agent and customer
163
prjSession.addRole("agent","Customer Service agent");
164       prjSession.addRole("customer","Sales order customer");
165       
166       // set roles for activities
167
prjSession.setNodeRole("Accept Order","agent");
168       prjSession.setNodeRole("Check Stock","agent");
169       prjSession.setNodeRole("Ship & Report","agent");
170       prjSession.setNodeRole("Cancel Order","agent");
171       prjSession.setNodeRole("Receive Order","customer");
172
173
174       // Adding iteration from Receive Order and Ship & report
175
// note : this is just as a sample : it is not a good design
176
// when an iteration includes nodes
177
// with many output nodes, as Accept Order is
178
String JavaDoc iterCondition="once_more.equals(\"OK\")" ;
179       prjSession.addIteration("Ship & Report","Receive Order",iterCondition);
180     }
181       
182     
183 }
184
185
186
Popular Tags