Clover coverage report - Code Coverage for tapestry release 4.0-alpha-3
Coverage timestamp: Mon May 16 2005 09:05:49 EDT
file stats: LOC: 88   Methods: 4
NCLOC: 50   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
InfrastructureObjectProvider.java 100% 84.6% 100% 90.5%
coverage 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 java.util.HashMap;
 18   
 import java.util.Map;
 19   
 
 20   
 import org.apache.hivemind.ErrorLog;
 21   
 import org.apache.hivemind.Location;
 22   
 import org.apache.hivemind.internal.Module;
 23   
 import org.apache.hivemind.service.ObjectProvider;
 24   
 import org.apache.hivemind.util.PropertyUtils;
 25   
 import org.apache.tapestry.services.Infrastructure;
 26   
 
 27   
 /**
 28   
  * An ObjectProvider that streamlines access to the central
 29   
  * {@link org.apache.tapestry.services.Infrastructure}object. The locator for this provider is the
 30   
  * name of a property of the Infrastructure.
 31   
  * 
 32   
  * @author Howard Lewis Ship
 33   
  * @since 4.0
 34   
  */
 35   
 
 36   
 public class InfrastructureObjectProvider implements ObjectProvider
 37   
 {
 38   
     private ErrorLog _errorLog;
 39   
 
 40   
     private Infrastructure _infrastructure;
 41   
 
 42   
     private Map _cache = new HashMap();
 43   
 
 44  1867
     public synchronized Object provideObject(Module contributingModule, Class propertyType,
 45   
             String locator, Location location)
 46   
     {
 47  1867
         Object result = _cache.get(locator);
 48   
 
 49  1867
         if (result == null)
 50   
         {
 51  794
             result = readProperty(locator, location);
 52  794
             _cache.put(locator, result);
 53   
         }
 54   
 
 55  1867
         return result;
 56   
     }
 57   
 
 58  794
     Object readProperty(String locator, Location location)
 59   
     {
 60  794
         try
 61   
         {            
 62  794
             if (PropertyUtils.isReadable(_infrastructure, locator))
 63  774
                 return PropertyUtils.read(_infrastructure, locator);
 64   
 
 65  20
             return _infrastructure.getProperty(locator);
 66   
         }
 67   
         catch (Throwable ex)
 68   
         {
 69  0
             _errorLog.error(ImplMessages.unableToReadInfrastructureProperty(
 70   
                     locator,
 71   
                     _infrastructure,
 72   
                     ex), location, ex);
 73   
 
 74  0
             return null;
 75   
         }
 76   
     }
 77   
 
 78  45
     public void setErrorLog(ErrorLog errorLog)
 79   
     {
 80  45
         _errorLog = errorLog;
 81   
     }
 82   
 
 83  46
     public void setInfrastructure(Infrastructure infrastructure)
 84   
     {
 85  46
         _infrastructure = infrastructure;
 86   
     }
 87   
 
 88   
 }