Clover coverage report - Code Coverage for tapestry release 3.1-alpha-1
Coverage timestamp: Mon Feb 21 2005 09:16:14 EST
file stats: LOC: 142   Methods: 8
NCLOC: 85   Classes: 1
30 day Evaluation Version distributed via the Maven Jar Repository. Clover is not free. You have 30 days to evaluate it. Please visit http://www.thecortex.net/clover to obtain a licensed version of Clover
 
 Source file Conditionals Statements Methods TOTAL
ApplicationSpecificationInitializer.java 100% 100% 100% 100%
coverage
 1   
 // Copyright 2004, 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.services.impl;
 16   
 
 17   
 import javax.servlet.ServletContext;
 18   
 import javax.servlet.http.HttpServlet;
 19   
 
 20   
 import org.apache.commons.logging.Log;
 21   
 import org.apache.hivemind.Resource;
 22   
 import org.apache.hivemind.util.ContextResource;
 23   
 import org.apache.tapestry.parse.ISpecificationParser;
 24   
 import org.apache.tapestry.services.ApplicationGlobals;
 25   
 import org.apache.tapestry.services.ApplicationInitializer;
 26   
 import org.apache.tapestry.services.ClasspathResourceFactory;
 27   
 import org.apache.tapestry.spec.ApplicationSpecification;
 28   
 import org.apache.tapestry.spec.IApplicationSpecification;
 29   
 
 30   
 /**
 31   
  * Locates the application specification and informs the
 32   
  * {@link org.apache.tapestry.services.ServletInfo}service about it.
 33   
  * 
 34   
  * @author Howard Lewis Ship
 35   
  * @since 3.1
 36   
  */
 37   
 public class ApplicationSpecificationInitializer implements ApplicationInitializer
 38   
 {
 39   
     private Log _log;
 40   
 
 41   
     private ClasspathResourceFactory _classpathResourceFactory;
 42   
 
 43   
     private ApplicationGlobals _globals;
 44   
 
 45   
     private ISpecificationParser _parser;
 46   
 
 47   
     public static final String APP_SPEC_PATH_PARAM = "org.apache.tapestry.application-specification";
 48   
 
 49  57
     public void initialize(HttpServlet servlet)
 50   
     {
 51  57
         IApplicationSpecification spec = null;
 52   
 
 53  57
         Resource specResource = findApplicationSpecification(servlet);
 54   
 
 55  57
         if (specResource == null)
 56   
         {
 57  18
             _log.debug(ImplMessages.noApplicationSpecification(servlet));
 58   
 
 59  18
             spec = constructStandinSpecification(servlet);
 60   
         }
 61   
         else
 62  39
             spec = _parser.parseApplicationSpecification(specResource);
 63   
 
 64  57
         _globals.store(servlet, spec);
 65   
     }
 66   
 
 67  57
     private Resource findApplicationSpecification(HttpServlet servlet)
 68   
     {
 69  57
         String path = servlet.getInitParameter(APP_SPEC_PATH_PARAM);
 70   
 
 71  57
         if (path != null)
 72  31
             return _classpathResourceFactory.newResource(path);
 73   
 
 74  26
         ServletContext context = servlet.getServletContext();
 75  26
         String servletName = servlet.getServletName();
 76  26
         String expectedName = servletName + ".application";
 77   
 
 78  26
         Resource webInfLocation = new ContextResource(context, "/WEB-INF/");
 79  26
         Resource webInfAppLocation = webInfLocation.getRelativeResource(servletName + "/");
 80   
 
 81  26
         Resource result = check(webInfAppLocation, expectedName);
 82  26
         if (result != null)
 83  2
             return result;
 84   
 
 85  24
         return check(webInfLocation, expectedName);
 86   
     }
 87   
 
 88  50
     private Resource check(Resource resource, String name)
 89   
     {
 90  50
         Resource result = resource.getRelativeResource(name);
 91   
 
 92  50
         if (_log.isDebugEnabled())
 93  1
             _log.debug("Checking for existence of " + result);
 94   
 
 95  50
         if (result.getResourceURL() != null)
 96   
         {
 97  8
             _log.debug("Found " + result);
 98  8
             return result;
 99   
         }
 100   
 
 101  42
         return null;
 102   
     }
 103   
 
 104  18
     private IApplicationSpecification constructStandinSpecification(HttpServlet servlet)
 105   
     {
 106  18
         String servletName = servlet.getServletName();
 107   
 
 108  18
         ApplicationSpecification result = new ApplicationSpecification();
 109   
 
 110   
         // Pretend the file exists in the most common expected location.
 111   
         
 112  18
         Resource virtualLocation = new ContextResource(servlet.getServletContext(), "/WEB-INF/"
 113   
                 + servletName + ".application");
 114   
 
 115  18
         result.setSpecificationLocation(virtualLocation);
 116   
 
 117  18
         result.setName(servletName);
 118   
 
 119  18
         return result;
 120   
     }
 121   
 
 122  57
     public void setClasspathResourceFactory(ClasspathResourceFactory factory)
 123   
     {
 124  57
         _classpathResourceFactory = factory;
 125   
     }
 126   
 
 127  57
     public void setLog(Log log)
 128   
     {
 129  57
         _log = log;
 130   
     }
 131   
 
 132  57
     public void setGlobals(ApplicationGlobals globals)
 133   
     {
 134  57
         _globals = globals;
 135   
     }
 136   
 
 137  56
     public void setParser(ISpecificationParser parser)
 138   
     {
 139  56
         _parser = parser;
 140   
     }
 141   
 
 142   
 }