Clover coverage report - Code Coverage for tapestry release 4.0.2
Coverage timestamp: Thu Apr 13 2006 10:52:06 EDT
file stats: LOC: 95   Methods: 3
NCLOC: 58   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.lang.reflect.Modifier;
 18    import java.util.Iterator;
 19   
 20    import org.apache.hivemind.ApplicationRuntimeException;
 21    import org.apache.hivemind.ErrorLog;
 22    import org.apache.hivemind.Location;
 23    import org.apache.hivemind.service.MethodSignature;
 24    import org.apache.hivemind.util.Defense;
 25    import org.apache.tapestry.IAsset;
 26    import org.apache.tapestry.spec.IAssetSpecification;
 27    import org.apache.tapestry.spec.IComponentSpecification;
 28   
 29    /**
 30    * Injects assets as component properties.
 31    *
 32    * @author Howard M. Lewis Ship
 33    * @since 4.0
 34    */
 35    public class InjectAssetWorker implements EnhancementWorker
 36    {
 37    private ErrorLog _errorLog;
 38   
 39  392 public void performEnhancement(EnhancementOperation op, IComponentSpecification spec)
 40    {
 41  392 Iterator i = spec.getAssetNames().iterator();
 42  392 while (i.hasNext())
 43    {
 44  37 String name = (String) i.next();
 45   
 46  37 IAssetSpecification as = spec.getAsset(name);
 47   
 48  37 String propertyName = as.getPropertyName();
 49   
 50  37 if (propertyName != null)
 51    {
 52  2 try
 53    {
 54  2 injectAsset(op, name, propertyName, as.getLocation());
 55    }
 56    catch (Exception ex)
 57    {
 58  1 _errorLog.error(EnhanceMessages.errorAddingProperty(propertyName, op
 59    .getBaseClass(), ex), as.getLocation(), ex);
 60    }
 61    }
 62    }
 63    }
 64   
 65  3 public void injectAsset(EnhancementOperation op, String assetName, String propertyName,
 66    Location location)
 67    {
 68  3 Defense.notNull(op, "op");
 69  3 Defense.notNull(assetName, "assetName");
 70  3 Defense.notNull(propertyName, "propertyName");
 71   
 72  3 Class propertyType = EnhanceUtils.extractPropertyType(op, propertyName, null);
 73   
 74  3 op.claimReadonlyProperty(propertyName);
 75   
 76  2 if (!propertyType.isAssignableFrom(IAsset.class))
 77  1 throw new ApplicationRuntimeException(EnhanceMessages.incompatiblePropertyType(
 78    propertyName,
 79    propertyType,
 80    IAsset.class));
 81   
 82  1 String methodName = op.getAccessorMethodName(propertyName);
 83   
 84  1 MethodSignature sig = new MethodSignature(propertyType, methodName, null, null);
 85   
 86  1 String code = "return getAsset(\"" + assetName + "\");";
 87   
 88  1 op.addMethod(Modifier.PUBLIC, sig, code, location);
 89    }
 90   
 91  40 public void setErrorLog(ErrorLog errorLog)
 92    {
 93  40 _errorLog = errorLog;
 94    }
 95    }