Source Code Cross Referenced for UsecaseInvokerImpl.java in  » Content-Management-System » apache-lenya-2.0 » org » apache » lenya » cms » usecase » 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.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.impl;
019:
020:        import java.util.ArrayList;
021:        import java.util.Collections;
022:        import java.util.Iterator;
023:        import java.util.List;
024:        import java.util.Map;
025:
026:        import org.apache.avalon.framework.logger.AbstractLogEnabled;
027:        import org.apache.avalon.framework.service.ServiceException;
028:        import org.apache.avalon.framework.service.ServiceManager;
029:        import org.apache.avalon.framework.service.Serviceable;
030:        import org.apache.lenya.cms.repository.Session;
031:        import org.apache.lenya.cms.usecase.Usecase;
032:        import org.apache.lenya.cms.usecase.UsecaseException;
033:        import org.apache.lenya.cms.usecase.UsecaseInvoker;
034:        import org.apache.lenya.cms.usecase.UsecaseMessage;
035:        import org.apache.lenya.cms.usecase.UsecaseResolver;
036:
037:        /**
038:         * Usecase invoker implementation.
039:         * 
040:         * @version $Id: UsecaseInvokerImpl.java 556887 2007-07-17 11:31:09Z andreas $
041:         */
042:        public class UsecaseInvokerImpl extends AbstractLogEnabled implements 
043:                UsecaseInvoker, Serviceable {
044:
045:            private String targetUrl;
046:
047:            /**
048:             * @see org.apache.lenya.cms.usecase.UsecaseInvoker#invoke(java.lang.String, java.lang.String,
049:             *      java.util.Map)
050:             */
051:            public void invoke(String webappUrl, String usecaseName,
052:                    Map parameters) throws UsecaseException {
053:
054:                this .errorMessages.clear();
055:                this .infoMessages.clear();
056:
057:                UsecaseResolver resolver = null;
058:                Usecase usecase = null;
059:                this .result = SUCCESS;
060:                try {
061:
062:                    resolver = (UsecaseResolver) this .manager
063:                            .lookup(UsecaseResolver.ROLE);
064:                    usecase = resolver.resolve(webappUrl, usecaseName);
065:
066:                    Session testSession = getTestSession();
067:                    if (testSession != null) {
068:                        usecase.setTestSession(testSession);
069:                    }
070:
071:                    passParameters(usecase, parameters);
072:
073:                    usecase.checkPreconditions();
074:
075:                    if (succeeded(PRECONDITIONS_FAILED, usecase)) {
076:
077:                        usecase.lockInvolvedObjects();
078:                        usecase.checkExecutionConditions();
079:
080:                        if (succeeded(EXECUTION_CONDITIONS_FAILED, usecase)) {
081:                            usecase.execute();
082:
083:                            boolean success = succeeded(EXECUTION_FAILED,
084:                                    usecase);
085:                            this .targetUrl = usecase.getTargetURL(success);
086:                            if (success) {
087:                                usecase.checkPostconditions();
088:                                succeeded(POSTCONDITIONS_FAILED, usecase);
089:                            }
090:                        }
091:                    }
092:
093:                } catch (Exception e) {
094:                    throw new RuntimeException(e);
095:                } finally {
096:                    if (resolver != null) {
097:                        if (usecase != null) {
098:                            try {
099:                                resolver.release(usecase);
100:                            } catch (ServiceException e) {
101:                                throw new RuntimeException(e);
102:                            }
103:                        }
104:                        this .manager.release(resolver);
105:                    }
106:                }
107:            }
108:
109:            private Session testSession = null;
110:
111:            protected Session getTestSession() {
112:                return this .testSession;
113:            }
114:
115:            protected boolean succeeded(int result, Usecase usecase) {
116:
117:                this .errorMessages.addAll(usecase.getErrorMessages());
118:                this .infoMessages.addAll(usecase.getInfoMessages());
119:
120:                if (usecase.getErrorMessages().isEmpty()) {
121:                    return true;
122:                } else {
123:                    this .result = result;
124:                    String message = null;
125:                    switch (result) {
126:                    case PRECONDITIONS_FAILED:
127:                        message = "Precondition messages:";
128:                        break;
129:                    case EXECUTION_CONDITIONS_FAILED:
130:                        message = "Execution condition messages:";
131:                        break;
132:                    case EXECUTION_FAILED:
133:                        message = "Execution messages:";
134:                        break;
135:                    case POSTCONDITIONS_FAILED:
136:                        message = "Postcondition messages:";
137:                        break;
138:                    }
139:                    logErrorMessages(usecase.getName(), message, usecase
140:                            .getErrorMessages());
141:                    return false;
142:                }
143:            }
144:
145:            /**
146:             * @param usecase The usecase to pass the parameters to.
147:             * @param parameters The parameters.
148:             */
149:            protected void passParameters(Usecase usecase, Map parameters) {
150:                for (Iterator i = parameters.keySet().iterator(); i.hasNext();) {
151:                    String key = (String) i.next();
152:                    Object value = parameters.get(key);
153:                    usecase.setParameter(key, value);
154:                }
155:            }
156:
157:            /**
158:             * @param usecaseName The name of the usecase.
159:             * @param headline The headline of the messages.
160:             * @param errorMessages The messages to log.
161:             */
162:            protected void logErrorMessages(String usecaseName,
163:                    String headline, List errorMessages) {
164:                getLogger()
165:                        .error("Usecase [" + usecaseName + "] - " + headline);
166:                for (Iterator i = errorMessages.iterator(); i.hasNext();) {
167:                    getLogger().error("" + (UsecaseMessage) i.next());
168:                }
169:            }
170:
171:            private ServiceManager manager;
172:
173:            /**
174:             * @see org.apache.avalon.framework.service.Serviceable#service(org.apache.avalon.framework.service.ServiceManager)
175:             */
176:            public void service(ServiceManager manager) throws ServiceException {
177:                this .manager = manager;
178:            }
179:
180:            private List errorMessages = new ArrayList();
181:            private List infoMessages = new ArrayList();
182:
183:            public List getErrorMessages() {
184:                return Collections.unmodifiableList(this .errorMessages);
185:            }
186:
187:            public List getInfoMessages() {
188:                return Collections.unmodifiableList(this .infoMessages);
189:            }
190:
191:            private int result = SUCCESS;
192:
193:            public int getResult() {
194:                return this .result;
195:            }
196:
197:            public String getTargetUrl() {
198:                if (this .targetUrl == null) {
199:                    throw new IllegalStateException(
200:                            "The usecase has not been executed yet.");
201:                }
202:                return this .targetUrl;
203:            }
204:
205:            public void setTestSession(Session session) {
206:                this.testSession = session;
207:            }
208:
209:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.