KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > directwebremoting > util > FakeServletConfig


1 /*
2  * Copyright 2005 Joe Walker
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 package org.directwebremoting.util;
17
18 import java.util.Collections JavaDoc;
19 import java.util.Enumeration JavaDoc;
20 import java.util.HashMap JavaDoc;
21 import java.util.Map JavaDoc;
22
23 import javax.servlet.ServletConfig JavaDoc;
24 import javax.servlet.ServletContext JavaDoc;
25
26 /**
27  * A fake implementation of ServletConfig for cases (Like inside Spring) when
28  * you don't have a real one.
29  * @author Joe Walker [joe at getahead dot ltd dot uk]
30  */

31 public class FakeServletConfig implements ServletConfig JavaDoc
32 {
33     /**
34      * @param name The servlet name
35      * @param servletContext The ServletContext
36      */

37     public FakeServletConfig(String JavaDoc name, ServletContext JavaDoc servletContext)
38     {
39         this(name, servletContext, null);
40     }
41
42     /**
43      * @param name The servlet name
44      * @param servletContext The ServletContext
45      * @param initParameters Optional init parameters (can be null)
46      */

47     public FakeServletConfig(String JavaDoc name, ServletContext JavaDoc servletContext, Map JavaDoc initParameters)
48     {
49         this.name = name;
50         this.servletContext = servletContext;
51         this.initParameters = initParameters;
52
53         if (this.initParameters == null)
54         {
55             this.initParameters = new HashMap JavaDoc();
56         }
57     }
58
59     /* (non-Javadoc)
60      * @see javax.servlet.ServletConfig#getServletName()
61      */

62     public String JavaDoc getServletName()
63     {
64         return name;
65     }
66
67     /* (non-Javadoc)
68      * @see javax.servlet.ServletConfig#getServletContext()
69      */

70     public ServletContext JavaDoc getServletContext()
71     {
72         return servletContext;
73     }
74
75     /* (non-Javadoc)
76      * @see javax.servlet.ServletConfig#getInitParameter(java.lang.String)
77      */

78     public String JavaDoc getInitParameter(String JavaDoc paramName)
79     {
80         Object JavaDoc obj = initParameters.get(paramName);
81         if (obj instanceof String JavaDoc)
82         {
83             return (String JavaDoc) obj;
84         }
85         else
86         {
87             return null;
88         }
89     }
90
91     /* (non-Javadoc)
92      * @see javax.servlet.ServletConfig#getInitParameterNames()
93      */

94     public Enumeration JavaDoc getInitParameterNames()
95     {
96         return Collections.enumeration(initParameters.keySet());
97     }
98
99     /**
100      * The servlet name
101      */

102     private final String JavaDoc name;
103
104     /**
105      * The servlet deployment information
106      */

107     private ServletContext JavaDoc servletContext;
108
109     /**
110      * Initialization parameters
111      */

112     private Map JavaDoc initParameters;
113 }
114
Popular Tags