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: 85   Methods: 4
NCLOC: 38   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
TypeConverterWrapper.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.coerce;
 16   
 
 17   
 import java.util.Iterator;
 18   
 import java.util.List;
 19   
 
 20   
 import org.apache.hivemind.lib.util.StrategyRegistry;
 21   
 import org.apache.hivemind.lib.util.StrategyRegistryImpl;
 22   
 
 23   
 /**
 24   
  * A service implementation that works around an
 25   
  * {@link org.apache.hivemind.lib.util.StrategyRegistry}. The registry is contructed from a
 26   
  * configuration that follows the <code>tapestry.coerce.Converters</code> schema (a List of
 27   
  * {@link org.apache.tapestry.coerce.TypeConverterContribution}plus an additional converter for
 28   
  * nulls.
 29   
  * 
 30   
  * @author Howard M. Lewis Ship
 31   
  * @since 4.0
 32   
  */
 33   
 public class TypeConverterWrapper implements TypeConverter
 34   
 {
 35   
     private StrategyRegistry _registry = new StrategyRegistryImpl();
 36   
 
 37   
     private List _contributions;
 38   
 
 39   
     private TypeConverter _nullConverter;
 40   
 
 41  45
     public void initializeService()
 42   
     {
 43  45
         Iterator i = _contributions.iterator();
 44   
 
 45  45
         while (i.hasNext())
 46   
         {
 47  141
             TypeConverterContribution c = (TypeConverterContribution) i.next();
 48   
 
 49  141
             _registry.register(c.getSubjectClass(), c.getConverter());
 50   
         }
 51   
     }
 52   
 
 53  242
     public Object convertValue(Object value)
 54   
     {
 55  242
         if (value == null)
 56   
         {
 57  139
             if (_nullConverter == null)
 58  1
                 return null;
 59   
 
 60  138
             return _nullConverter.convertValue(null);
 61   
         }
 62   
 
 63  103
         TypeConverter delegate = (TypeConverter) _registry.getStrategy(value.getClass());
 64   
 
 65  103
         return delegate.convertValue(value);
 66   
     }
 67   
 
 68   
     /**
 69   
      * Sets the List of {@link org.apache.tapestry.coerce.TypeConverterContribution}s.
 70   
      */
 71   
 
 72  45
     public void setContributions(List contributions)
 73   
     {
 74  45
         _contributions = contributions;
 75   
     }
 76   
 
 77   
     /**
 78   
      * Sets the converter used to convert null.
 79   
      */
 80   
 
 81  45
     public void setNullConverter(TypeConverter nullConverter)
 82   
     {
 83  45
         _nullConverter = nullConverter;
 84   
     }
 85   
 }