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: 97   Methods: 3
NCLOC: 57   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
InjectAssetWorker.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.ApplicationRuntimeException;
 20    import org.apache.hivemind.ErrorLog;
 21    import org.apache.hivemind.Location;
 22    import org.apache.hivemind.util.Defense;
 23    import org.apache.tapestry.IAsset;
 24    import org.apache.tapestry.IComponent;
 25    import org.apache.tapestry.spec.IAssetSpecification;
 26    import org.apache.tapestry.spec.IComponentSpecification;
 27   
 28    /**
 29    * Injects assets as component properties.
 30    *
 31    * @author Howard M. Lewis Ship
 32    * @since 4.0
 33    */
 34    public class InjectAssetWorker implements EnhancementWorker
 35    {
 36    private ErrorLog _errorLog;
 37   
 38  421 public void performEnhancement(EnhancementOperation op, IComponentSpecification spec)
 39    {
 40  421 Iterator i = spec.getAssetNames().iterator();
 41  421 while (i.hasNext())
 42    {
 43  39 String name = (String) i.next();
 44   
 45  39 IAssetSpecification as = spec.getAsset(name);
 46   
 47  39 String propertyName = as.getPropertyName();
 48   
 49  39 if (propertyName != null)
 50    {
 51  2 try
 52    {
 53  2 injectAsset(op, name, propertyName, as.getLocation());
 54    }
 55    catch (Exception ex)
 56    {
 57  1 _errorLog.error(EnhanceMessages.errorAddingProperty(propertyName, op
 58    .getBaseClass(), ex), as.getLocation(), ex);
 59    }
 60    }
 61    }
 62    }
 63   
 64  3 public void injectAsset(EnhancementOperation op, String assetName, String propertyName, Location location)
 65    {
 66  3 Defense.notNull(op, "op");
 67  3 Defense.notNull(assetName, "assetName");
 68  3 Defense.notNull(propertyName, "propertyName");
 69   
 70  3 Class propertyType = EnhanceUtils.extractPropertyType(op, propertyName, null);
 71   
 72  3 op.claimReadonlyProperty(propertyName);
 73   
 74  2 if (!propertyType.isAssignableFrom(IAsset.class))
 75  1 throw new ApplicationRuntimeException(EnhanceMessages.incompatiblePropertyType(
 76    propertyName,
 77    propertyType,
 78    IAsset.class));
 79   
 80  1 String fieldName = "_$" + propertyName;
 81   
 82  1 op.addField(fieldName, propertyType);
 83   
 84  1 EnhanceUtils.createSimpleAccessor(op, fieldName, propertyName, propertyType, location);
 85   
 86    // i.e. _$fred = getAsset("barney");
 87   
 88  1 String code = fieldName + " = getAsset(\"" + assetName + "\");";
 89   
 90  1 op.extendMethodImplementation(IComponent.class, EnhanceUtils.FINISH_LOAD_SIGNATURE, code);
 91    }
 92   
 93  42 public void setErrorLog(ErrorLog errorLog)
 94    {
 95  42 _errorLog = errorLog;
 96    }
 97    }