Source Code Cross Referenced for UsecaseCronJob.java in  » Content-Management-System » apache-lenya-2.0 » org » apache » lenya » cms » usecase » scheduling » impl » 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.usecase.scheduling.impl 
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
012:         *  distributed under the License is distributed on an "AS IS" BASIS,
013:         *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014:         *  See the License for the specific language governing permissions and
015:         *  limitations under the License.
016:         *
017:         */
018:        package org.apache.lenya.cms.usecase.scheduling.impl;
019:
020:        import java.util.Collections;
021:        import java.util.Enumeration;
022:        import java.util.HashMap;
023:        import java.util.Map;
024:
025:        import org.apache.avalon.framework.context.Context;
026:        import org.apache.avalon.framework.context.ContextException;
027:        import org.apache.avalon.framework.context.Contextualizable;
028:        import org.apache.avalon.framework.parameters.Parameters;
029:        import org.apache.avalon.framework.service.ServiceException;
030:        import org.apache.avalon.framework.service.ServiceSelector;
031:        import org.apache.cocoon.components.CocoonComponentManager;
032:        import org.apache.cocoon.components.ContextHelper;
033:        import org.apache.cocoon.components.cron.ConfigurableCronJob;
034:        import org.apache.cocoon.components.cron.ServiceableCronJob;
035:        import org.apache.cocoon.environment.Environment;
036:        import org.apache.cocoon.environment.ObjectModelHelper;
037:        import org.apache.cocoon.environment.Request;
038:        import org.apache.cocoon.environment.Session;
039:        import org.apache.cocoon.environment.commandline.CommandLineRequest;
040:        import org.apache.lenya.ac.AccessControlException;
041:        import org.apache.lenya.ac.AccessController;
042:        import org.apache.lenya.ac.AccessControllerResolver;
043:        import org.apache.lenya.ac.Identifiable;
044:        import org.apache.lenya.ac.Identity;
045:        import org.apache.lenya.ac.Machine;
046:        import org.apache.lenya.ac.User;
047:        import org.apache.lenya.ac.UserManager;
048:        import org.apache.lenya.cms.usecase.Usecase;
049:        import org.apache.lenya.cms.usecase.UsecaseInvoker;
050:
051:        /**
052:         * Job to schedule usecase execution.
053:         * 
054:         * @version $Id: UsecaseCronJob.java 535152 2007-05-04 10:14:41Z andreas $
055:         */
056:        public class UsecaseCronJob extends ServiceableCronJob implements 
057:                ConfigurableCronJob, Contextualizable {
058:
059:            /**
060:             * Initializes the job.
061:             * @param usecase The usecase.
062:             */
063:            public void setup(Usecase usecase) {
064:                this .usecaseName = usecase.getName();
065:                String[] keys = usecase.getParameterNames();
066:                for (int i = 0; i < keys.length; i++) {
067:                    this .parameters.put(keys[i], usecase.getParameter(keys[i]));
068:                }
069:            }
070:
071:            private String usecaseName;
072:            private String sourceUrl;
073:            private String userId;
074:            private String machineIp;
075:
076:            private Map parameters = new HashMap();
077:
078:            protected static final String USECASE_NAME = "usecaseName";
079:            protected static final String SOURCE_URL = "sourceUrl";
080:            protected static final String USER_ID = "userId";
081:            protected static final String MACHINE_IP = "machineIp";
082:
083:            /**
084:             * @return The name of the usecase to execute.
085:             */
086:            public String getUsecaseName() {
087:                return this .usecaseName;
088:            }
089:
090:            /**
091:             * @return The ID of the user who scheduled the job.
092:             */
093:            public String getUserId() {
094:                return this .userId;
095:            }
096:
097:            protected String getSourceURL() {
098:                return this .sourceUrl;
099:            }
100:
101:            protected Map getParameters() {
102:                return Collections.unmodifiableMap(this .parameters);
103:            }
104:
105:            /**
106:             * @see org.apache.cocoon.components.cron.CronJob#execute(java.lang.String)
107:             */
108:            public void execute(String jobname) {
109:                UsecaseInvoker invoker = null;
110:                try {
111:                    setupOriginalRequest();
112:                    authorizeRequest();
113:
114:                    invoker = (UsecaseInvoker) this .manager
115:                            .lookup(UsecaseInvoker.ROLE);
116:                    invoker.invoke(getSourceURL(), getUsecaseName(),
117:                            getParameters());
118:
119:                } catch (Exception e) {
120:                    throw new RuntimeException(e);
121:                } finally {
122:                    if (invoker != null) {
123:                        this .manager.release(invoker);
124:                    }
125:                }
126:            }
127:
128:            /**
129:             * Creates a new request object based on the information from the original request which
130:             * triggered the usecase.
131:             */
132:            protected void setupOriginalRequest() {
133:                Environment env = CocoonComponentManager
134:                        .getCurrentEnvironment();
135:
136:                Request request = ContextHelper.getRequest(this .context);
137:                Map attributes = new HashMap();
138:                for (Enumeration e = request.getAttributeNames(); e
139:                        .hasMoreElements();) {
140:                    String key = (String) e.nextElement();
141:                    attributes.put(key, request.getAttribute(key));
142:                }
143:
144:                Map requestParameters = new HashMap();
145:                for (Enumeration e = request.getParameterNames(); e
146:                        .hasMoreElements();) {
147:                    String key = (String) e.nextElement();
148:                    requestParameters.put(key, request.getParameter(key));
149:                }
150:
151:                Map objectModel = ContextHelper.getObjectModel(this .context);
152:                objectModel.put(ObjectModelHelper.REQUEST_OBJECT,
153:                        new CommandLineRequest(env, request.getContextPath(),
154:                                request.getServletPath(), getSourceURL(),
155:                                attributes, requestParameters));
156:            }
157:
158:            /**
159:             * Initializes the session with the access control information.
160:             * @throws AccessControlException if an error occurs.
161:             * @throws ServiceException if the access controller resolver could not be created.
162:             */
163:            protected void authorizeRequest() throws AccessControlException,
164:                    ServiceException {
165:
166:                ServiceSelector selector = null;
167:                AccessControllerResolver acResolver = null;
168:                AccessController controller = null;
169:                try {
170:                    selector = (ServiceSelector) this .manager
171:                            .lookup(AccessControllerResolver.ROLE + "Selector");
172:                    acResolver = (AccessControllerResolver) selector
173:                            .select(AccessControllerResolver.DEFAULT_RESOLVER);
174:                    controller = acResolver
175:                            .resolveAccessController(getSourceURL());
176:
177:                    getLogger().debug("Add identity to session");
178:                    getLogger().debug("User ID: [" + this .userId + "]");
179:                    getLogger().debug("Machine: [" + this .machineIp + "]");
180:
181:                    Request request = ContextHelper.getRequest(this .context);
182:                    controller.setupIdentity(request);
183:                    Session session = request.getSession(false);
184:                    Identity identity = (Identity) session
185:                            .getAttribute(Identity.class.getName());
186:                    Identifiable[] identifiables = identity.getIdentifiables();
187:                    for (int i = 0; i < identifiables.length; i++) {
188:                        identity.removeIdentifiable(identifiables[i]);
189:                    }
190:
191:                    UserManager userManager = controller
192:                            .getAccreditableManager().getUserManager();
193:                    if (this .userId != null) {
194:                        User user = userManager.getUser(this .userId);
195:
196:                        if (user == null) {
197:                            throw new RuntimeException("User [" + this .userId
198:                                    + "] does not exist!");
199:                        }
200:
201:                        identity.addIdentifiable(user);
202:                    }
203:                    if (this .machineIp != null) {
204:                        Machine machine = new Machine(this .machineIp);
205:                        identity.addIdentifiable(machine);
206:                    }
207:
208:                    controller.authorize(request);
209:
210:                } finally {
211:                    if (selector != null) {
212:                        if (acResolver != null) {
213:                            if (controller != null) {
214:                                acResolver.release(controller);
215:                            }
216:                            selector.release(acResolver);
217:                        }
218:                        this .manager.release(selector);
219:                    }
220:                }
221:
222:            }
223:
224:            /**
225:             * @see org.apache.cocoon.components.cron.ConfigurableCronJob#setup(org.apache.avalon.framework.parameters.Parameters,
226:             *      java.util.Map)
227:             */
228:            public void setup(Parameters parameters, Map objects) {
229:                this .parameters.putAll(Parameters.toProperties(parameters));
230:                this .usecaseName = (String) objects.get(USECASE_NAME);
231:                this .sourceUrl = (String) objects.get(SOURCE_URL);
232:                this .userId = (String) objects.get(USER_ID);
233:                this .machineIp = (String) objects.get(MACHINE_IP);
234:            }
235:
236:            private Context context;
237:
238:            /**
239:             * @see org.apache.avalon.framework.context.Contextualizable#contextualize(org.apache.avalon.framework.context.Context)
240:             */
241:            public void contextualize(Context context) throws ContextException {
242:                this.context = context;
243:            }
244:
245:        }
w_ww___.___j_a___v___a2___s_.c_o___m___ | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.