Source Code Cross Referenced for Pattern17InterleavedParallelRouting.java in  » Workflow-Engines » bonita-v3.1 » hero » client » samples » patterns » src » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Workflow Engines » bonita v3.1 » hero.client.samples.patterns.src 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /**
002:         * Bonita
003:         * Copyright (C) 1999 Bull S.A.
004:         * Bull 68 route de versailles  78434 Louveciennes Cedex France
005:         * Further information: bonita@objectweb.org
006:         *
007:         * This library is free software; you can redistribute it and/or
008:         * modify it under the terms of the GNU Lesser General Public
009:         * License as published by the Free Software Foundation; either
010:         * version 2.1 of the License, or any later version.
011:         *
012:         * This library is distributed in the hope that it will be useful,
013:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
014:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
015:         * Lesser General Public License for more details.
016:         *
017:         * You should have received a copy of the GNU Lesser General Public
018:         * License along with this library; if not, write to the Free Software
019:         * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
020:         * USA
021:        --------------------------------------------------------------------------
022:         * BONITA Workflow Patterns sample
023:         *   Pattern 17 : Interleaved Parallel Routing
024:         *       Author : Jordi Anguela
025:         *         Date : 2006/03/01 
026:        --------------------------------------------------------------------------
027:         * Example
028:         * In this example we have 3 activies: physical_test, mental_test and
029:         * skill_test that we want to execute but not at the same time.
030:         * We will use an iteration to execute the three activities and after
031:         * that continues the process execution.
032:        --------------------------------------------------------------------------
033:         */package hero.client.samples.patterns.src;
034:
035:        import hero.client.test.SimpleCallbackHandler;
036:        import hero.interfaces.ProjectSession;
037:        import hero.interfaces.ProjectSessionHome;
038:        import hero.interfaces.ProjectSessionUtil;
039:
040:        import javax.security.auth.login.LoginContext;
041:
042:        public class Pattern17InterleavedParallelRouting {
043:
044:            public static void main(String[] args) {
045:                try {
046:                    // User Admin login
047:                    char[] password = { 't', 'o', 't', 'o' };
048:                    SimpleCallbackHandler handler = new SimpleCallbackHandler(
049:                            "admin", password);
050:                    LoginContext lc = new LoginContext("TestClient", handler);
051:                    lc.login();
052:
053:                    // Project Session Bean creation
054:                    ProjectSessionHome prjHome = (ProjectSessionHome) ProjectSessionUtil
055:                            .getHome();
056:                    ProjectSession prjSession = prjHome.create();
057:
058:                    // Model creation 
059:                    System.out
060:                            .print("\n   Pattern 17 - Interleaved Parallel Routing");
061:                    prjSession
062:                            .initModel("Pattern 17 - Interleaved Parallel Routing");
063:
064:                    // Add activities and set them to Non anticipable
065:                    prjSession.addNode("select_avaliable_test",
066:                            hero.interfaces.Constants.Nd.AND_JOIN_NODE);
067:                    prjSession.addNode("physical_test",
068:                            hero.interfaces.Constants.Nd.AND_JOIN_NODE);
069:                    prjSession.addNode("mental_test",
070:                            hero.interfaces.Constants.Nd.AND_JOIN_NODE);
071:                    prjSession.addNode("skill_test",
072:                            hero.interfaces.Constants.Nd.AND_JOIN_NODE);
073:                    prjSession.addNode("decide",
074:                            hero.interfaces.Constants.Nd.OR_JOIN_NODE);
075:                    prjSession.addNode("tests_report",
076:                            hero.interfaces.Constants.Nd.AND_JOIN_NODE);
077:                    prjSession.setNodeTraditional("select_avaliable_test");
078:                    prjSession.setNodeTraditional("physical_test");
079:                    prjSession.setNodeTraditional("mental_test");
080:                    prjSession.setNodeTraditional("skill_test");
081:                    prjSession.setNodeTraditional("decide");
082:                    prjSession.setNodeTraditional("tests_report");
083:
084:                    // Add transitions between activities
085:                    String toPhysicalTest = prjSession.addEdge(
086:                            "select_avaliable_test", "physical_test");
087:                    String toMentalTest = prjSession.addEdge(
088:                            "select_avaliable_test", "mental_test");
089:                    String toSkillTest = prjSession.addEdge(
090:                            "select_avaliable_test", "skill_test");
091:                    prjSession.addEdge("physical_test", "decide");
092:                    prjSession.addEdge("mental_test", "decide");
093:                    prjSession.addEdge("skill_test", "decide");
094:                    String toTestReport = prjSession.addEdge("decide",
095:                            "tests_report");
096:
097:                    // Add a Project Property and set transition conditions
098:                    prjSession.setProperty("test", "");
099:                    prjSession.setProperty("physical_test", "not_passed");
100:                    prjSession.setProperty("mental_test", "not_passed");
101:                    prjSession.setProperty("skill_test", "not_passed");
102:                    prjSession.setEdgeCondition(toPhysicalTest,
103:                            "test.equals(\"1\")");
104:                    prjSession.setEdgeCondition(toMentalTest,
105:                            "test.equals(\"2\")");
106:                    prjSession.setEdgeCondition(toSkillTest,
107:                            "test.equals(\"3\")");
108:                    prjSession
109:                            .setEdgeCondition(
110:                                    toTestReport,
111:                                    "physical_test.equals(\"passed\") && mental_test.equals(\"passed\") && skill_test.equals(\"passed\")");
112:
113:                    // Add hook that simulates the avaliability of the tests
114:                    String simulateAvalibilityHookScript = "import hero.interfaces.*;\n"
115:                            + "import java.util.Random; \n"
116:                            + "beforeTerminate(Object engine, Object currentNode) { \n"
117:                            + "  hero.interfaces.ProjectSessionHome pHome = (hero.interfaces.ProjectSessionHome) hero.interfaces.ProjectSessionUtil.getHome(); \n"
118:                            + "  hero.interfaces.ProjectSession prjSession = pHome.create(); \n"
119:                            + "  prjSession.initModel(currentNode.getBnProject().getName()); \n"
120:                            + "  String physicalPassed = prjSession.getProperty(\"physical_test\").getTheValue(); \n"
121:                            + "  String mentalPassed = prjSession.getProperty(\"mental_test\").getTheValue(); \n"
122:                            + "  String skillPassed = prjSession.getProperty(\"skill_test\").getTheValue(); \n"
123:                            + "  Random generator = new Random(System.currentTimeMillis()); \n"
124:                            + "  boolean avaliableTest = false; \n"
125:                            + "  int testNum; \n"
126:                            + "  System.out.println(\" Physical : \" + physicalPassed); \n"
127:                            + "  System.out.println(\"   Mental : \" + mentalPassed); \n"
128:                            + "  System.out.println(\"    Skill : \" + skillPassed); \n"
129:                            + "  while (avaliableTest == false) { \n"
130:                            + "    testNum = generator.nextInt(3) + 1; \n"
131:                            + "    System.out.println(\"    --> Test : \" + testNum); \n"
132:                            + "    if (((testNum == 1) && (physicalPassed.equals(\"not_passed\")))"
133:                            + "        || ((testNum == 2) && (mentalPassed.equals(\"not_passed\")))"
134:                            + "        || ((testNum == 3) && (skillPassed.equals(\"not_passed\")))) { \n"
135:                            + "      avaliableTest = true; \n"
136:                            + "    } \n"
137:                            + "  } \n"
138:                            + "  prjSession.setProperty(\"test\", Integer.toString(testNum)); \n"
139:                            + "  System.out.println(\"    --> Tests remaining : \" + testNum); \n"
140:                            + "} \n";
141:                    prjSession.addNodeInterHook("select_avaliable_test",
142:                            "Select test Hook",
143:                            hero.interfaces.Constants.Nd.BEFORETERMINATE,
144:                            hero.interfaces.Constants.Hook.BSINTERACTIVE,
145:                            simulateAvalibilityHookScript);
146:
147:                    // Add hook that set each test as passed
148:                    String testPassedHookScript = "import hero.interfaces.*;\n"
149:                            + "import java.util.Random; \n"
150:                            + "beforeTerminate(Object engine, Object currentNode) { \n"
151:                            + "  hero.interfaces.ProjectSessionHome pHome = (hero.interfaces.ProjectSessionHome) hero.interfaces.ProjectSessionUtil.getHome(); \n"
152:                            + "  hero.interfaces.ProjectSession prjSession = pHome.create(); \n"
153:                            + "  prjSession.initModel(currentNode.getBnProject().getName()); \n"
154:                            + "  String nodeName = currentNode.getName(); \n"
155:                            + "  prjSession.setProperty(nodeName, \"passed\"); \n"
156:                            + "  System.out.println(\"    --> Test \" + nodeName + \" : passed\"); \n"
157:                            + "} \n";
158:                    prjSession.addNodeInterHook("physical_test",
159:                            "physical_test Hook",
160:                            hero.interfaces.Constants.Nd.BEFORETERMINATE,
161:                            hero.interfaces.Constants.Hook.BSINTERACTIVE,
162:                            testPassedHookScript);
163:                    prjSession.addNodeInterHook("mental_test",
164:                            "mental_test Hook",
165:                            hero.interfaces.Constants.Nd.BEFORETERMINATE,
166:                            hero.interfaces.Constants.Hook.BSINTERACTIVE,
167:                            testPassedHookScript);
168:                    prjSession.addNodeInterHook("skill_test",
169:                            "skill_test Hook",
170:                            hero.interfaces.Constants.Nd.BEFORETERMINATE,
171:                            hero.interfaces.Constants.Hook.BSINTERACTIVE,
172:                            testPassedHookScript);
173:
174:                    // Add iteration until all tests are passed
175:                    prjSession
176:                            .addIteration(
177:                                    "decide",
178:                                    "select_avaliable_test",
179:                                    "(physical_test.equals(\"not_passed\") || mental_test.equals(\"not_passed\") || skill_test.equals(\"not_passed\"))");
180:
181:                    // Add and set a role for the user admin to execute the activities
182:                    prjSession.addRole("Executor",
183:                            "Rol that enables to execute the activities");
184:                    prjSession.setUserRole("admin", "Executor");
185:                    prjSession.setNodeRole("select_avaliable_test", "Executor");
186:                    prjSession.setNodeRole("physical_test", "Executor");
187:                    prjSession.setNodeRole("mental_test", "Executor");
188:                    prjSession.setNodeRole("skill_test", "Executor");
189:                    prjSession.setNodeRole("decide", "Executor");
190:                    prjSession.setNodeRole("tests_report", "Executor");
191:
192:                    // Check model definition
193:                    prjSession.checkModelDefinition();
194:
195:                    System.out.println("   [ OK ]");
196:                } catch (Exception e) {
197:                    System.out.println("\n\n   [ ERROR ] : " + e);
198:                    e.printStackTrace();
199:                } // Maybe something is wrong
200:            }
201:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.