Clover coverage report - Code Coverage for tapestry release 4.0-beta-6
Coverage timestamp: Wed Sep 7 2005 18:41:34 EDT
file stats: LOC: 93   Methods: 3
NCLOC: 52   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
InjectComponentWorker.java 100% 100% 100% 100%
coverage
 1    // Copyright 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.enhance;
 16   
 17    import java.util.Iterator;
 18   
 19    import org.apache.hivemind.ErrorLog;
 20    import org.apache.hivemind.Location;
 21    import org.apache.hivemind.service.ClassFabUtils;
 22    import org.apache.hivemind.util.Defense;
 23    import org.apache.tapestry.IComponent;
 24    import org.apache.tapestry.spec.IComponentSpecification;
 25    import org.apache.tapestry.spec.IContainedComponent;
 26   
 27    /**
 28    * Injects components for which the property attribute of the <component> element was
 29    * specified. This makes it easier to reference a particular component from Java code.
 30    *
 31    * @author Howard M. Lewis Ship
 32    * @since 4.0
 33    */
 34    public class InjectComponentWorker implements EnhancementWorker
 35    {
 36    private ErrorLog _errorLog;
 37   
 38  421 public void performEnhancement(EnhancementOperation op, IComponentSpecification spec)
 39    {
 40  421 Iterator i = spec.getComponentIds().iterator();
 41   
 42  421 while (i.hasNext())
 43    {
 44  259 String id = (String) i.next();
 45   
 46  259 IContainedComponent cc = spec.getComponent(id);
 47   
 48  259 String propertyName = cc.getPropertyName();
 49   
 50  259 if (propertyName != null)
 51    {
 52  2 try
 53    {
 54  2 injectComponent(op, id, propertyName, cc.getLocation());
 55    }
 56    catch (Exception ex)
 57    {
 58  1 _errorLog.error(EnhanceMessages.errorAddingProperty(propertyName, op
 59    .getBaseClass(), ex), cc.getLocation(), ex);
 60    }
 61    }
 62    }
 63    }
 64   
 65  2 public void injectComponent(EnhancementOperation op, String componentId, String propertyName, Location location)
 66    {
 67  2 Defense.notNull(op, "op");
 68  2 Defense.notNull(componentId, "componentId");
 69  2 Defense.notNull(propertyName, "propertyName");
 70   
 71  2 Class propertyType = EnhanceUtils.extractPropertyType(op, propertyName, null);
 72   
 73  2 op.claimReadonlyProperty(propertyName);
 74   
 75  1 String fieldName = "_$" + propertyName;
 76   
 77  1 op.addField(fieldName, propertyType);
 78   
 79  1 EnhanceUtils.createSimpleAccessor(op, fieldName, propertyName, propertyType, location);
 80   
 81    // I.e. _$fred = (IComponent) getComponent("fred");
 82   
 83  1 String code = fieldName + " = (" + ClassFabUtils.getJavaClassName(propertyType)
 84    + ") getComponent(\"" + componentId + "\");";
 85   
 86  1 op.extendMethodImplementation(IComponent.class, EnhanceUtils.FINISH_LOAD_SIGNATURE, code);
 87    }
 88   
 89  42 public void setErrorLog(ErrorLog errorLog)
 90    {
 91  42 _errorLog = errorLog;
 92    }
 93    }