001: /*
002: * ========================================================================
003: *
004: * Copyright 2001-2003 The Apache Software Foundation.
005: *
006: * Licensed under the Apache License, Version 2.0 (the "License");
007: * you may not use this file except in compliance with the License.
008: * You may obtain a copy of the License at
009: *
010: * http://www.apache.org/licenses/LICENSE-2.0
011: *
012: * Unless required by applicable law or agreed to in writing, software
013: * distributed under the License is distributed on an "AS IS" BASIS,
014: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015: * See the License for the specific language governing permissions and
016: * limitations under the License.
017: *
018: * ========================================================================
019: */
020: package org.apache.cactus.server;
021:
022: import java.lang.reflect.Method;
023:
024: import java.util.Set;
025:
026: import javax.servlet.ServletContext;
027:
028: /**
029: * Wrapper around Servlet 2.3 <code>ServletContext</code>. This wrapper
030: * provides additional behaviour (see
031: * <code>AbstractServletContextWrapper</code>).
032: *
033: * @version $Id: ServletContextWrapper.java 238991 2004-05-22 11:34:50Z vmassol $
034: * @see RequestDispatcherWrapper
035: */
036: public class ServletContextWrapper extends
037: AbstractServletContextWrapper {
038: /**
039: * @param theOriginalContext the original servlet context object
040: */
041: public ServletContextWrapper(ServletContext theOriginalContext) {
042: super (theOriginalContext);
043: }
044:
045: /**
046: * @see ServletContext#getServletContextName()
047: */
048: public String getServletContextName() {
049: return this .originalContext.getServletContextName();
050: }
051:
052: /**
053: * @see #getResourcePaths(String)
054: */
055: public Set getResourcePaths() {
056: Set returnSet;
057:
058: // Use reflection because newest Servlet API 2.3 changes removed this
059: // method
060: try {
061: Method method = this .originalContext.getClass().getMethod(
062: "getResourcePaths", null);
063:
064: if (method != null) {
065: returnSet = (Set) method.invoke(this .originalContext,
066: null);
067: } else {
068: throw new RuntimeException(
069: "Method ServletContext."
070: + "getResourcePaths() no longer supported by your servlet "
071: + "engine !");
072: }
073: } catch (Exception e) {
074: e.printStackTrace();
075: throw new RuntimeException("Error getting/calling method "
076: + "getResourcePaths()");
077: }
078:
079: return returnSet;
080: }
081:
082: /**
083: * Added to support the changes of the Jakarta Servlet API 2.3 of the
084: * 17/03/2001 (in anticipation of the upcoming draft of Servlet 2.3). Kept
085: * the method without parameters for servlet engines that do not have
086: * upgraded yet to the new signature.
087: *
088: * @see ServletContext#getResourcePaths(String)
089: */
090: public Set getResourcePaths(String thePath) {
091: Set returnSet;
092:
093: // Check if the method exist (for servlet engines that do not have
094: // upgraded yet)
095: try {
096: Method method = this .originalContext.getClass().getMethod(
097: "getResourcePaths", new Class[] { String.class });
098:
099: if (method != null) {
100: returnSet = (Set) method.invoke(this .originalContext,
101: new Object[] { thePath });
102: } else {
103: throw new RuntimeException(
104: "Method ServletContext."
105: + "getResourcePaths(String path) not supported yet by your "
106: + "servlet engine !");
107: }
108: } catch (Exception e) {
109: e.printStackTrace();
110: throw new RuntimeException("Error getting/calling method "
111: + "getResourcePaths(String path)");
112: }
113:
114: return returnSet;
115: }
116: }
|