Source Code Cross Referenced for Pattern18MilestoneAsDeadline.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 18 : Milestone
024:         *       Author : Jordi Anguela
025:         *         Date : 2006/03/01 
026:        --------------------------------------------------------------------------
027:         * Example
028:         * This exemple shows how you can use Bonita deadlines to control the period
029:         * of execution of an activity.
030:         * 'withdraw_order' is only enabled :
031:         *    - only after the execution of 'order_book'
032:         *    - only during 20 seconds
033:         *    - only if 'shipping_process' activity is not started 
034:        --------------------------------------------------------------------------
035:         */package hero.client.samples.patterns.src;
036:
037:        import hero.client.test.SimpleCallbackHandler;
038:        import hero.interfaces.Constants;
039:        import hero.interfaces.ProjectSession;
040:        import hero.interfaces.ProjectSessionHome;
041:        import hero.interfaces.ProjectSessionUtil;
042:
043:        import javax.security.auth.login.LoginContext;
044:
045:        public class Pattern18MilestoneAsDeadline {
046:            final static long DEADLINE = 1000; // In miliseconds
047:
048:            public static void main(String[] args) {
049:                try {
050:                    // User Admin login
051:                    char[] password = { 't', 'o', 't', 'o' };
052:                    SimpleCallbackHandler handler = new SimpleCallbackHandler(
053:                            "admin", password);
054:                    LoginContext lc = new LoginContext("TestClient", handler);
055:                    lc.login();
056:
057:                    // Project Session Bean creation
058:                    ProjectSessionHome prjHome = (ProjectSessionHome) ProjectSessionUtil
059:                            .getHome();
060:                    ProjectSession prjSession = prjHome.create();
061:
062:                    // Model creation 
063:                    System.out.print("\n   Pattern 18 - Milestone as Deadline");
064:                    prjSession.initModel("Pattern 18 - Milestone as Deadline");
065:
066:                    // Add activities and set them to Non anticipable
067:                    prjSession.addNode("order_book",
068:                            hero.interfaces.Constants.Nd.AND_JOIN_NODE);
069:                    prjSession.addNode("withdraw_order",
070:                            hero.interfaces.Constants.Nd.AND_JOIN_NODE);
071:                    prjSession.addNode("ship_order",
072:                            hero.interfaces.Constants.Nd.AND_JOIN_NODE);
073:                    prjSession.setNodeTraditional("order_book");
074:                    prjSession.setNodeTraditional("withdraw_order");
075:                    prjSession.setNodeTraditional("ship_order");
076:
077:                    // Add transitions between activities
078:                    prjSession.addEdge("order_book", "ship_order");
079:                    prjSession.addEdge("order_book", "withdraw_order");
080:
081:                    // Add Hook that set the Deadline for 'withdraw_order'
082:                    String setDeadlineScript = "import hero.interfaces.*; \n"
083:                            + "beforeTerminate(Object engine, Object currentNode) { \n"
084:                            + "  hero.interfaces.ProjectSessionHome pHome = (hero.interfaces.ProjectSessionHome) hero.interfaces.ProjectSessionUtil.getHome(); \n"
085:                            + "  hero.interfaces.ProjectSession prjSession = pHome.create(); \n"
086:                            + "  prjSession.initModel(currentNode.getBnProject().getName()); \n"
087:                            + "  ArrayList deadlines = new ArrayList(); \n"
088:                            + "  long date1 = System.currentTimeMillis() + (long)10000; \n"
089:                            + "  deadlines.add(new Long(date1)); \n"
090:                            + "  prjSession.setNodeDeadlines(\"withdraw_order\", deadlines); \n"
091:                            + "}";
092:                    prjSession.addNodeInterHook("order_book",
093:                            "order_book Hook",
094:                            hero.interfaces.Constants.Nd.BEFORETERMINATE,
095:                            hero.interfaces.Constants.Hook.BSINTERACTIVE,
096:                            setDeadlineScript);
097:
098:                    // Add Deadline Hook to 'withdraw_order' to cancel itself when the deadline expires 
099:                    String onDeadlineScript = "import hero.interfaces.*; \n"
100:                            + "onDeadline(Object engine, Object currentNode) { \n"
101:                            + "  System.out.println(\"\n\n   --> Deadline hook <--\"); \n"
102:                            + "  UserSessionHome userHome = UserSessionUtil.getHome(); \n"
103:                            + "  UserSession userSession = userHome.create(); \n"
104:                            + "  userSession.cancelActivity(currentNode.getBnProject().getName(), \"withdraw_order\"); \n "
105:                            + "}";
106:                    //prjSession.addNodeInterHook("withdraw_order", "withdraw_order Hook", hero.interfaces.Constants.Nd.ONDEADLINE, hero.interfaces.Constants.Hook.BSINTERACTIVE, onDeadlineScript);
107:                    prjSession.addNodeHook("withdraw_order",
108:                            "hero.hook.CancelActivity",
109:                            hero.interfaces.Constants.Nd.ONDEADLINE,
110:                            Constants.Hook.JAVA);
111:
112:                    // Add Hook to 'ship_order' to cancel the 'order_book if it has not executed yet 
113:                    String cancelScript = "import hero.interfaces.*; \n"
114:                            + "beforeStart(Object engine, Object currentNode) { \n"
115:                            + "  hero.interfaces.ProjectSessionHome pHome = (hero.interfaces.ProjectSessionHome) hero.interfaces.ProjectSessionUtil.getHome(); \n"
116:                            + "  hero.interfaces.ProjectSession prjSession = pHome.create(); \n"
117:                            + "  prjSession.initModel(currentNode.getBnProject().getName()); \n"
118:                            + "  if (prjSession.getNodeState(\"withdraw_order\") == hero.interfaces.Constants.Nd.READY) { \n"
119:                            + "    UserSessionHome userHome = UserSessionUtil.getHome(); \n"
120:                            + "    UserSession userSession = userHome.create(); \n"
121:                            + "    userSession.cancelActivity(currentNode.getBnProject().getName(), \"withdraw_order\"); \n "
122:                            + "  } \n" + "}";
123:                    prjSession.addNodeInterHook("ship_order",
124:                            "ship_order Hook",
125:                            hero.interfaces.Constants.Nd.BEFORESTART,
126:                            hero.interfaces.Constants.Hook.BSINTERACTIVE,
127:                            cancelScript);
128:
129:                    // Add and set a role for the user admin to execute the activities
130:                    prjSession.addRole("Executor",
131:                            "Rol that enables to execute the activities");
132:                    prjSession.setUserRole("admin", "Executor");
133:                    prjSession.setNodeRole("order_book", "Executor");
134:                    prjSession.setNodeRole("withdraw_order", "Executor");
135:                    prjSession.setNodeRole("ship_order", "Executor");
136:
137:                    // Check model definition
138:                    prjSession.checkModelDefinition();
139:
140:                    System.out.println("   [ OK ]");
141:                } catch (Exception e) {
142:                    System.out.println("\n\n   [ ERROR ] : " + e);
143:                    e.printStackTrace();
144:                } // Maybe something is wrong
145:            }
146:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.