001: /*
002: * Copyright 2005 Joe Walker
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.directwebremoting.util;
017:
018: import java.util.Collections;
019: import java.util.Enumeration;
020: import java.util.HashMap;
021: import java.util.Map;
022:
023: import javax.servlet.ServletConfig;
024: import javax.servlet.ServletContext;
025:
026: /**
027: * A fake implementation of ServletConfig for cases (Like inside Spring) when
028: * you don't have a real one.
029: * @author Joe Walker [joe at getahead dot ltd dot uk]
030: */
031: public class FakeServletConfig implements ServletConfig {
032: /**
033: * @param name The servlet name
034: * @param servletContext The ServletContext
035: */
036: public FakeServletConfig(String name, ServletContext servletContext) {
037: this (name, servletContext, null);
038: }
039:
040: /**
041: * @param name The servlet name
042: * @param servletContext The ServletContext
043: * @param initParameters Optional init parameters (can be null)
044: */
045: public FakeServletConfig(String name,
046: ServletContext servletContext,
047: Map<String, String> initParameters) {
048: this .name = name;
049: this .servletContext = servletContext;
050: this .initParameters = initParameters;
051:
052: if (this .initParameters == null) {
053: this .initParameters = new HashMap<String, String>();
054: }
055: }
056:
057: /* (non-Javadoc)
058: * @see javax.servlet.ServletConfig#getServletName()
059: */
060: public String getServletName() {
061: return name;
062: }
063:
064: /* (non-Javadoc)
065: * @see javax.servlet.ServletConfig#getServletContext()
066: */
067: public ServletContext getServletContext() {
068: return servletContext;
069: }
070:
071: /* (non-Javadoc)
072: * @see javax.servlet.ServletConfig#getInitParameter(java.lang.String)
073: */
074: public String getInitParameter(String paramName) {
075: Object obj = initParameters.get(paramName);
076: if (obj instanceof String) {
077: return (String) obj;
078: } else {
079: return null;
080: }
081: }
082:
083: /* (non-Javadoc)
084: * @see javax.servlet.ServletConfig#getInitParameterNames()
085: */
086: public Enumeration<String> getInitParameterNames() {
087: return Collections.enumeration(initParameters.keySet());
088: }
089:
090: /**
091: * The servlet name
092: */
093: private final String name;
094:
095: /**
096: * The servlet deployment information
097: */
098: private ServletContext servletContext;
099:
100: /**
101: * Initialization parameters
102: */
103: private Map<String, String> initParameters;
104: }
|