KickJava   Java API By Example, From Geeks To Geeks.

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


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: Sample1CreateSubProcessModel.java,v 1.3 2004/11/10 17:10:50 mvaldes Exp $
26  *
27 --------------------------------------------------------------------------
28  */

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

52       // Collaboration Project Session Bean Creation using Remote Interface
53
ProjectSessionHome prjHome= (ProjectSessionHome) ProjectSessionUtil.getHome();
54       ProjectSession prjSession = prjHome.create();
55       
56       // Customer Service project creation
57
prjSession.initModel("Customer Service");
58       
59       //Process Model creation by user admin
60
// Activities creation : non anticipative : traditional execution mode)
61
// Two activities are created : "Ask Customer" and "Notify Sales"
62
prjSession.addNode("Ask Customer",Constants.Nd.AND_JOIN_NODE);
63       prjSession.setNodeTraditional("Ask Customer");
64       
65       prjSession.addNode("Notify Sales",Constants.Nd.AND_JOIN_NODE);
66       prjSession.setNodeTraditional("Notify Sales");
67       
68       
69       // Activities connection : Set edges between nodes
70
prjSession.addEdge("Ask Customer","Notify Sales");
71      
72      
73       // Set node hook
74
// First hook is in charge of printing information
75
String JavaDoc scriptHook1 =
76               "import hero.interfaces.*;\n"
77                   + "import hero.interfaces.BnNodeLocal;\n"
78                   + "afterStart (Object b,Object n) {\n\n\n"
79                   + "System.out.println(\"customer name: \"+ customer_name);"
80                   + "System.out.println(\"product name: \"+ product_name);"
81                   + "System.out.println(\"items : \"+ items );"
82                   + "}";
83       prjSession.addNodeInterHook("Ask Customer","order data",Constants.Nd.AFTERSTART,Constants.Hook.BSINTERACTIVE,scriptHook1);
84       // second hook is in charge of creating a new property containing the user order confirmation choice :
85
// partial_sales_status
86
String JavaDoc scriptHook2 =
87             " import hero.interfaces.* ;"
88                 + "import hero.interfaces.BnNodeLocal;\n"
89                 + "afterTerminate (Object b,Object n) {\n\n\n"
90                     + "System.out.println(\"partial_sales_status = OK\"); \n"
91                     + "hero.interfaces.ProjectSessionLocalHome pHome = (hero.interfaces.ProjectSessionLocalHome) hero.interfaces.ProjectSessionUtil.getLocalHome(); \n"
92                     + "hero.interfaces.ProjectSessionLocal subProcess = pHome.create(); \n"
93                     + "subProcess.initModel(n.getBnProject().getName()); \n"
94                     + "subProcess.setProperty(\"partial_sales_status\",\"ok\"); \n"
95                 +"}" ;
96       prjSession.addNodeInterHook("Notify Sales","Set property",Constants.Nd.AFTERTERMINATE,Constants.Hook.BSINTERACTIVE,scriptHook2);
97       
98       
99       // Add roles to this process
100
prjSession.addRole("agent","Customer Service agent");
101       prjSession.addRole("customer","Sales order customer");
102
103       // specify role for each node
104
prjSession.setNodeRole("Ask Customer","customer");
105       prjSession.setNodeRole("Notify Sales","agent");
106
107
108       // Use Mappers for the role resolution
109
prjSession.addRoleMapper("agent","hero.mapper.Sample1CustomAgentGroupMembers",Constants.Mapper.CUSTOM);
110       prjSession.addRoleMapper("customer","hero.mapper.Sample1CustomCustomerGroupMembers",Constants.Mapper.CUSTOM);
111     }
112       
113     
114 }
115
116
117
Popular Tags