Source Code Cross Referenced for WorkflowInvoker.java in  » Content-Management-System » apache-lenya-2.0 » org » apache » lenya » cms » task » 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 » Content Management System » apache lenya 2.0 » org.apache.lenya.cms.task 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Licensed to the Apache Software Foundation (ASF) under one or more
003:         *  contributor license agreements.  See the NOTICE file distributed with
004:         *  this work for additional information regarding copyright ownership.
005:         *  The ASF licenses this file to You under the Apache License, Version 2.0
006:         *  (the "License"); you may not use this file except in compliance with
007:         *  the License.  You may obtain a copy of the License at
008:         * 
009:         * http://www.apache.org/licenses/LICENSE-2.0
010:         * 
011:         * Unless required by applicable law or agreed to in writing, software distributed under the License
012:         * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
013:         * or implied. See the License for the specific language governing permissions and limitations under
014:         * the License.
015:         *  
016:         */
017:
018:        /* $Id: WorkflowInvoker.java 473861 2006-11-12 03:51:14Z gregor $ */
019:
020:        package org.apache.lenya.cms.task;
021:
022:        import java.util.Map;
023:
024:        import org.apache.avalon.framework.logger.ConsoleLogger;
025:        import org.apache.avalon.framework.service.ServiceManager;
026:        import org.apache.lenya.ac.Identity;
027:        import org.apache.lenya.ac.Machine;
028:        import org.apache.lenya.ac.Role;
029:        import org.apache.lenya.ac.User;
030:        import org.apache.lenya.cms.publication.Document;
031:        import org.apache.lenya.cms.publication.DocumentFactory;
032:        import org.apache.lenya.cms.publication.DocumentUtil;
033:        import org.apache.lenya.cms.publication.Publication;
034:        import org.apache.lenya.cms.repository.RepositoryUtil;
035:        import org.apache.lenya.cms.repository.Session;
036:        import org.apache.lenya.cms.workflow.WorkflowUtil;
037:        import org.apache.lenya.util.NamespaceMap;
038:        import org.apache.log4j.Logger;
039:
040:        /**
041:         * The workflow invoker
042:         * @deprecated Use the usecase framework instead.
043:         */
044:        public class WorkflowInvoker extends ParameterWrapper {
045:
046:            private static Logger log = Logger.getLogger(WorkflowInvoker.class);
047:            private ServiceManager manager;
048:
049:            /**
050:             * <code>ROLES</code> The roles
051:             */
052:            public static final String ROLES = "roles";
053:            /**
054:             * <code>USER_ID</code> The user id
055:             */
056:            public static final String USER_ID = "user-id";
057:            /**
058:             * <code>MACHINE</code> The machine
059:             */
060:            public static final String MACHINE = "machine";
061:            /**
062:             * <code>EVENT</code> The event
063:             */
064:            public static final String EVENT = "event";
065:            /**
066:             * <code>PREFIX</code> The workflow namespace prefix
067:             */
068:            public static final String PREFIX = "workflow";
069:            /**
070:             * <code>EVENT_REQUEST_PARAMETER</code> The workflow event request parameter
071:             */
072:            public static final String EVENT_REQUEST_PARAMETER = "workflow.event";
073:            /**
074:             * <code>LENYA_EVENT_REQUEST_PARAMETER</code> The Lenya event request parameter
075:             */
076:            public static final String LENYA_EVENT_REQUEST_PARAMETER = "lenya.event";
077:
078:            /**
079:             * Ctor.
080:             * 
081:             * @param eventName The event name.
082:             * @param identity The identity.
083:             * @param roles The roles.
084:             * @return A namespace map containing the parameters.
085:             */
086:            public static NamespaceMap extractParameters(String eventName,
087:                    Identity identity, Role[] roles) {
088:                NamespaceMap parameters = new NamespaceMap(PREFIX);
089:                log.debug("Extractign workflow invoker parameters.");
090:                log.debug("    Event: [" + eventName + "]");
091:                parameters.put(EVENT, eventName);
092:                setRoles(parameters, roles);
093:                setIdentity(parameters, identity);
094:                return parameters;
095:            }
096:
097:            /**
098:             * Ctor.
099:             * 
100:             * @param parameters A map containing the prefixed parameters.
101:             * @param manager The service manager.
102:             */
103:            public WorkflowInvoker(Map parameters, ServiceManager manager) {
104:                super (parameters);
105:                this .manager = manager;
106:            }
107:
108:            /**
109:             * Returns the role names.
110:             * 
111:             * @return A string array.
112:             */
113:            protected String[] getRoleIDs() {
114:                String rolesString = get(ROLES);
115:                String[] roleIDs = rolesString.split(",");
116:                return roleIDs;
117:            }
118:
119:            /**
120:             * Sets the roles.
121:             * 
122:             * @param parameters A workflow invoker namespace map.
123:             * @param roles A role array.
124:             */
125:            public static void setRoles(NamespaceMap parameters, Role[] roles) {
126:
127:                StringBuffer buf = new StringBuffer();
128:                for (int i = 0; i < roles.length; i++) {
129:                    if (i > 0) {
130:                        buf.append(",");
131:                    }
132:                    buf.append(roles[i].getId());
133:                }
134:                String roleString = buf.toString();
135:                parameters.put(ROLES, roleString);
136:            }
137:
138:            /**
139:             * Sets the identity.
140:             * 
141:             * @param parameters A workflow invoker namespace map.
142:             * @param identity An identity.
143:             */
144:            public static void setIdentity(NamespaceMap parameters,
145:                    Identity identity) {
146:
147:                String userId = "";
148:                User user = identity.getUser();
149:                if (user != null) {
150:                    userId = user.getId();
151:                }
152:                parameters.put(USER_ID, userId);
153:
154:                String machineIp = "";
155:                Machine machine = identity.getMachine();
156:                if (machine != null) {
157:                    machineIp = machine.getIp();
158:                }
159:                parameters.put(MACHINE, machineIp);
160:            }
161:
162:            /**
163:             * Returns the workflow event name.
164:             * @return A string.
165:             */
166:            public String getEventName() {
167:                return get(EVENT);
168:            }
169:
170:            /**
171:             * Returns the user ID.
172:             * @return A string.
173:             */
174:            public String getUserId() {
175:                return get(USER_ID);
176:            }
177:
178:            /**
179:             * Returns the machine IP address.
180:             * @return A string.
181:             */
182:            public String getMachineIp() {
183:                return get(MACHINE);
184:            }
185:
186:            private Document document;
187:
188:            /**
189:             * Initializes the workflow invoker.
190:             * 
191:             * @param publication The publication.
192:             * @param webappUrl The webapp URL.
193:             * @throws ExecutionException when something went wrong.
194:             */
195:            public void setup(Publication publication, String webappUrl)
196:                    throws ExecutionException {
197:                String eventName = getEventName();
198:                if (eventName == null) {
199:                    log.debug("No workflow event.");
200:                } else {
201:                    log.debug("Workflow event: [" + eventName + "]");
202:                    // check for workflow instance first (task can initialize the workflow history)
203:                    try {
204:                        Session session = RepositoryUtil.createSession(
205:                                this .manager, null);
206:                        DocumentFactory map = DocumentUtil
207:                                .createDocumentIdentityMap(this .manager,
208:                                        session);
209:                        this .document = map.getFromURL(webappUrl);
210:                    } catch (Exception e) {
211:                        throw new ExecutionException(e);
212:                    }
213:                }
214:            }
215:
216:            /**
217:             * Invokes the transition.
218:             * @throws ExecutionException when something went wrong.
219:             */
220:            public void invokeTransition() throws ExecutionException {
221:
222:                try {
223:                    Session session = RepositoryUtil.createSession(
224:                            this .manager, null);
225:                    WorkflowUtil.invoke(this .manager, session,
226:                            new ConsoleLogger(), this .document, getEventName());
227:                } catch (Exception e) {
228:                    throw new ExecutionException(e);
229:                }
230:            }
231:
232:            /**
233:             * @see org.apache.lenya.cms.task.ParameterWrapper#getPrefix()
234:             */
235:            public String getPrefix() {
236:                return PREFIX;
237:            }
238:
239:            /**
240:             * @see org.apache.lenya.cms.task.ParameterWrapper#getRequiredKeys()
241:             */
242:            protected String[] getRequiredKeys() {
243:                String[] keys = {};
244:                return keys;
245:            }
246:
247:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.