Clover coverage report - Cactus 1.4.1 for J2EE API 13
Coverage timestamp: Sat Aug 31 2002 22:02:23 BST
file stats: LOC: 117   Methods: 7
NCLOC: 53   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
ServletConfigWrapper.java 90% 100% 100% 97.6%
 1   
 /*   Generated by AspectJ version 1.0.5 */
 2   
 package org.apache.cactus.server;
 3   
 import java.util.Enumeration;
 4   
 import java.util.Hashtable;
 5   
 import java.util.Vector;
 6   
 import javax.servlet.ServletConfig;
 7   
 import javax.servlet.ServletContext;
 8   
 
 9   
 /** 
 10   
  * Wrapper around <code>ServletConfig</code> which overrides the 
 11   
  * <code>getServletContext()</code> method to return our own wrapper around 
 12   
  * <code>ServletContext</code>. 
 13   
  * 
 14   
  * @author <a href="mailto:vmassol@apache.org">Vincent Massol</a> 
 15   
  * 
 16   
  * @version $Id: ServletConfigWrapper.html,v 1.1 2003/04/14 12:27:33 sinisa Exp $ 
 17   
  * @see ServletContext 
 18   
  */
 19   
 public class ServletConfigWrapper implements ServletConfig {
 20   
   /** 
 21   
        * The original servlet config object 
 22   
        */
 23   
   private ServletConfig originalConfig;
 24   
   /** 
 25   
        * List of parameters set using the <code>setInitParameter()</code> method. 
 26   
        */
 27   
   private Hashtable initParameters;
 28   
   /** 
 29   
        * Simulated name of the servlet 
 30   
        */
 31   
   private String servletName;
 32   
   /** 
 33   
        * @param theOriginalConfig the original servlet config object 
 34   
        */
 35  305
   public ServletConfigWrapper(ServletConfig theOriginalConfig) {
 36  305
     super();
 37  305
     this.originalConfig = theOriginalConfig;
 38  305
     this.initParameters = new Hashtable();
 39   
   } 
 40   
   /** 
 41   
        * Sets a parameter as if it were set in the <code>web.xml</code> file. 
 42   
        * 
 43   
        * @param theName the parameter's name 
 44   
        * @param theValue the parameter's value 
 45   
        */
 46  5
   public void setInitParameter(String theName, String theValue) {
 47  5
     this.initParameters.put(theName, theValue);
 48   
   } 
 49   
 
 50   
   /** 
 51   
        * Sets the servlet name. That will be the value returned by the 
 52   
        * <code>getServletName()</code> method. 
 53   
        * 
 54   
        * @param theServletName the servlet's name 
 55   
        */
 56  5
   public void setServletName(String theServletName) {
 57  5
     this.servletName = theServletName;
 58   
   } 
 59   
 
 60   
   /** 
 61   
        * @return the simulated servlet's name if defined or the redirector 
 62   
        *         servlet's name 
 63   
        */
 64  7
   public String getServletName() {
 65  7
     if (this.servletName != null) {
 66  5
       return this.servletName;
 67   
     } 
 68  2
     return this.originalConfig.getServletName();
 69   
   } 
 70   
 
 71   
   /** 
 72   
        * @return our own wrapped servlet context object 
 73   
        */
 74  30
   public ServletContext getServletContext() {
 75  30
     return new ServletContextWrapper(this.originalConfig.getServletContext());
 76   
   } 
 77   
 
 78   
   /** 
 79   
        * Return the union of the parameters defined in the Redirector 
 80   
        * <code>web.xml</code> file and the one set using the 
 81   
        * <code>setInitParameter()</code> method. The parameters with the same 
 82   
        * name (and same case) are only returned once. 
 83   
        * 
 84   
        * @return the init parameters 
 85   
        */
 86  5
   public Enumeration getInitParameterNames() {
 87  5
     Vector names = new Vector();
 88  5
     Enumeration enum = this.initParameters.keys();
 89  5
     while (enum.hasMoreElements()){
 90  5
       String value = (String)enum.nextElement();
 91  5
       names.add(value);
 92   
     } 
 93  5
     enum = this.originalConfig.getInitParameterNames();
 94  5
     while (enum.hasMoreElements()){
 95  5
       String value = (String)enum.nextElement();
 96  5
       if (!names.contains(value)) {
 97  5
         names.add(value);
 98   
       } 
 99   
     } 
 100  5
     return names.elements();
 101   
   } 
 102   
 
 103   
   /** 
 104   
        * @param theName the name of the parameter's value to return 
 105   
        * @return the value of the parameter, looking for it first in the list of 
 106   
        *         parameters set using the <code>setInitParameter()</code> method 
 107   
        *         and then in those set in <code>web.xml</code>. 
 108   
        */
 109  25
   public String getInitParameter(String theName) {
 110  25
     String value = (String)this.initParameters.get(theName);
 111  25
     if (value == null) {
 112  20
       value = this.originalConfig.getInitParameter(theName);
 113   
     } 
 114  25
     return value;
 115   
   } 
 116   
 
 117   
 }