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: 112   Methods: 6
NCLOC: 57   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
ComponentConstructorFactoryImpl.java 100% 92.9% 83.3% 90.9%
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.Collections;
 18   
 import java.util.HashMap;
 19   
 import java.util.Map;
 20   
 
 21   
 import org.apache.hivemind.ClassResolver;
 22   
 import org.apache.hivemind.service.ClassFactory;
 23   
 import org.apache.tapestry.enhance.EnhancedClassValidator;
 24   
 import org.apache.tapestry.enhance.EnhancementOperationImpl;
 25   
 import org.apache.tapestry.enhance.EnhancementWorker;
 26   
 import org.apache.tapestry.event.ResetEventListener;
 27   
 import org.apache.tapestry.services.ComponentConstructor;
 28   
 import org.apache.tapestry.services.ComponentConstructorFactory;
 29   
 import org.apache.tapestry.spec.IComponentSpecification;
 30   
 
 31   
 /**
 32   
  * Implementation of the {@link org.apache.tapestry.services.ComponentConstructorFactory}service
 33   
  * interface.
 34   
  * 
 35   
  * @author Howard M. Lewis Ship
 36   
  * @since 4.0
 37   
  */
 38   
 public class ComponentConstructorFactoryImpl implements ComponentConstructorFactory,
 39   
         ResetEventListener
 40   
 {
 41   
     private ClassFactory _classFactory;
 42   
 
 43   
     private ClassResolver _classResolver;
 44   
 
 45   
     private EnhancedClassValidator _validator;
 46   
 
 47   
     private EnhancementWorker _chain;
 48   
 
 49   
     /**
 50   
      * Map of {@link org.apache.tapestry.services.ComponentConstructor}keyed on
 51   
      * {@link org.apache.tapestry.spec.IComponentSpecification}.
 52   
      */
 53   
 
 54   
     private Map _cachedConstructors = Collections.synchronizedMap(new HashMap());
 55   
 
 56  0
     public void resetEventDidOccur()
 57   
     {
 58  0
         _cachedConstructors.clear();
 59   
     }
 60   
 
 61  1162
     public ComponentConstructor getComponentConstructor(IComponentSpecification specification,
 62   
             String className)
 63   
     {
 64  1162
         ComponentConstructor result = (ComponentConstructor) _cachedConstructors.get(specification);
 65   
 
 66  1162
         if (result == null)
 67   
         {
 68  462
             Class baseClass = _classResolver.findClass(className);
 69   
 
 70  462
             EnhancementOperationImpl eo = new EnhancementOperationImpl(_classResolver,
 71   
                     specification, baseClass, _classFactory);
 72   
 
 73   
             // Invoking on the chain is the same as invoking on every
 74   
             // object in the chain (because method performEnhancement() is type void).
 75   
 
 76  462
             _chain.performEnhancement(eo, specification);
 77   
 
 78  462
             result = eo.getConstructor();
 79   
 
 80   
             // TODO: This should be optional to work around that IBM JVM bug.
 81   
             // Also, to some degree, it should be passed into EnhancementOperationImpl,
 82   
             // as it generally only needs to be done if a enhanced class
 83   
             // is fabricated.
 84   
 
 85  462
             _validator.validate(baseClass, result.getComponentClass(), specification);
 86   
 
 87  462
             _cachedConstructors.put(specification, result);
 88   
         }
 89   
 
 90  1162
         return result;
 91   
     }
 92   
 
 93  45
     public void setClassFactory(ClassFactory classFactory)
 94   
     {
 95  45
         _classFactory = classFactory;
 96   
     }
 97   
 
 98  45
     public void setClassResolver(ClassResolver classResolver)
 99   
     {
 100  45
         _classResolver = classResolver;
 101   
     }
 102   
 
 103  45
     public void setValidator(EnhancedClassValidator validator)
 104   
     {
 105  45
         _validator = validator;
 106   
     }
 107   
 
 108  45
     public void setChain(EnhancementWorker chain)
 109   
     {
 110  45
         _chain = chain;
 111   
     }
 112   
 }