Source Code Cross Referenced for ApplicationFilterConfig.java in  » Sevlet-Container » tomcat-catalina » org » apache » catalina » core » 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 » Sevlet Container » tomcat catalina » org.apache.catalina.core 
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:
017:        package org.apache.catalina.core;
018:
019:        import java.io.Serializable;
020:        import java.util.ArrayList;
021:        import java.util.Enumeration;
022:        import java.util.Map;
023:
024:        import javax.servlet.Filter;
025:        import javax.servlet.FilterConfig;
026:        import javax.servlet.ServletContext;
027:        import javax.servlet.ServletException;
028:
029:        import org.apache.catalina.Context;
030:        import org.apache.catalina.deploy.FilterDef;
031:        import org.apache.catalina.security.SecurityUtil;
032:        import org.apache.catalina.util.Enumerator;
033:        import org.apache.tomcat.util.log.SystemLogHandler;
034:
035:        /**
036:         * Implementation of a <code>javax.servlet.FilterConfig</code> useful in
037:         * managing the filter instances instantiated when a web application
038:         * is first started.
039:         *
040:         * @author Craig R. McClanahan
041:         * @version $Revision: 1.8 $ $Date: 2004/02/27 14:58:42 $
042:         */
043:
044:        final class ApplicationFilterConfig implements  FilterConfig,
045:                Serializable {
046:
047:            private static org.apache.commons.logging.Log log = org.apache.commons.logging.LogFactory
048:                    .getLog(ApplicationFilterConfig.class);
049:
050:            // ----------------------------------------------------------- Constructors
051:
052:            /**
053:             * Construct a new ApplicationFilterConfig for the specified filter
054:             * definition.
055:             *
056:             * @param context The context with which we are associated
057:             * @param filterDef Filter definition for which a FilterConfig is to be
058:             *  constructed
059:             *
060:             * @exception ClassCastException if the specified class does not implement
061:             *  the <code>javax.servlet.Filter</code> interface
062:             * @exception ClassNotFoundException if the filter class cannot be found
063:             * @exception IllegalAccessException if the filter class cannot be
064:             *  publicly instantiated
065:             * @exception InstantiationException if an exception occurs while
066:             *  instantiating the filter object
067:             * @exception ServletException if thrown by the filter's init() method
068:             */
069:            public ApplicationFilterConfig(Context context, FilterDef filterDef)
070:                    throws ClassCastException, ClassNotFoundException,
071:                    IllegalAccessException, InstantiationException,
072:                    ServletException {
073:
074:                super ();
075:                this .context = context;
076:                setFilterDef(filterDef);
077:
078:            }
079:
080:            // ----------------------------------------------------- Instance Variables
081:
082:            /**
083:             * The Context with which we are associated.
084:             */
085:            private Context context = null;
086:
087:            /**
088:             * The application Filter we are configured for.
089:             */
090:            private transient Filter filter = null;
091:
092:            /**
093:             * The <code>FilterDef</code> that defines our associated Filter.
094:             */
095:            private FilterDef filterDef = null;
096:
097:            // --------------------------------------------------- FilterConfig Methods
098:
099:            /**
100:             * Return the name of the filter we are configuring.
101:             */
102:            public String getFilterName() {
103:
104:                return (filterDef.getFilterName());
105:
106:            }
107:
108:            /**
109:             * Return a <code>String</code> containing the value of the named
110:             * initialization parameter, or <code>null</code> if the parameter
111:             * does not exist.
112:             *
113:             * @param name Name of the requested initialization parameter
114:             */
115:            public String getInitParameter(String name) {
116:
117:                Map map = filterDef.getParameterMap();
118:                if (map == null)
119:                    return (null);
120:                else
121:                    return ((String) map.get(name));
122:
123:            }
124:
125:            /**
126:             * Return an <code>Enumeration</code> of the names of the initialization
127:             * parameters for this Filter.
128:             */
129:            public Enumeration getInitParameterNames() {
130:
131:                Map map = filterDef.getParameterMap();
132:                if (map == null)
133:                    return (new Enumerator(new ArrayList()));
134:                else
135:                    return (new Enumerator(map.keySet()));
136:
137:            }
138:
139:            /**
140:             * Return the ServletContext of our associated web application.
141:             */
142:            public ServletContext getServletContext() {
143:
144:                return (this .context.getServletContext());
145:
146:            }
147:
148:            /**
149:             * Return a String representation of this object.
150:             */
151:            public String toString() {
152:
153:                StringBuffer sb = new StringBuffer("ApplicationFilterConfig[");
154:                sb.append("name=");
155:                sb.append(filterDef.getFilterName());
156:                sb.append(", filterClass=");
157:                sb.append(filterDef.getFilterClass());
158:                sb.append("]");
159:                return (sb.toString());
160:
161:            }
162:
163:            // -------------------------------------------------------- Package Methods
164:
165:            /**
166:             * Return the application Filter we are configured for.
167:             *
168:             * @exception ClassCastException if the specified class does not implement
169:             *  the <code>javax.servlet.Filter</code> interface
170:             * @exception ClassNotFoundException if the filter class cannot be found
171:             * @exception IllegalAccessException if the filter class cannot be
172:             *  publicly instantiated
173:             * @exception InstantiationException if an exception occurs while
174:             *  instantiating the filter object
175:             * @exception ServletException if thrown by the filter's init() method
176:             */
177:            Filter getFilter() throws ClassCastException,
178:                    ClassNotFoundException, IllegalAccessException,
179:                    InstantiationException, ServletException {
180:
181:                // Return the existing filter instance, if any
182:                if (this .filter != null)
183:                    return (this .filter);
184:
185:                // Identify the class loader we will be using
186:                String filterClass = filterDef.getFilterClass();
187:                ClassLoader classLoader = null;
188:                if (filterClass.startsWith("org.apache.catalina."))
189:                    classLoader = this .getClass().getClassLoader();
190:                else
191:                    classLoader = context.getLoader().getClassLoader();
192:
193:                ClassLoader oldCtxClassLoader = Thread.currentThread()
194:                        .getContextClassLoader();
195:
196:                // Instantiate a new instance of this filter and return it
197:                Class clazz = classLoader.loadClass(filterClass);
198:                this .filter = (Filter) clazz.newInstance();
199:                if (context instanceof  StandardContext
200:                        && ((StandardContext) context).getSwallowOutput()) {
201:                    try {
202:                        SystemLogHandler.startCapture();
203:                        filter.init(this );
204:                    } finally {
205:                        String log = SystemLogHandler.stopCapture();
206:                        if (log != null && log.length() > 0) {
207:                            getServletContext().log(log);
208:                        }
209:                    }
210:                } else {
211:                    filter.init(this );
212:                }
213:                return (this .filter);
214:
215:            }
216:
217:            /**
218:             * Return the filter definition we are configured for.
219:             */
220:            FilterDef getFilterDef() {
221:
222:                return (this .filterDef);
223:
224:            }
225:
226:            /**
227:             * Release the Filter instance associated with this FilterConfig,
228:             * if there is one.
229:             */
230:            void release() {
231:
232:                if (this .filter != null) {
233:                    if (System.getSecurityManager() != null) {
234:                        try {
235:                            SecurityUtil.doAsPrivilege("destroy", filter);
236:                            SecurityUtil.remove(filter);
237:                        } catch (java.lang.Exception ex) {
238:                            log.error("ApplicationFilterConfig.doAsPrivilege",
239:                                    ex);
240:                        }
241:                    } else {
242:                        filter.destroy();
243:                    }
244:                }
245:                this .filter = null;
246:
247:            }
248:
249:            /**
250:             * Set the filter definition we are configured for.  This has the side
251:             * effect of instantiating an instance of the corresponding filter class.
252:             *
253:             * @param filterDef The new filter definition
254:             *
255:             * @exception ClassCastException if the specified class does not implement
256:             *  the <code>javax.servlet.Filter</code> interface
257:             * @exception ClassNotFoundException if the filter class cannot be found
258:             * @exception IllegalAccessException if the filter class cannot be
259:             *  publicly instantiated
260:             * @exception InstantiationException if an exception occurs while
261:             *  instantiating the filter object
262:             * @exception ServletException if thrown by the filter's init() method
263:             */
264:            void setFilterDef(FilterDef filterDef) throws ClassCastException,
265:                    ClassNotFoundException, IllegalAccessException,
266:                    InstantiationException, ServletException {
267:
268:                this .filterDef = filterDef;
269:                if (filterDef == null) {
270:
271:                    // Release any previously allocated filter instance
272:                    if (this .filter != null) {
273:                        if (System.getSecurityManager() != null) {
274:                            try {
275:                                SecurityUtil.doAsPrivilege("destroy", filter);
276:                                SecurityUtil.remove(filter);
277:                            } catch (java.lang.Exception ex) {
278:                                log
279:                                        .error(
280:                                                "ApplicationFilterConfig.doAsPrivilege",
281:                                                ex);
282:                            }
283:                        } else {
284:                            filter.destroy();
285:                        }
286:                    }
287:                    this .filter = null;
288:
289:                } else {
290:
291:                    // Allocate a new filter instance
292:                    Filter filter = getFilter();
293:
294:                }
295:
296:            }
297:
298:            // -------------------------------------------------------- Private Methods
299:
300:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.