Clover coverage report - Code Coverage for tapestry release 4.0.2
Coverage timestamp: Thu Apr 13 2006 10:52:06 EDT
file stats: LOC: 113   Methods: 12
NCLOC: 72   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
ServletWebContext.java 100% 83.3% 75% 81.2%
coverage coverage
 1    // Copyright 2005 The Apache Software Foundation
 2    //
 3    // Licensed under the Apache License, Version 2.0 (the "License");
 4    // you may not use this file except in compliance with the License.
 5    // You may obtain a copy of the License at
 6    //
 7    // http://www.apache.org/licenses/LICENSE-2.0
 8    //
 9    // Unless required by applicable law or agreed to in writing, software
 10    // distributed under the License is distributed on an "AS IS" BASIS,
 11    // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 12    // See the License for the specific language governing permissions and
 13    // limitations under the License.
 14   
 15    package org.apache.tapestry.web;
 16   
 17    import java.io.InputStream;
 18    import java.net.MalformedURLException;
 19    import java.net.URL;
 20    import java.util.List;
 21    import java.util.Set;
 22   
 23    import javax.servlet.ServletContext;
 24   
 25    import org.apache.commons.logging.Log;
 26    import org.apache.commons.logging.LogFactory;
 27    import org.apache.hivemind.util.Defense;
 28    import org.apache.tapestry.describe.DescriptionReceiver;
 29   
 30    /**
 31    * Adapts {@link javax.servlet.ServletContext} as {@link org.apache.tapestry.web.WebContext}.
 32    *
 33    * @author Howard M. Lewis Ship
 34    * @since 4.0
 35    */
 36    public class ServletWebContext implements WebContext
 37    {
 38    private static final Log LOG = LogFactory.getLog(ServletWebContext.class);
 39   
 40    private final ServletContext _servletContext;
 41   
 42  48 public ServletWebContext(ServletContext context)
 43    {
 44  48 Defense.notNull(context, "context");
 45   
 46  48 _servletContext = context;
 47    }
 48   
 49  17 public void describeTo(DescriptionReceiver receiver)
 50    {
 51  17 receiver.describeAlternate(_servletContext);
 52    }
 53   
 54  1 public List getAttributeNames()
 55    {
 56  1 return WebUtils.toSortedList(_servletContext.getAttributeNames());
 57    }
 58   
 59  1 public Object getAttribute(String name)
 60    {
 61  1 return _servletContext.getAttribute(name);
 62    }
 63   
 64  2 public void setAttribute(String name, Object attribute)
 65    {
 66  2 if (attribute == null)
 67  1 _servletContext.removeAttribute(name);
 68    else
 69  1 _servletContext.setAttribute(name, attribute);
 70   
 71    }
 72   
 73  668 public URL getResource(String path)
 74    {
 75  668 try
 76    {
 77  668 return _servletContext.getResource(path);
 78    }
 79    catch (MalformedURLException ex)
 80    {
 81  1 LOG.error(WebMessages.errorGettingResource(path, ex), ex);
 82   
 83  1 return null;
 84    }
 85    }
 86   
 87  2094 public String getInitParameterValue(String name)
 88    {
 89  2094 return _servletContext.getInitParameter(name);
 90    }
 91   
 92  1 public List getInitParameterNames()
 93    {
 94  1 return WebUtils.toSortedList(_servletContext.getInitParameterNames());
 95    }
 96   
 97  1 public String getMimeType(String resourcePath)
 98    {
 99  1 return _servletContext.getMimeType(resourcePath);
 100    }
 101   
 102  0 public String getRealPath(String path) {
 103  0 return _servletContext.getRealPath(path);
 104    }
 105   
 106  0 public InputStream getResourceAsStream(String path) {
 107  0 return _servletContext.getResourceAsStream(path);
 108    }
 109   
 110  0 public Set getResourcePaths(String path) {
 111  0 return _servletContext.getResourcePaths(path);
 112    }
 113    }