Source Code Cross Referenced for WorkflowBuilder.java in  » Wiki-Engine » JSPWiki » com » ecyrd » jspwiki » workflow » 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 » Wiki Engine » JSPWiki » com.ecyrd.jspwiki.workflow 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /* 
002:            JSPWiki - a JSP-based WikiWiki clone.
003:
004:            Copyright (C) 2001-2002 Janne Jalkanen (Janne.Jalkanen@iki.fi)
005:
006:            This program is free software; you can redistribute it and/or modify
007:            it under the terms of the GNU Lesser General Public License as published by
008:            the Free Software Foundation; either version 2.1 of the License, or
009:            (at your option) any later version.
010:
011:            This program is distributed in the hope that it will be useful,
012:            but WITHOUT ANY WARRANTY; without even the implied warranty of
013:            MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
014:            GNU Lesser General Public License for more details.
015:
016:            You should have received a copy of the GNU Lesser General Public License
017:            along with this program; if not, write to the Free Software
018:            Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
019:         */
020:        package com.ecyrd.jspwiki.workflow;
021:
022:        import java.security.Principal;
023:        import java.util.HashMap;
024:        import java.util.Map;
025:
026:        import com.ecyrd.jspwiki.WikiEngine;
027:        import com.ecyrd.jspwiki.WikiException;
028:
029:        /**
030:         * Factory class that creates common Workflow instances such as a standard approval workflow.
031:         * @author Andrew Jaquith
032:         */
033:        public final class WorkflowBuilder {
034:            private static final Map BUILDERS = new HashMap();
035:            private final WikiEngine m_engine;
036:
037:            /**
038:             * Private constructor that creates a new WorkflowBuilder for the supplied WikiEngine.
039:             * @param engine the wiki engine
040:             */
041:            private WorkflowBuilder(WikiEngine engine) {
042:                m_engine = engine;
043:            }
044:
045:            /**
046:             * Returns the WorkflowBuilder instance for a WikiEngine. Only one WorkflowBuilder
047:             * exists for a given engine.
048:             * @param engine the wiki engine
049:             * @return the workflow builder
050:             */
051:            public static WorkflowBuilder getBuilder(WikiEngine engine) {
052:                WorkflowBuilder builder = (WorkflowBuilder) BUILDERS
053:                        .get(engine);
054:                if (builder == null) {
055:                    builder = new WorkflowBuilder(engine);
056:                    BUILDERS.put(engine, builder);
057:                }
058:                return builder;
059:            }
060:
061:            /**
062:             * <p>Builds an approval workflow that requests approval from a named
063:             * user, {@link com.ecyrd.jspwiki.auth.authorize.Group} or
064:             * {@link com.ecyrd.jspwiki.auth.authorize.Role} before running a Task.</p>
065:             * <p>The Principal who approves the activity is determined by looking up
066:             * the property <code>jspwiki.approver.<var>workflowApproverKey</var></code>
067:             * in <code>jspwiki.properties</code>. If that Principal resolves to a known user, Group
068:             * Role, a Decision will be placed in the respective workflow queue (or multiple queues,
069:             * if necessary). Only one approver needs to make the Decision, and if the request is
070:             * approved, the completion task will be executed. If the request is denied, a
071:             * {@link SimpleNotification} with a message corresponding to the <code>rejectedMessage</code>
072:             * message key will be placed in the submitter's workflow queue.</p>
073:             * <p>To help approvers determine how to make the Decision, callers can supply an
074:             * array of Fact objects to this method, which will be added to the Decision in the order
075:             * they appear in the array. These items will be displayed in the web UI.
076:             * In addition, the value of the first Fact will also be added as the third message
077:             * argument for the workflow (the first two are always the submitter and the approver).
078:             * For example, the PageManager code that creates the "save page approval" workflow
079:             * adds the name of the page as its first Fact; this results in the page name being
080:             * substituted correctly into the resulting message:
081:             * "Save wiki page &lt;strong&gt;{2}&lt;/strong&gt;".</p>
082:             * @param submitter the user submitting the request
083:             * @param workflowApproverKey the key that names the user, Group or Role who must approve
084:             * the request. The key is looked up in <code>jspwiki.properties</code>, and is derived
085:             * by prepending <code>jspwiki.approver</code> to the value of <code>workflowApproverKey</code>
086:             * @param prepTask the initial task that should run before the Decision step is processed.
087:             * If this parameter is <code>null</code>, the Decision will run as the first Step instead
088:             * @param decisionKey the message key in <code>default.properties</code> that contains
089:             * the text that will appear in approvers' workflow queues indicating they need to make
090:             * a Decision; for example, <code>decision.saveWikiPage</code>. In the i18n message bundle
091:             * file, this key might return text that reads "Approve page &lt;strong&gt;{2}&lt;/strong&gt;"
092:             * @param facts an array of {@link Fact} objects that will be shown to the approver
093:             * to aid decision-making. The facts will be displayed in the order supplied in the array
094:             * @param completionTask the Task that will run if the Decision is approved
095:             * @param rejectedMessageKey the message key in <code>default.properties</code> that contains
096:             * the text that will appear in the submitter's workflow queue if request was
097:             * not approved; for example, <code>notification.saveWikiPage.reject</code>. In the
098:             * i18n message bundle file, this key might might return
099:             * text that reads "Your request to save page &lt;strong&gt;{2}&lt;/strong&gt; was rejected."
100:             * If this parameter is <code>null</code>, no message will be sent
101:             * @return the created workflow
102:             * @throws WikiException if the name of the approving user, Role or Group cannot be determined
103:             */
104:            public Workflow buildApprovalWorkflow(Principal submitter,
105:                    String workflowApproverKey, Task prepTask,
106:                    String decisionKey, Fact[] facts, Task completionTask,
107:                    String rejectedMessageKey) throws WikiException {
108:                WorkflowManager mgr = m_engine.getWorkflowManager();
109:                Workflow workflow = new Workflow(workflowApproverKey, submitter);
110:
111:                // Is a Decision required to run the approve task?
112:                boolean decisionRequired = mgr
113:                        .requiresApproval(workflowApproverKey);
114:
115:                // If Decision required, create a simple approval workflow
116:                if (decisionRequired) {
117:                    // Look up the name of the approver (user or group) listed in jspwiki.properties;
118:                    // approvals go to the approver's decision cue
119:                    Principal approverPrincipal = mgr
120:                            .getApprover(workflowApproverKey);
121:                    Decision decision = new SimpleDecision(workflow,
122:                            decisionKey, approverPrincipal);
123:
124:                    // Add facts to the Decision, if any were supplied
125:                    if (facts != null) {
126:                        for (int i = 0; i < facts.length; i++) {
127:                            decision.addFact(facts[i]);
128:                        }
129:                        // Add the first one as a message key
130:                        if (facts.length > 0) {
131:                            workflow.addMessageArgument(facts[0].getValue());
132:                        }
133:                    }
134:
135:                    // If rejected, sent a notification
136:                    if (rejectedMessageKey != null) {
137:                        SimpleNotification rejectNotification = new SimpleNotification(
138:                                workflow, rejectedMessageKey, submitter);
139:                        decision.addSuccessor(Outcome.DECISION_DENY,
140:                                rejectNotification);
141:                    }
142:
143:                    // If approved, run the 'approved' task
144:                    decision.addSuccessor(Outcome.DECISION_APPROVE,
145:                            completionTask);
146:
147:                    // Set the first step
148:                    if (prepTask == null) {
149:                        workflow.setFirstStep(decision);
150:                    } else {
151:                        workflow.setFirstStep(prepTask);
152:                        prepTask.addSuccessor(Outcome.STEP_COMPLETE, decision);
153:                    }
154:                }
155:
156:                // If Decision not required, just run the prep + approved tasks in succession
157:                else {
158:                    // Set the first step
159:                    if (prepTask == null) {
160:                        workflow.setFirstStep(completionTask);
161:                    } else {
162:                        workflow.setFirstStep(prepTask);
163:                        prepTask.addSuccessor(Outcome.STEP_COMPLETE,
164:                                completionTask);
165:                    }
166:                }
167:
168:                // Make sure our tasks have this workflow as the parent, then return
169:                if (prepTask != null) {
170:                    prepTask.setWorkflow(workflow);
171:                }
172:                completionTask.setWorkflow(workflow);
173:                return workflow;
174:            }
175:
176:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.