Clover coverage report - Code Coverage for tapestry release 4.0-beta-10
Coverage timestamp: Sat Oct 8 2005 19:08:05 EDT
file stats: LOC: 124   Methods: 7
NCLOC: 69   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
ComponentConstructorFactoryImpl.java 100% 94.1% 85.7% 92.3%
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.commons.logging.Log;
 22    import org.apache.hivemind.ClassResolver;
 23    import org.apache.hivemind.service.ClassFactory;
 24    import org.apache.hivemind.util.Defense;
 25    import org.apache.tapestry.enhance.EnhancedClassValidator;
 26    import org.apache.tapestry.enhance.EnhancementOperationImpl;
 27    import org.apache.tapestry.enhance.EnhancementWorker;
 28    import org.apache.tapestry.event.ResetEventListener;
 29    import org.apache.tapestry.services.ComponentConstructor;
 30    import org.apache.tapestry.services.ComponentConstructorFactory;
 31    import org.apache.tapestry.spec.IComponentSpecification;
 32   
 33    /**
 34    * Implementation of the {@link org.apache.tapestry.services.ComponentConstructorFactory} service
 35    * interface.
 36    *
 37    * @author Howard M. Lewis Ship
 38    * @since 4.0
 39    */
 40    public class ComponentConstructorFactoryImpl implements ComponentConstructorFactory,
 41    ResetEventListener
 42    {
 43    private Log _log;
 44   
 45    private ClassFactory _classFactory;
 46   
 47    private ClassResolver _classResolver;
 48   
 49    private EnhancedClassValidator _validator;
 50   
 51    private EnhancementWorker _chain;
 52   
 53    /**
 54    * Map of {@link org.apache.tapestry.services.ComponentConstructor}keyed on
 55    * {@link org.apache.tapestry.spec.IComponentSpecification}.
 56    */
 57   
 58    private Map _cachedConstructors = Collections.synchronizedMap(new HashMap());
 59   
 60  0 public void resetEventDidOccur()
 61    {
 62  0 _cachedConstructors.clear();
 63    }
 64   
 65  1058 public ComponentConstructor getComponentConstructor(IComponentSpecification specification,
 66    String className)
 67    {
 68  1058 Defense.notNull(specification, "specification");
 69   
 70  1058 synchronized (specification)
 71    {
 72  1058 ComponentConstructor result = (ComponentConstructor) _cachedConstructors
 73    .get(specification);
 74   
 75  1058 if (result == null)
 76    {
 77  405 Class baseClass = _classResolver.findClass(className);
 78   
 79  405 EnhancementOperationImpl eo = new EnhancementOperationImpl(_classResolver,
 80    specification, baseClass, _classFactory, _log);
 81   
 82    // Invoking on the chain is the same as invoking on every
 83    // object in the chain (because method performEnhancement() is type void).
 84   
 85  405 _chain.performEnhancement(eo, specification);
 86   
 87  405 result = eo.getConstructor();
 88   
 89    // TODO: This should be optional to work around that IBM JVM bug.
 90   
 91  405 _validator.validate(baseClass, result.getComponentClass(), specification);
 92   
 93  405 _cachedConstructors.put(specification, result);
 94    }
 95   
 96  1058 return result;
 97    }
 98    }
 99   
 100  40 public void setClassFactory(ClassFactory classFactory)
 101    {
 102  40 _classFactory = classFactory;
 103    }
 104   
 105  40 public void setClassResolver(ClassResolver classResolver)
 106    {
 107  40 _classResolver = classResolver;
 108    }
 109   
 110  40 public void setValidator(EnhancedClassValidator validator)
 111    {
 112  40 _validator = validator;
 113    }
 114   
 115  40 public void setChain(EnhancementWorker chain)
 116    {
 117  40 _chain = chain;
 118    }
 119   
 120  40 public void setLog(Log log)
 121    {
 122  40 _log = log;
 123    }
 124    }