Source Code Cross Referenced for ChainProcessor.java in  » Library » Apache-commons-chain-1.1-src » org » apache » commons » chain » web » servlet » 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 » Library » Apache commons chain 1.1 src » org.apache.commons.chain.web.servlet 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright 1999-2004 The Apache Software Foundation
003:         *
004:         * Licensed under the Apache License, Version 2.0 (the "License");
005:         * you may not use this file except in compliance with the License.
006:         * You may obtain a copy of the License at
007:         *
008:         *     http://www.apache.org/licenses/LICENSE-2.0
009:         *
010:         * Unless required by applicable law or agreed to in writing, software
011:         * distributed under the License is distributed on an "AS IS" BASIS,
012:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013:         * See the License for the specific language governing permissions and
014:         * limitations under the License.
015:         */
016:        package org.apache.commons.chain.web.servlet;
017:
018:        import java.io.IOException;
019:        import javax.servlet.ServletException;
020:        import javax.servlet.http.HttpServletRequest;
021:        import javax.servlet.http.HttpServletResponse;
022:        import org.apache.commons.chain.Catalog;
023:        import org.apache.commons.chain.CatalogFactory;
024:        import org.apache.commons.chain.Command;
025:        import org.apache.commons.chain.web.ChainServlet;
026:
027:        /**
028:         * <p>Custom subclass of {@link ChainServlet} that also dispatches incoming
029:         * requests to a configurable {@link Command} loaded from the specified
030:         * {@link Catalog}.</p>
031:         *
032:         * <p>In addition to the <em>servlet</em> init parameters supported by
033:         * {@link ChainServlet}, this class supports the following additional
034:         * parameters:</p>
035:         * <ul>
036:         * <li><strong>org.apache.commons.chain.CATALOG</strong> - Name of the
037:         *     catalog from which to acquire commands to be executed.  If not
038:         *     specified, the default catalog for this application will be used.</li>
039:         * <li><strong>org.apache.commons.chain.COMMAND</strong> - Name of the
040:         *     {@link Command} (looked up in our configured {@link Catalog} used
041:         *     to process all incoming servlet requests.  If not specified,
042:         *     defaults to <code>command</code>.</li>
043:         * </ul>
044:         *
045:         * <p>Also, the <code>org.apache.commons.chain.CONFIG_ATTR</code>
046:         * init parameter is also used to identify the
047:         * {@link org.apache.commons.chain.Context} attribute under
048:         * which our configured {@link Catalog} will be made available to
049:         * {@link Command}s processing our requests, in addition to its definition
050:         * of the <code>ServletContext</code> attribute key under which the
051:         * {@link Catalog} is available.</p>
052:         */
053:
054:        public class ChainProcessor extends ChainServlet {
055:
056:            // ------------------------------------------------------ Manifest Constants
057:
058:            /**
059:             * <p>The name of the servlet init parameter containing the name of the
060:             * {@link Catalog} to use for processing incoming requests.</p>
061:             */
062:            public static final String CATALOG = "org.apache.commons.chain.CATALOG";
063:
064:            /**
065:             * <p>The default request attribute under which we expose the
066:             * {@link Catalog} being used to subordinate {@link Command}s.</p>
067:             */
068:            public static final String CATALOG_DEFAULT = "org.apache.commons.chain.CATALOG";
069:
070:            /**
071:             * <p>The name of the servlet init parameter containing the name of the
072:             * {@link Command} (loaded from our configured {@link Catalog} to use
073:             * for processing each incoming request.</p>
074:             */
075:            public static final String COMMAND = "org.apache.commons.chain.COMMAND";
076:
077:            /**
078:             * <p>The default command name.</p>
079:             */
080:            private static final String COMMAND_DEFAULT = "command";
081:
082:            // ------------------------------------------------------ Instance Variables
083:
084:            /**
085:             * <p>The name of the context attribute under which our {@link Catalog}
086:             * is stored.  This value is also used as the name of the
087:             * context attribute under which the catalog is exposed to commands.
088:             * If not specified, we will look up commands in the appropriate
089:             * {@link Catalog} retrieved from our {@link CatalogFactory}.</p>
090:             */
091:            private String attribute = null;
092:
093:            /**
094:             * <p>The name of the {@link Catalog} to retrieve from the
095:             * {@link CatalogFactory} for this application, or <code>null</code>
096:             * to select the default {@link Catalog}.</p>
097:             */
098:            private String catalog = null;
099:
100:            /**
101:             * <p>The name of the {@link Command} to be executed for each incoming
102:             * request.</p>
103:             */
104:            private String command = null;
105:
106:            /**
107:             * <p>The {@link CatalogFactory} for this application.</p>
108:             */
109:            private CatalogFactory factory = null;
110:
111:            // --------------------------------------------------------- Servlet Methods
112:
113:            /**
114:             * <p>Clean up as this application is shut down.</p>
115:             */
116:            public void destroy() {
117:
118:                super .destroy();
119:                attribute = null;
120:                catalog = null;
121:                command = null;
122:                factory = null;
123:
124:            }
125:
126:            /**
127:             * <p>Cache the name of the command we should execute for each request.</p>
128:             *
129:             * @exception ServletException if an initialization error occurs
130:             */
131:            public void init() throws ServletException {
132:
133:                super .init();
134:                attribute = getServletConfig().getInitParameter(CONFIG_ATTR);
135:                catalog = getServletConfig().getInitParameter(CATALOG);
136:                command = getServletConfig().getInitParameter(COMMAND);
137:                if (command == null) {
138:                    command = COMMAND_DEFAULT;
139:                }
140:                factory = CatalogFactory.getInstance();
141:
142:            }
143:
144:            /**
145:             * <p>Configure a {@link ServletWebContext} for the current request, and
146:             * pass it to the <code>execute()</code> method of the specified
147:             * {@link Command}, loaded from our configured {@link Catalog}.</p>
148:             *
149:             * @param request The request we are processing
150:             * @param response The response we are creating
151:             *
152:             * @exception IOException if an input/output error occurs
153:             * @exception ServletException if a servlet exception occurs
154:             */
155:            public void service(HttpServletRequest request,
156:                    HttpServletResponse response) throws IOException,
157:                    ServletException {
158:
159:                ServletWebContext context = new ServletWebContext(
160:                        getServletContext(), request, response);
161:                Catalog theCatalog = null;
162:                if (attribute != null) {
163:                    theCatalog = (Catalog) getServletContext().getAttribute(
164:                            this .attribute);
165:                } else if (catalog != null) {
166:                    theCatalog = factory.getCatalog(catalog);
167:                } else {
168:                    theCatalog = factory.getCatalog();
169:                }
170:                if (attribute == null) {
171:                    request.setAttribute(CATALOG_DEFAULT, theCatalog);
172:                }
173:                Command command = theCatalog.getCommand(this .command);
174:                try {
175:                    command.execute(context);
176:                } catch (Exception e) {
177:                    throw new ServletException(e);
178:                }
179:
180:            }
181:
182:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.