Source Code Cross Referenced for ApplesProcessor.java in  » Content-Management-System » apache-lenya-2.0 » org » apache » cocoon » components » flow » apples » 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.cocoon.components.flow.apples 
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:        package org.apache.cocoon.components.flow.apples;
018:
019:        import java.util.List;
020:
021:        import org.apache.avalon.framework.CascadingRuntimeException;
022:        import org.apache.avalon.framework.activity.Disposable;
023:        import org.apache.avalon.framework.component.WrapperComponentManager;
024:        import org.apache.avalon.framework.context.ContextException;
025:        import org.apache.avalon.framework.context.DefaultContext;
026:        import org.apache.avalon.framework.service.ServiceException;
027:        import org.apache.avalon.framework.service.ServiceManager;
028:        import org.apache.avalon.framework.service.Serviceable;
029:        import org.apache.cocoon.components.ContextHelper;
030:        import org.apache.cocoon.components.LifecycleHelper;
031:        import org.apache.cocoon.components.flow.AbstractInterpreter;
032:        import org.apache.cocoon.components.flow.ContinuationsDisposer;
033:        import org.apache.cocoon.components.flow.InvalidContinuationException;
034:        import org.apache.cocoon.components.flow.WebContinuation;
035:        import org.apache.cocoon.environment.Redirector;
036:        import org.apache.cocoon.environment.Request;
037:        import org.apache.cocoon.environment.Response;
038:
039:        /**
040:         * ApplesProcessor is the core Cocoon component that provides the 'Apples' 
041:         * flow implementation. 
042:         */
043:        public class ApplesProcessor extends AbstractInterpreter implements 
044:                Serviceable, ContinuationsDisposer {
045:
046:            //private ServiceManager serviceManager;
047:
048:            public void callFunction(String className, List params,
049:                    Redirector redirector) throws Exception {
050:
051:                AppleController app = instantiateController(className);
052:
053:                WebContinuation wk = null;
054:                if (!(app instanceof  StatelessAppleController)) {
055:                    wk = this .continuationsMgr.createWebContinuation(app, null,
056:                            0, getInterpreterID(), this );
057:                    if (getLogger().isDebugEnabled())
058:                        getLogger().debug(
059:                                "Instantiated a stateful apple, continuationid = "
060:                                        + wk.getId());
061:                }
062:
063:                DefaultContext appleContext = new DefaultContext(avalonContext);
064:                if (wk != null) {
065:                    appleContext.put("continuation-id", wk.getId());
066:                }
067:
068:                //      Use the current sitemap's service manager for components
069:                ServiceManager sitemapManager;
070:                try {
071:                    sitemapManager = (ServiceManager) avalonContext
072:                            .get(ContextHelper.CONTEXT_SITEMAP_SERVICE_MANAGER);
073:                } catch (ContextException e) {
074:                    throw new CascadingRuntimeException(
075:                            "Cannot get sitemap service manager", e);
076:                }
077:
078:                LifecycleHelper.setupComponent(app, getLogger(), appleContext,
079:                        sitemapManager, new WrapperComponentManager(
080:                                sitemapManager), null, null, true);
081:
082:                processApple(params, redirector, app, wk);
083:            }
084:
085:            public void handleContinuation(String continuationId, List params,
086:                    Redirector redirector) throws Exception {
087:
088:                WebContinuation wk = this .continuationsMgr
089:                        .lookupWebContinuation(continuationId,
090:                                getInterpreterID());
091:                if (wk == null) {
092:                    // Throw an InvalidContinuationException to be handled inside the
093:                    // <map:handle-errors> sitemap element.
094:                    throw new InvalidContinuationException(
095:                            "The continuation ID " + continuationId
096:                                    + " is invalid.");
097:                }
098:
099:                AppleController app = (AppleController) wk.getContinuation();
100:
101:                getLogger().debug("found apple from continuation: " + app);
102:
103:                // TODO access control checks? exception to be thrown for illegal access?
104:                processApple(params, redirector, app, wk);
105:
106:            }
107:
108:            private AppleController instantiateController(String className)
109:                    throws Exception {
110:
111:                // TODO think about dynamic reloading of these beasts in future
112:                // classloading stuf et al.
113:
114:                Class clazz = Class.forName(className);
115:                Object o = clazz.newInstance();
116:                return (AppleController) o;
117:            }
118:
119:            private void processApple(List params, Redirector redirector,
120:                    AppleController app, WebContinuation wk) throws Exception {
121:
122:                Request cocoonRequest = ContextHelper
123:                        .getRequest(this .avalonContext);
124:                AppleRequest req = new DefaultAppleRequest(params,
125:                        cocoonRequest);
126:                Response cocoonResponse = ContextHelper
127:                        .getResponse(this .avalonContext);
128:                DefaultAppleResponse res = new DefaultAppleResponse(
129:                        cocoonResponse);
130:
131:                try {
132:                    app.process(req, res);
133:                } finally {
134:                    if (wk == null) {
135:                        // dispose stateless apple immediatelly
136:                        if (app instanceof  Disposable) {
137:                            try {
138:                                ((Disposable) app).dispose();
139:                            } catch (Exception e) {
140:                                getLogger().error(
141:                                        "Error disposing Apple instance.", e);
142:                            }
143:                        }
144:                    }
145:                }
146:
147:                if (res.isRedirect()) {
148:                    redirector.redirect(false, res.getURI());
149:                } else {
150:                    String uri = res.getURI();
151:                    if (getLogger().isDebugEnabled()) {
152:                        getLogger().debug(
153:                                "Apple forwards to "
154:                                        + uri
155:                                        + " with bizdata= "
156:                                        + res.getData()
157:                                        + (wk != null ? " and continuationid= "
158:                                                + wk.getId()
159:                                                : " without continuationid"));
160:                    }
161:
162:                    // Note: it is ok for wk to be null
163:                    this .forwardTo(uri, res.getData(), wk, redirector);
164:                }
165:
166:                //TODO allow for AppleResponse to set some boolean saying the use case
167:                // is completed and the continuation can be invalidated ?
168:            }
169:
170:            public void disposeContinuation(WebContinuation webContinuation) {
171:                AppleController app = (AppleController) webContinuation
172:                        .getContinuation();
173:                if (app instanceof  Disposable) {
174:                    ((Disposable) app).dispose();
175:                }
176:
177:            }
178:
179:            public void service(ServiceManager serviceManager)
180:                    throws ServiceException {
181:                super .service(serviceManager);
182:                //this.serviceManager = serviceManager;
183:            }
184:
185:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.