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