Clover coverage report - Code Coverage for tapestry release 4.0.2
Coverage timestamp: Thu Apr 13 2006 10:52:06 EDT
file stats: LOC: 141   Methods: 9
NCLOC: 82   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
ComponentConstructorFactoryImpl.java 100% 95.2% 88.9% 93.8%
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.ReportStatusEvent;
 29    import org.apache.tapestry.event.ReportStatusListener;
 30    import org.apache.tapestry.event.ResetEventListener;
 31    import org.apache.tapestry.services.ComponentConstructor;
 32    import org.apache.tapestry.services.ComponentConstructorFactory;
 33    import org.apache.tapestry.spec.IComponentSpecification;
 34   
 35    /**
 36    * Implementation of the {@link org.apache.tapestry.services.ComponentConstructorFactory} service
 37    * interface.
 38    *
 39    * @author Howard M. Lewis Ship
 40    * @since 4.0
 41    */
 42    public class ComponentConstructorFactoryImpl implements ComponentConstructorFactory,
 43    ResetEventListener, ReportStatusListener
 44    {
 45    private String _serviceId;
 46   
 47    private Log _log;
 48   
 49    private ClassFactory _classFactory;
 50   
 51    private ClassResolver _classResolver;
 52   
 53    private EnhancedClassValidator _validator;
 54   
 55    private EnhancementWorker _chain;
 56   
 57    /**
 58    * Map of {@link org.apache.tapestry.services.ComponentConstructor} keyed on
 59    * {@link org.apache.tapestry.spec.IComponentSpecification}.
 60    */
 61   
 62    private Map _cachedConstructors = Collections.synchronizedMap(new HashMap());
 63   
 64  0 public void resetEventDidOccur()
 65    {
 66  0 _cachedConstructors.clear();
 67    }
 68   
 69  17 public synchronized void reportStatus(ReportStatusEvent event)
 70    {
 71  17 event.title(_serviceId);
 72   
 73  17 event.property("enhanced class count", _cachedConstructors.size());
 74  17 event.collection("enhanced classes", _cachedConstructors.keySet());
 75    }
 76   
 77  1006 public ComponentConstructor getComponentConstructor(IComponentSpecification specification,
 78    String className)
 79    {
 80  1006 Defense.notNull(specification, "specification");
 81   
 82  1006 synchronized (specification)
 83    {
 84  1006 ComponentConstructor result = (ComponentConstructor) _cachedConstructors
 85    .get(specification);
 86   
 87  1006 if (result == null)
 88    {
 89  389 Class baseClass = _classResolver.findClass(className);
 90   
 91  389 EnhancementOperationImpl eo = new EnhancementOperationImpl(_classResolver,
 92    specification, baseClass, _classFactory, _log);
 93   
 94    // Invoking on the chain is the same as invoking on every
 95    // object in the chain (because method performEnhancement() is type void).
 96   
 97  389 _chain.performEnhancement(eo, specification);
 98   
 99  389 result = eo.getConstructor();
 100   
 101    // TODO: This should be optional to work around that IBM JVM bug.
 102   
 103  389 _validator.validate(baseClass, result.getComponentClass(), specification);
 104   
 105  389 _cachedConstructors.put(specification, result);
 106    }
 107   
 108  1006 return result;
 109    }
 110    }
 111   
 112  39 public void setClassFactory(ClassFactory classFactory)
 113    {
 114  39 _classFactory = classFactory;
 115    }
 116   
 117  39 public void setClassResolver(ClassResolver classResolver)
 118    {
 119  39 _classResolver = classResolver;
 120    }
 121   
 122  39 public void setValidator(EnhancedClassValidator validator)
 123    {
 124  39 _validator = validator;
 125    }
 126   
 127  39 public void setChain(EnhancementWorker chain)
 128    {
 129  39 _chain = chain;
 130    }
 131   
 132  39 public void setLog(Log log)
 133    {
 134  39 _log = log;
 135    }
 136   
 137  39 public void setServiceId(String serviceId)
 138    {
 139  39 _serviceId = serviceId;
 140    }
 141    }