You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cactus-dev@jakarta.apache.org by vm...@apache.org on 2003/05/25 16:07:38 UTC
cvs commit: jakarta-cactus/framework/src/java/share/org/apache/cactus/server AbstractServletConfigWrapper.java
vmassol 2003/05/25 07:07:37
Modified: framework/src/java/j2ee12/org/apache/cactus/server
ServletConfigWrapper.java
framework/src/java/j2ee13/org/apache/cactus/server
ServletConfigWrapper.java
Added: framework/src/java/share/org/apache/cactus/server
AbstractServletConfigWrapper.java
Log:
Factorized commonalities in ServletConfigWrapper for Servlet APIs 2.2 and 2.3 and added a getOriginalConfig() method that returns the original config object.
Revision Changes Path
1.7 +6 -126 jakarta-cactus/framework/src/java/j2ee12/org/apache/cactus/server/ServletConfigWrapper.java
Index: ServletConfigWrapper.java
===================================================================
RCS file: /home/cvs/jakarta-cactus/framework/src/java/j2ee12/org/apache/cactus/server/ServletConfigWrapper.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- ServletConfigWrapper.java 24 May 2003 16:47:46 -0000 1.6
+++ ServletConfigWrapper.java 25 May 2003 14:07:37 -0000 1.7
@@ -56,143 +56,23 @@
*/
package org.apache.cactus.server;
-import java.util.Enumeration;
-import java.util.Hashtable;
-import java.util.Vector;
-
import javax.servlet.ServletConfig;
-import javax.servlet.ServletContext;
/**
- * Wrapper around <code>ServletConfig</code> which overrides the
- * <code>getServletContext()</code> method to return our own wrapper around
- * <code>ServletContext</code>.
+ * Wrapper around <code>ServletConfig</code> for Servlet API 2.2.
*
* @author <a href="mailto:vmassol@apache.org">Vincent Massol</a>
*
* @version $Id$
- * @see ServletContext
+ * @see AbstractServletConfigWrapper
*/
-public class ServletConfigWrapper implements ServletConfig
+public class ServletConfigWrapper extends AbstractServletConfigWrapper
{
/**
- * The original servlet config object
- */
- private ServletConfig originalConfig;
-
- /**
- * List of parameters set using the <code>setInitParameter()</code> method.
- */
- private Hashtable initParameters;
-
- /**
- * Simulated name of the servlet
- */
- private String servletName;
-
- /**
- * @param theOriginalConfig the original servlet config object
+ * @see AbstractServletConfigWrapper#AbstractServletConfigWrapper()
*/
public ServletConfigWrapper(ServletConfig theOriginalConfig)
{
- this.originalConfig = theOriginalConfig;
- this.initParameters = new Hashtable();
- }
-
- /**
- * Sets a parameter as if it were set in the <code>web.xml</code> file.
- *
- * @param theName the parameter's name
- * @param theValue the parameter's value
- */
- public void setInitParameter(String theName, String theValue)
- {
- this.initParameters.put(theName, theValue);
- }
-
- /**
- * Sets the servlet name. That will be the value returned by the
- * <code>getServletName()</code> method.
- *
- * @param theServletName the servlet's name
- */
- public void setServletName(String theServletName)
- {
- this.servletName = theServletName;
- }
-
- //--Overridden methods ----------------------------------------------------
-
- /**
- * @return our own wrapped servlet context object
- */
- public ServletContext getServletContext()
- {
- return new ServletContextWrapper(
- this.originalConfig.getServletContext());
- }
-
- /**
- * @param theName the name of the parameter's value to return
- * @return the value of the parameter, looking for it first in the list of
- * parameters set using the <code>setInitParameter()</code> method
- * and then in those set in <code>web.xml</code>.
- */
- public String getInitParameter(String theName)
- {
- // Look first in the list of parameters set using the
- // setInitParameter() method.
- String value = (String) this.initParameters.get(theName);
-
- if (value == null)
- {
- value = this.originalConfig.getInitParameter(theName);
- }
-
- return value;
- }
-
- /**
- * @return the union of the parameters defined in the Redirector
- * <code>web.xml</code> file and the one set using the
- * <code>setInitParameter()</code> method.
- */
- public Enumeration getInitParameterNames()
- {
- Vector names = new Vector();
-
- Enumeration enum = this.initParameters.keys();
-
- while (enum.hasMoreElements())
- {
- String value = (String) enum.nextElement();
-
- names.add(value);
- }
-
- enum = this.originalConfig.getInitParameterNames();
-
- while (enum.hasMoreElements())
- {
- String value = (String) enum.nextElement();
-
- names.add(value);
- }
-
- return names.elements();
- }
-
- /**
- * @return the simulated servlet's name if defined or the redirector
- * servlet's name
- */
- public String getServletName()
- {
- if (this.servletName != null)
- {
- return this.servletName;
- }
-
- return this.originalConfig.getServletName();
+ super(theOriginalConfig);
}
}
1.7 +6 -135 jakarta-cactus/framework/src/java/j2ee13/org/apache/cactus/server/ServletConfigWrapper.java
Index: ServletConfigWrapper.java
===================================================================
RCS file: /home/cvs/jakarta-cactus/framework/src/java/j2ee13/org/apache/cactus/server/ServletConfigWrapper.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- ServletConfigWrapper.java 24 May 2003 16:47:45 -0000 1.6
+++ ServletConfigWrapper.java 25 May 2003 14:07:37 -0000 1.7
@@ -56,152 +56,23 @@
*/
package org.apache.cactus.server;
-import java.util.Enumeration;
-import java.util.Hashtable;
-import java.util.Vector;
-
import javax.servlet.ServletConfig;
-import javax.servlet.ServletContext;
/**
- * Wrapper around <code>ServletConfig</code> which overrides the
- * <code>getServletContext()</code> method to return our own wrapper around
- * <code>ServletContext</code>.
+ * Wrapper around <code>ServletConfig</code> for Servlet API 2.3.
*
* @author <a href="mailto:vmassol@apache.org">Vincent Massol</a>
*
* @version $Id$
- * @see ServletContext
+ * @see AbstractServletConfigWrapper
*/
-public class ServletConfigWrapper implements ServletConfig
+public class ServletConfigWrapper extends AbstractServletConfigWrapper
{
/**
- * The original servlet config object
- */
- private ServletConfig originalConfig;
-
- /**
- * List of parameters set using the <code>setInitParameter()</code> method.
- */
- private Hashtable initParameters;
-
- /**
- * Simulated name of the servlet
- */
- private String servletName;
-
- /**
- * @param theOriginalConfig the original servlet config object
+ * @see AbstractServletConfigWrapper#AbstractServletConfigWrapper()
*/
public ServletConfigWrapper(ServletConfig theOriginalConfig)
{
- this.originalConfig = theOriginalConfig;
- this.initParameters = new Hashtable();
- }
-
- /**
- * Sets a parameter as if it were set in the <code>web.xml</code> file.
- *
- * @param theName the parameter's name
- * @param theValue the parameter's value
- */
- public void setInitParameter(String theName, String theValue)
- {
- this.initParameters.put(theName, theValue);
- }
-
- /**
- * Sets the servlet name. That will be the value returned by the
- * <code>getServletName()</code> method.
- *
- * @param theServletName the servlet's name
- */
- public void setServletName(String theServletName)
- {
- this.servletName = theServletName;
- }
-
- //--Overridden methods ----------------------------------------------------
-
- /**
- * @return the simulated servlet's name if defined or the redirector
- * servlet's name
- */
- public String getServletName()
- {
- if (this.servletName != null)
- {
- return this.servletName;
- }
-
- return this.originalConfig.getServletName();
- }
-
- /**
- * @return our own wrapped servlet context object
- */
- public ServletContext getServletContext()
- {
- return new ServletContextWrapper(
- this.originalConfig.getServletContext());
- }
-
- /**
- * Return the union of the parameters defined in the Redirector
- * <code>web.xml</code> file and the one set using the
- * <code>setInitParameter()</code> method. The parameters with the same
- * name (and same case) are only returned once.
- *
- * @return the init parameters
- */
- public Enumeration getInitParameterNames()
- {
- Vector names = new Vector();
-
- // Add parameters that were added using setInitParameter()
- Enumeration enum = this.initParameters.keys();
-
- while (enum.hasMoreElements())
- {
- String value = (String) enum.nextElement();
-
- names.add(value);
- }
-
-
- // Add parameters from web.xml
- enum = this.originalConfig.getInitParameterNames();
-
- while (enum.hasMoreElements())
- {
- String value = (String) enum.nextElement();
-
- if (!names.contains(value))
- {
- names.add(value);
- }
- }
-
- return names.elements();
- }
-
- /**
- * @param theName the name of the parameter's value to return
- * @return the value of the parameter, looking for it first in the list of
- * parameters set using the <code>setInitParameter()</code> method
- * and then in those set in <code>web.xml</code>.
- */
- public String getInitParameter(String theName)
- {
- // Look first in the list of parameters set using the
- // setInitParameter() method.
- String value = (String) this.initParameters.get(theName);
-
- if (value == null)
- {
- value = this.originalConfig.getInitParameter(theName);
- }
-
- return value;
+ super(theOriginalConfig);
}
}
1.1 jakarta-cactus/framework/src/java/share/org/apache/cactus/server/AbstractServletConfigWrapper.java
Index: AbstractServletConfigWrapper.java
===================================================================
/*
* ====================================================================
*
* The Apache Software License, Version 1.1
*
* Copyright (c) 2001-2003 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution, if
* any, must include the following acknowlegement:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
*
* 4. The names "The Jakarta Project", "Cactus" and "Apache Software
* Foundation" must not be used to endorse or promote products
* derived from this software without prior written permission. For
* written permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache"
* nor may "Apache" appear in their names without prior written
* permission of the Apache Group.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*
*/
package org.apache.cactus.server;
import java.util.Enumeration;
import java.util.Hashtable;
import java.util.Vector;
import javax.servlet.ServletConfig;
import javax.servlet.ServletContext;
/**
* Abstract wrapper around <code>ServletConfig</code> which overrides the
* <code>getServletContext()</code> method to return our own wrapper around
* <code>ServletContext</code>. This class provides a common implementation
* of the wrapper for the different servlet API.
*
* @author <a href="mailto:vmassol@apache.org">Vincent Massol</a>
*
* @version $Id: AbstractServletConfigWrapper.java,v 1.1 2003/05/25 14:07:37 vmassol Exp $
*/
public abstract class AbstractServletConfigWrapper
implements ServletConfig
{
/**
* The original servlet config object
*/
protected ServletConfig originalConfig;
/**
* List of parameters set using the <code>setInitParameter()</code> method.
*/
protected Hashtable initParameters;
/**
* Simulated name of the servlet
*/
protected String servletName;
/**
* @param theOriginalConfig the original servlet config object
*/
public AbstractServletConfigWrapper(ServletConfig theOriginalConfig)
{
this.originalConfig = theOriginalConfig;
this.initParameters = new Hashtable();
}
/**
* Sets a parameter as if it were set in the <code>web.xml</code> file.
*
* @param theName the parameter's name
* @param theValue the parameter's value
*/
public void setInitParameter(String theName, String theValue)
{
this.initParameters.put(theName, theValue);
}
/**
* Sets the servlet name. That will be the value returned by the
* <code>getServletName()</code> method.
*
* @param theServletName the servlet's name
*/
public void setServletName(String theServletName)
{
this.servletName = theServletName;
}
/**
* @return the original unmodified config object
*/
public ServletConfig getOriginalConfig()
{
return this.originalConfig;
}
//--Overridden methods ----------------------------------------------------
/**
* @return our own wrapped servlet context object
*/
public ServletContext getServletContext()
{
return new ServletContextWrapper(
this.originalConfig.getServletContext());
}
/**
* @param theName the name of the parameter's value to return
* @return the value of the parameter, looking for it first in the list of
* parameters set using the <code>setInitParameter()</code> method
* and then in those set in <code>web.xml</code>.
*/
public String getInitParameter(String theName)
{
// Look first in the list of parameters set using the
// setInitParameter() method.
String value = (String) this.initParameters.get(theName);
if (value == null)
{
value = this.originalConfig.getInitParameter(theName);
}
return value;
}
/**
* @return the union of the parameters defined in the Redirector
* <code>web.xml</code> file and the one set using the
* <code>setInitParameter()</code> method.
*/
public Enumeration getInitParameterNames()
{
Vector names = new Vector();
// Add parameters that were added using setInitParameter()
Enumeration enum = this.initParameters.keys();
while (enum.hasMoreElements())
{
String value = (String) enum.nextElement();
names.add(value);
}
// Add parameters from web.xml
enum = this.originalConfig.getInitParameterNames();
while (enum.hasMoreElements())
{
String value = (String) enum.nextElement();
if (!names.contains(value))
{
names.add(value);
}
}
return names.elements();
}
/**
* @return the simulated servlet's name if defined or the redirector
* servlet's name
*/
public String getServletName()
{
if (this.servletName != null)
{
return this.servletName;
}
return this.originalConfig.getServletName();
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: cactus-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: cactus-dev-help@jakarta.apache.org