Source Code Cross Referenced for Pattern16DeferredChoice.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 16 : Deferred Choice
024:         *       Author : Jordi Anguela
025:         *         Date : 2006/03/01 
026:        --------------------------------------------------------------------------
027:         * Example
028:         * In this example we have two activities avaliable: load_truck1 and 
029:         * load_truck2. select_avaliable_resource activity has hook that decides 
030:         * which truck is avaliable (the decision is taken at random using a hook) 
031:        --------------------------------------------------------------------------
032:         */package hero.client.samples.patterns.src;
033:
034:        import hero.client.test.SimpleCallbackHandler;
035:        import hero.interfaces.ProjectSession;
036:        import hero.interfaces.ProjectSessionHome;
037:        import hero.interfaces.ProjectSessionUtil;
038:
039:        import javax.security.auth.login.LoginContext;
040:
041:        public class Pattern16DeferredChoice {
042:
043:            public static void main(String[] args) {
044:                try {
045:                    // User Admin login
046:                    char[] password = { 't', 'o', 't', 'o' };
047:                    SimpleCallbackHandler handler = new SimpleCallbackHandler(
048:                            "admin", password);
049:                    LoginContext lc = new LoginContext("TestClient", handler);
050:                    lc.login();
051:
052:                    // Project Session Bean creation
053:                    ProjectSessionHome prjHome = (ProjectSessionHome) ProjectSessionUtil
054:                            .getHome();
055:                    ProjectSession prjSession = prjHome.create();
056:
057:                    // Model creation 
058:                    System.out.print("\n   Pattern 16 - Deferred Choice");
059:                    prjSession.initModel("Pattern 16 - Deferred Choice");
060:
061:                    // Add activities and set them to Non anticipable
062:                    prjSession.addNode("select_avaliable_resource",
063:                            hero.interfaces.Constants.Nd.AND_JOIN_NODE);
064:                    prjSession.addNode("load_truck1",
065:                            hero.interfaces.Constants.Nd.AND_JOIN_NODE);
066:                    prjSession.addNode("load_truck2",
067:                            hero.interfaces.Constants.Nd.AND_JOIN_NODE);
068:                    prjSession.setNodeTraditional("select_avaliable_resource");
069:                    prjSession.setNodeTraditional("load_truck1");
070:                    prjSession.setNodeTraditional("load_truck2");
071:
072:                    // Add transitions between activities
073:                    String toTruck1 = prjSession.addEdge(
074:                            "select_avaliable_resource", "load_truck1");
075:                    String toTruck2 = prjSession.addEdge(
076:                            "select_avaliable_resource", "load_truck2");
077:
078:                    // Add a Project Property and set transition conditions
079:                    prjSession.setProperty("truck_number", "0");
080:                    prjSession.setEdgeCondition(toTruck1,
081:                            "truck_number.equals(\"1\")");
082:                    prjSession.setEdgeCondition(toTruck2,
083:                            "truck_number.equals(\"2\")");
084:
085:                    // Set a hook that simulates trucks avaliability 
086:                    String simulateAvalibilityHookScript = "import hero.interfaces.*;\n"
087:                            + "import java.util.Random; \n"
088:                            + "beforeTerminate(Object engine, Object currentNode) {\n\n\n"
089:                            + "  hero.interfaces.ProjectSessionHome pHome = (hero.interfaces.ProjectSessionHome) hero.interfaces.ProjectSessionUtil.getHome(); \n"
090:                            + "  hero.interfaces.ProjectSession prjSession = pHome.create(); \n"
091:                            + "  prjSession.initModel(currentNode.getBnProject().getName()); \n"
092:                            + "  Random generator = new Random(System.currentTimeMillis()); \n"
093:                            + "  int truck = generator.nextInt(2) + 1; \n"
094:                            + "  prjSession.setProperty(\"truck_number\", Integer.toString(truck)); \n"
095:                            + "  System.out.println(\"    --> Truck avaliable : \" + truck); \n"
096:                            + "} \n";
097:                    prjSession.addNodeInterHook("select_avaliable_resource",
098:                            "select_avaliable_resource hook",
099:                            hero.interfaces.Constants.Nd.BEFORETERMINATE,
100:                            hero.interfaces.Constants.Hook.BSINTERACTIVE,
101:                            simulateAvalibilityHookScript);
102:
103:                    // Add and set a role for the user admin to execute the activities
104:                    prjSession.addRole("Executor",
105:                            "Rol that enables to execute the activities");
106:                    prjSession.setUserRole("admin", "Executor");
107:                    prjSession.setNodeRole("select_avaliable_resource",
108:                            "Executor");
109:                    prjSession.setNodeRole("load_truck1", "Executor");
110:                    prjSession.setNodeRole("load_truck2", "Executor");
111:
112:                    // Check model definition
113:                    prjSession.checkModelDefinition();
114:
115:                    System.out.println("   [ OK ]");
116:                } catch (Exception e) {
117:                    System.out.println("\n\n   [ ERROR ] : " + e);
118:                    e.printStackTrace();
119:                } // Maybe something is wrong
120:            }
121:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.