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