|
|||||||||||||||||||
| 30 day Evaluation Version distributed via the Maven Jar Repository. Clover is not free. You have 30 days to evaluate it. Please visit http://www.thecortex.net/clover to obtain a licensed version of Clover | |||||||||||||||||||
| Source file | Conditionals | Statements | Methods | TOTAL | |||||||||||||||
| AbstractServletConfigWrapper.java | 20% | 37.5% | 50% | 35.7% |
|
||||||||||||||
| 1 |
/*
|
|
| 2 |
* ========================================================================
|
|
| 3 |
*
|
|
| 4 |
* Copyright 2001-2003 The Apache Software Foundation.
|
|
| 5 |
*
|
|
| 6 |
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
| 7 |
* you may not use this file except in compliance with the License.
|
|
| 8 |
* You may obtain a copy of the License at
|
|
| 9 |
*
|
|
| 10 |
* http://www.apache.org/licenses/LICENSE-2.0
|
|
| 11 |
*
|
|
| 12 |
* Unless required by applicable law or agreed to in writing, software
|
|
| 13 |
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
| 14 |
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
| 15 |
* See the License for the specific language governing permissions and
|
|
| 16 |
* limitations under the License.
|
|
| 17 |
*
|
|
| 18 |
* ========================================================================
|
|
| 19 |
*/
|
|
| 20 |
package org.apache.cactus.server;
|
|
| 21 |
|
|
| 22 |
import java.util.Enumeration;
|
|
| 23 |
import java.util.Hashtable;
|
|
| 24 |
import java.util.Vector;
|
|
| 25 |
|
|
| 26 |
import javax.servlet.ServletConfig;
|
|
| 27 |
import javax.servlet.ServletContext;
|
|
| 28 |
|
|
| 29 |
/**
|
|
| 30 |
* Abstract wrapper around <code>ServletConfig</code> which overrides the
|
|
| 31 |
* <code>getServletContext()</code> method to return our own wrapper around
|
|
| 32 |
* <code>ServletContext</code>. This class provides a common implementation
|
|
| 33 |
* of the wrapper for the different servlet API.
|
|
| 34 |
*
|
|
| 35 |
* @version $Id: AbstractServletConfigWrapper.java 239054 2004-10-24 01:30:23Z felipeal $
|
|
| 36 |
*/
|
|
| 37 |
public abstract class AbstractServletConfigWrapper |
|
| 38 |
implements ServletConfig
|
|
| 39 |
{
|
|
| 40 |
/**
|
|
| 41 |
* The original servlet config object
|
|
| 42 |
*/
|
|
| 43 |
protected ServletConfig originalConfig;
|
|
| 44 |
|
|
| 45 |
/**
|
|
| 46 |
* List of parameters set using the <code>setInitParameter()</code> method.
|
|
| 47 |
*/
|
|
| 48 |
protected Hashtable initParameters;
|
|
| 49 |
|
|
| 50 |
/**
|
|
| 51 |
* Simulated name of the servlet
|
|
| 52 |
*/
|
|
| 53 |
protected String servletName;
|
|
| 54 |
|
|
| 55 |
/**
|
|
| 56 |
* @param theOriginalConfig the original servlet config object
|
|
| 57 |
*/
|
|
| 58 | 19 |
public AbstractServletConfigWrapper(ServletConfig theOriginalConfig)
|
| 59 |
{
|
|
| 60 | 19 |
this.originalConfig = theOriginalConfig;
|
| 61 | 19 |
this.initParameters = new Hashtable(); |
| 62 |
} |
|
| 63 |
|
|
| 64 |
/**
|
|
| 65 |
* Sets a parameter as if it were set in the <code>web.xml</code> file.
|
|
| 66 |
*
|
|
| 67 |
* @param theName the parameter's name
|
|
| 68 |
* @param theValue the parameter's value
|
|
| 69 |
*/
|
|
| 70 | 0 |
public void setInitParameter(String theName, String theValue) |
| 71 |
{
|
|
| 72 | 0 |
this.initParameters.put(theName, theValue);
|
| 73 |
} |
|
| 74 |
|
|
| 75 |
/**
|
|
| 76 |
* Sets the servlet name. That will be the value returned by the
|
|
| 77 |
* <code>getServletName()</code> method.
|
|
| 78 |
*
|
|
| 79 |
* @param theServletName the servlet's name
|
|
| 80 |
*/
|
|
| 81 | 0 |
public void setServletName(String theServletName) |
| 82 |
{
|
|
| 83 | 0 |
this.servletName = theServletName;
|
| 84 |
} |
|
| 85 |
|
|
| 86 |
/**
|
|
| 87 |
* @return the original unmodified config object
|
|
| 88 |
* @since 1.5
|
|
| 89 |
*/
|
|
| 90 | 0 |
public ServletConfig getOriginalConfig()
|
| 91 |
{
|
|
| 92 | 0 |
return this.originalConfig; |
| 93 |
} |
|
| 94 |
|
|
| 95 |
//--Overridden methods ----------------------------------------------------
|
|
| 96 |
|
|
| 97 |
/**
|
|
| 98 |
* @return our own wrapped servlet context object
|
|
| 99 |
*/
|
|
| 100 | 3 |
public ServletContext getServletContext()
|
| 101 |
{
|
|
| 102 | 3 |
return new ServletContextWrapper( |
| 103 |
this.originalConfig.getServletContext());
|
|
| 104 |
} |
|
| 105 |
|
|
| 106 |
/**
|
|
| 107 |
* @param theName the name of the parameter's value to return
|
|
| 108 |
* @return the value of the parameter, looking for it first in the list of
|
|
| 109 |
* parameters set using the <code>setInitParameter()</code> method
|
|
| 110 |
* and then in those set in <code>web.xml</code>.
|
|
| 111 |
*/
|
|
| 112 | 1 |
public String getInitParameter(String theName)
|
| 113 |
{
|
|
| 114 |
// Look first in the list of parameters set using the
|
|
| 115 |
// setInitParameter() method.
|
|
| 116 | 1 |
String value = (String) this.initParameters.get(theName);
|
| 117 |
|
|
| 118 | 1 |
if (value == null) |
| 119 |
{
|
|
| 120 | 1 |
value = this.originalConfig.getInitParameter(theName);
|
| 121 |
} |
|
| 122 |
|
|
| 123 | 1 |
return value;
|
| 124 |
} |
|
| 125 |
|
|
| 126 |
/**
|
|
| 127 |
* @return the union of the parameters defined in the Redirector
|
|
| 128 |
* <code>web.xml</code> file and the one set using the
|
|
| 129 |
* <code>setInitParameter()</code> method.
|
|
| 130 |
*/
|
|
| 131 | 0 |
public Enumeration getInitParameterNames()
|
| 132 |
{
|
|
| 133 | 0 |
Vector names = new Vector();
|
| 134 |
|
|
| 135 |
// Add parameters that were added using setInitParameter()
|
|
| 136 | 0 |
Enumeration en = this.initParameters.keys();
|
| 137 |
|
|
| 138 | 0 |
while (en.hasMoreElements())
|
| 139 |
{
|
|
| 140 | 0 |
String value = (String) en.nextElement(); |
| 141 |
|
|
| 142 | 0 |
names.add(value); |
| 143 |
} |
|
| 144 |
|
|
| 145 |
// Add parameters from web.xml
|
|
| 146 | 0 |
en = this.originalConfig.getInitParameterNames();
|
| 147 |
|
|
| 148 | 0 |
while (en.hasMoreElements())
|
| 149 |
{
|
|
| 150 | 0 |
String value = (String) en.nextElement(); |
| 151 |
|
|
| 152 |
// Do not add parameters that have been overriden by calling
|
|
| 153 |
// the setInitParameter() method.
|
|
| 154 | 0 |
if (!names.contains(value))
|
| 155 |
{
|
|
| 156 | 0 |
names.add(value); |
| 157 |
} |
|
| 158 |
} |
|
| 159 |
|
|
| 160 | 0 |
return names.elements();
|
| 161 |
} |
|
| 162 |
|
|
| 163 |
/**
|
|
| 164 |
* @return the simulated servlet's name if defined or the redirector
|
|
| 165 |
* servlet's name
|
|
| 166 |
*/
|
|
| 167 | 1 |
public String getServletName()
|
| 168 |
{
|
|
| 169 | 1 |
if (this.servletName != null) |
| 170 |
{
|
|
| 171 | 0 |
return this.servletName; |
| 172 |
} |
|
| 173 |
|
|
| 174 | 1 |
return this.originalConfig.getServletName(); |
| 175 |
} |
|
| 176 |
} |
|
| 177 |
|
|
||||||||||