Coverage report

  %line %branch
org.apache.commons.configuration.web.ServletConfiguration
100% 
100% 

 1  
 /*
 2  
  * Copyright 2004 The Apache Software Foundation.
 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  
 
 17  
 package org.apache.commons.configuration.web;
 18  
 
 19  
 import java.util.Iterator;
 20  
 import java.util.List;
 21  
 import javax.servlet.Servlet;
 22  
 import javax.servlet.ServletConfig;
 23  
 
 24  
 import org.apache.commons.collections.iterators.EnumerationIterator;
 25  
 import org.apache.commons.configuration.AbstractConfiguration;
 26  
 import org.apache.commons.configuration.PropertyConverter;
 27  
 
 28  
 /**
 29  
  * A configuration wrapper around a {@link ServletConfig}. This configuration
 30  
  * is read only, adding or removing a property will throw an
 31  
  * UnsupportedOperationException.
 32  
  *
 33  
  * @author <a href="mailto:ebourg@apache.org">Emmanuel Bourg</a>
 34  
  * @version $Revision: 155408 $, $Date: 2005-02-26 13:56:39 +0100 (Sa, 26 Feb 2005) $
 35  
  * @since 1.1
 36  
  */
 37  
 public class ServletConfiguration extends AbstractConfiguration
 38  
 {
 39  
     protected ServletConfig config;
 40  
 
 41  
     /**
 42  
      * Create a ServletConfiguration using the initialization parameter of
 43  
      * the specified servlet.
 44  
      *
 45  
      * @param servlet the servlet
 46  
      */
 47  54
     public ServletConfiguration(Servlet servlet)
 48  54
     {
 49  98
         this(servlet.getServletConfig());
 50  98
     }
 51  
 
 52  
     /**
 53  
      * Create a ServletConfiguration using the servlet initialization parameters.
 54  
      *
 55  
      * @param config the servlet configuration
 56  72
      */
 57  72
     public ServletConfiguration(ServletConfig config)
 58  184
     {
 59  112
         this.config = config;
 60  112
     }
 61  
 
 62  45
     public Object getProperty(String key)
 63  
     {
 64  98
         Object value = config.getInitParameter(key);
 65  98
         List list = PropertyConverter.split((String) value, getDelimiter());
 66  
 
 67  98
         return list.size() > 1 ? list : value;
 68  
     }
 69  
 
 70  
     /**
 71  
      * <p><strong>This operation is not supported and will throw an
 72  
      * UnsupportedOperationException.</strong></p>
 73  9
      *
 74  
      * @throws UnsupportedOperationException
 75  
      */
 76  
     protected void addPropertyDirect(String key, Object obj)
 77  
     {
 78  32
         throw new UnsupportedOperationException("Read only configuration");
 79  
     }
 80  
 
 81  
     public boolean isEmpty()
 82  
     {
 83  46
         return !getKeys().hasNext();
 84  
     }
 85  
 
 86  
     public boolean containsKey(String key)
 87  
     {
 88  28
         return getProperty(key) != null;
 89  
     }
 90  
 
 91  
     /**
 92  
      * <p><strong>This operation is not supported and will throw an
 93  
      * UnsupportedOperationException.</strong></p>
 94  9
      *
 95  
      * @throws UnsupportedOperationException
 96  
      */
 97  
     public void clearProperty(String key)
 98  
     {
 99  50
         throw new UnsupportedOperationException("Read only configuration");
 100  
     }
 101  
 
 102  
     public Iterator getKeys()
 103  
     {
 104  42
         return new EnumerationIterator(config.getInitParameterNames());
 105  
     }
 106  
 
 107  
 }

This report is generated by jcoverage, Maven and Maven JCoverage Plugin.