Clover coverage report - Cactus 1.5 for J2EE API 1.3
Coverage timestamp: Wed Feb 18 2004 09:09:13 EST
file stats: LOC: 216   Methods: 8
NCLOC: 72   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
AbstractServletConfigWrapper.java 0% 0% 0% 0%
coverage
 1   
 /*
 2   
  * ====================================================================
 3   
  *
 4   
  * The Apache Software License, Version 1.1
 5   
  *
 6   
  * Copyright (c) 2001-2003 The Apache Software Foundation.  All rights
 7   
  * reserved.
 8   
  *
 9   
  * Redistribution and use in source and binary forms, with or without
 10   
  * modification, are permitted provided that the following conditions
 11   
  * are met:
 12   
  *
 13   
  * 1. Redistributions of source code must retain the above copyright
 14   
  *    notice, this list of conditions and the following disclaimer.
 15   
  *
 16   
  * 2. Redistributions in binary form must reproduce the above copyright
 17   
  *    notice, this list of conditions and the following disclaimer in
 18   
  *    the documentation and/or other materials provided with the
 19   
  *    distribution.
 20   
  *
 21   
  * 3. The end-user documentation included with the redistribution, if
 22   
  *    any, must include the following acknowlegement:
 23   
  *       "This product includes software developed by the
 24   
  *        Apache Software Foundation (http://www.apache.org/)."
 25   
  *    Alternately, this acknowlegement may appear in the software itself,
 26   
  *    if and wherever such third-party acknowlegements normally appear.
 27   
  *
 28   
  * 4. The names "The Jakarta Project", "Cactus" and "Apache Software
 29   
  *    Foundation" must not be used to endorse or promote products
 30   
  *    derived from this software without prior written permission. For
 31   
  *    written permission, please contact apache@apache.org.
 32   
  *
 33   
  * 5. Products derived from this software may not be called "Apache"
 34   
  *    nor may "Apache" appear in their names without prior written
 35   
  *    permission of the Apache Group.
 36   
  *
 37   
  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
 38   
  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
 39   
  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 40   
  * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
 41   
  * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 42   
  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
 43   
  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
 44   
  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
 45   
  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
 46   
  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
 47   
  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 48   
  * SUCH DAMAGE.
 49   
  * ====================================================================
 50   
  *
 51   
  * This software consists of voluntary contributions made by many
 52   
  * individuals on behalf of the Apache Software Foundation.  For more
 53   
  * information on the Apache Software Foundation, please see
 54   
  * <http://www.apache.org/>.
 55   
  *
 56   
  */
 57   
 package org.apache.cactus.server;
 58   
 
 59   
 import java.util.Enumeration;
 60   
 import java.util.Hashtable;
 61   
 import java.util.Vector;
 62   
 
 63   
 import javax.servlet.ServletConfig;
 64   
 import javax.servlet.ServletContext;
 65   
 
 66   
 /**
 67   
  * Abstract wrapper around <code>ServletConfig</code> which overrides the
 68   
  * <code>getServletContext()</code> method to return our own wrapper around
 69   
  * <code>ServletContext</code>. This class provides a common implementation 
 70   
  * of the wrapper for the different servlet API.
 71   
  *
 72   
  * @author <a href="mailto:vmassol@apache.org">Vincent Massol</a>
 73   
  *
 74   
  * @version $Id: AbstractServletConfigWrapper.java,v 1.4 2003/05/26 11:45:22 cmlenz Exp $
 75   
  */
 76   
 public abstract class AbstractServletConfigWrapper
 77   
     implements ServletConfig
 78   
 {
 79   
     /**
 80   
      * The original servlet config object
 81   
      */
 82   
     protected ServletConfig originalConfig;
 83   
 
 84   
     /**
 85   
      * List of parameters set using the <code>setInitParameter()</code> method.
 86   
      */
 87   
     protected Hashtable initParameters;
 88   
 
 89   
     /**
 90   
      * Simulated name of the servlet
 91   
      */
 92   
     protected String servletName;
 93   
 
 94   
     /**
 95   
      * @param theOriginalConfig the original servlet config object
 96   
      */
 97  0
     public AbstractServletConfigWrapper(ServletConfig theOriginalConfig)
 98   
     {
 99  0
         this.originalConfig = theOriginalConfig;
 100  0
         this.initParameters = new Hashtable();
 101   
     }
 102   
 
 103   
     /**
 104   
      * Sets a parameter as if it were set in the <code>web.xml</code> file.
 105   
      *
 106   
      * @param theName the parameter's name
 107   
      * @param theValue the parameter's value
 108   
      */
 109  0
     public void setInitParameter(String theName, String theValue)
 110   
     {
 111  0
         this.initParameters.put(theName, theValue);
 112   
     }
 113   
 
 114   
     /**
 115   
      * Sets the servlet name. That will be the value returned by the
 116   
      * <code>getServletName()</code> method.
 117   
      *
 118   
      * @param theServletName the servlet's name
 119   
      */
 120  0
     public void setServletName(String theServletName)
 121   
     {
 122  0
         this.servletName = theServletName;
 123   
     }
 124   
 
 125   
     /**
 126   
      * @return the original unmodified config object
 127   
      * @since 1.5
 128   
      */
 129  0
     public ServletConfig getOriginalConfig()
 130   
     {
 131  0
         return this.originalConfig;
 132   
     }
 133   
 
 134   
     //--Overridden methods ----------------------------------------------------
 135   
 
 136   
     /**
 137   
      * @return our own wrapped servlet context object
 138   
      */
 139  0
     public ServletContext getServletContext()
 140   
     {
 141  0
         return new ServletContextWrapper(
 142   
             this.originalConfig.getServletContext());
 143   
     }
 144   
 
 145   
     /**
 146   
      * @param theName the name of the parameter's value to return
 147   
      * @return the value of the parameter, looking for it first in the list of
 148   
      *         parameters set using the <code>setInitParameter()</code> method
 149   
      *         and then in those set in <code>web.xml</code>.
 150   
      */
 151  0
     public String getInitParameter(String theName)
 152   
     {
 153   
         // Look first in the list of parameters set using the
 154   
         // setInitParameter() method.
 155  0
         String value = (String) this.initParameters.get(theName);
 156   
 
 157  0
         if (value == null)
 158   
         {
 159  0
             value = this.originalConfig.getInitParameter(theName);
 160   
         }
 161   
 
 162  0
         return value;
 163   
     }
 164   
 
 165   
     /**
 166   
      * @return the union of the parameters defined in the Redirector
 167   
      *         <code>web.xml</code> file and the one set using the
 168   
      *         <code>setInitParameter()</code> method.
 169   
      */
 170  0
     public Enumeration getInitParameterNames()
 171   
     {
 172  0
         Vector names = new Vector();
 173   
 
 174   
         // Add parameters that were added using setInitParameter()
 175  0
         Enumeration enum = this.initParameters.keys();
 176   
 
 177  0
         while (enum.hasMoreElements())
 178   
         {
 179  0
             String value = (String) enum.nextElement();
 180   
 
 181  0
             names.add(value);
 182   
         }
 183   
 
 184   
         // Add parameters from web.xml
 185  0
         enum = this.originalConfig.getInitParameterNames();
 186   
 
 187  0
         while (enum.hasMoreElements())
 188   
         {
 189  0
             String value = (String) enum.nextElement();
 190   
 
 191   
             // Do not add parameters that have been overriden by calling
 192   
             // the setInitParameter() method.
 193  0
             if (!names.contains(value))
 194   
             {
 195  0
                 names.add(value);
 196   
             }
 197   
         }
 198   
 
 199  0
         return names.elements();
 200   
     }
 201   
 
 202   
     /**
 203   
      * @return the simulated servlet's name if defined or the redirector
 204   
      *         servlet's name
 205   
      */
 206  0
     public String getServletName()
 207   
     {
 208  0
         if (this.servletName != null)
 209   
         {
 210  0
             return this.servletName;
 211   
         }
 212   
 
 213  0
         return this.originalConfig.getServletName();
 214   
     }
 215   
 }
 216