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: Sample1CreateSubProcessModel.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 Sample1CreateSubProcessModel {
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 "Customer Service "
050: // It will be used as Sub Process in our complete Order Processing Project
051:
052: // Collaboration Project Session Bean Creation using Remote Interface
053: ProjectSessionHome prjHome = (ProjectSessionHome) ProjectSessionUtil
054: .getHome();
055: ProjectSession prjSession = prjHome.create();
056:
057: // Customer Service project creation
058: prjSession.initModel("Customer Service");
059:
060: //Process Model creation by user admin
061: // Activities creation : non anticipative : traditional execution mode)
062: // Two activities are created : "Ask Customer" and "Notify Sales"
063: prjSession.addNode("Ask Customer", Constants.Nd.AND_JOIN_NODE);
064: prjSession.setNodeTraditional("Ask Customer");
065:
066: prjSession.addNode("Notify Sales", Constants.Nd.AND_JOIN_NODE);
067: prjSession.setNodeTraditional("Notify Sales");
068:
069: // Activities connection : Set edges between nodes
070: prjSession.addEdge("Ask Customer", "Notify Sales");
071:
072: // Set node hook
073: // First hook is in charge of printing information
074: String scriptHook1 = "import hero.interfaces.*;\n"
075: + "import hero.interfaces.BnNodeLocal;\n"
076: + "afterStart (Object b,Object n) {\n\n\n"
077: + "System.out.println(\"customer name: \"+ customer_name);"
078: + "System.out.println(\"product name: \"+ product_name);"
079: + "System.out.println(\"items : \"+ items );" + "}";
080: prjSession.addNodeInterHook("Ask Customer", "order data",
081: Constants.Nd.AFTERSTART, Constants.Hook.BSINTERACTIVE,
082: scriptHook1);
083: // second hook is in charge of creating a new property containing the user order confirmation choice :
084: // partial_sales_status
085: String scriptHook2 = " import hero.interfaces.* ;"
086: + "import hero.interfaces.BnNodeLocal;\n"
087: + "afterTerminate (Object b,Object n) {\n\n\n"
088: + "System.out.println(\"partial_sales_status = OK\"); \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: + "subProcess.setProperty(\"partial_sales_status\",\"ok\"); \n"
093: + "}";
094: prjSession.addNodeInterHook("Notify Sales", "Set property",
095: Constants.Nd.AFTERTERMINATE,
096: Constants.Hook.BSINTERACTIVE, scriptHook2);
097:
098: // Add roles to this process
099: prjSession.addRole("agent", "Customer Service agent");
100: prjSession.addRole("customer", "Sales order customer");
101:
102: // specify role for each node
103: prjSession.setNodeRole("Ask Customer", "customer");
104: prjSession.setNodeRole("Notify Sales", "agent");
105:
106: // Use Mappers for the role resolution
107: prjSession.addRoleMapper("agent",
108: "hero.mapper.Sample1CustomAgentGroupMembers",
109: Constants.Mapper.CUSTOM);
110: prjSession.addRoleMapper("customer",
111: "hero.mapper.Sample1CustomCustomerGroupMembers",
112: Constants.Mapper.CUSTOM);
113: }
114:
115: }
|