Source Code Cross Referenced for DefaultChainHandler.java in  » Web-Server » pygmy-httpd » pygmy » handlers » 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 » Web Server » pygmy httpd » pygmy.handlers 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


01:        package pygmy.handlers;
02:
03:        import pygmy.core.*;
04:
05:        import java.io.IOException;
06:        import java.util.StringTokenizer;
07:        import java.util.List;
08:        import java.util.ArrayList;
09:        import java.util.Iterator;
10:        import java.util.logging.Logger;
11:        import java.util.logging.Level;
12:
13:        /**
14:         * This is the default implementation of a chain of handlers.  The .chain parameter defines the names of the
15:         * handlers in the chain, and it defines the order in which those handlers will be called.  Each handler name is
16:         * seperated by either a ' ' (space) or a ',' (comma).  This handler will then try to create a handler for each of
17:         * the handler names by looking at configuration property {handler-name}.class.  This handler also has a .url-prefix
18:         * parameter it uses to know when this handler should pass the request to the chain.
19:         *
20:         * <table class="inner">
21:         * <tr class="header"><td>Parameter Name</td><td>Explanation</td><td>Default Value</td><td>Required</td></tr>
22:         * <tr class="row"><td>url-prefix</td><td>The prefix to filter request urls.</td><td>None</td><td>Yes</td></tr>
23:         * <tr class="altrow"><td>chain</td><td>A space or comma seperated list of the names of the handlers within the chain.</td><td>None</td><td>Yes</td></tr>
24:         * <tr class="row"><td>class</td><td>For each of the names in the chain property, this is appended the name to find the classname to instatiate.</td><td>None</td><td>Yes</td></tr>
25:         * </table>
26:         */
27:        public class DefaultChainHandler extends AbstractHandler implements 
28:                Handler {
29:            private static final Logger log = Logger
30:                    .getLogger(DefaultChainHandler.class.getName());
31:
32:            public static String CHAIN = ".chain";
33:
34:            public static final ConfigOption CHAIN_OPTION = new ConfigOption(
35:                    "chain", true,
36:                    "A comma seperated list of handler names to chain together.");
37:
38:            private List chain;
39:
40:            public boolean initialize(String handlerName, Server server) {
41:                super .initialize(handlerName, server);
42:                this .chain = new ArrayList();
43:                initializeChain(server);
44:                return true;
45:            }
46:
47:            private void initializeChain(Server server) {
48:                StringTokenizer tokenizer = new StringTokenizer(CHAIN_OPTION
49:                        .getProperty(server, handlerName), " ,");
50:                while (tokenizer.hasMoreTokens()) {
51:                    String chainChildName = tokenizer.nextToken();
52:                    try {
53:                        Handler handler = (Handler) server
54:                                .constructPygmyObject(chainChildName);
55:                        if (handler.initialize(chainChildName, server)) {
56:                            chain.add(handler);
57:                        } else {
58:                            log.severe(chainChildName + " was not initialized");
59:                        }
60:                    } catch (ClassCastException e) {
61:                        log
62:                                .log(
63:                                        Level.SEVERE,
64:                                        chainChildName
65:                                                + " class does not implement the Handler interface.",
66:                                        e);
67:                    }
68:                }
69:            }
70:
71:            public boolean handle(Request request, Response response)
72:                    throws IOException {
73:                boolean hasBeenHandled = false;
74:                for (Iterator i = chain.iterator(); i.hasNext()
75:                        && !hasBeenHandled;) {
76:                    Handler handler = (Handler) i.next();
77:                    hasBeenHandled = handler.handle(request, response);
78:                }
79:                return hasBeenHandled;
80:            }
81:
82:            public boolean shutdown(Server server) {
83:                boolean success = true;
84:                if (chain != null) {
85:                    for (Iterator i = chain.iterator(); i.hasNext();) {
86:                        Handler current = (Handler) i.next();
87:                        boolean currentSuccess = current.shutdown(server);
88:                        success = success && currentSuccess;
89:                    }
90:                }
91:
92:                return success;
93:            }
94:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.