Clover coverage report - Code Coverage for tapestry release 4.0-alpha-3
Coverage timestamp: Mon May 16 2005 09:05:49 EDT
file stats: LOC: 85   Methods: 3
NCLOC: 45   Classes: 1
30 day Evaluation Version distributed via the Maven Jar Repository. Clover is not free. You have 30 days to evaluate it. Please visit http://www.thecortex.net/clover to obtain a licensed version of Clover
 
 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.tapestry.IComponent;
 21   
 import org.apache.tapestry.spec.IAssetSpecification;
 22   
 import org.apache.tapestry.spec.IComponentSpecification;
 23   
 
 24   
 /**
 25   
  * Injects assets as component properties.
 26   
  * 
 27   
  * @author Howard M. Lewis Ship
 28   
  * @since 4.0
 29   
  */
 30   
 public class InjectAssetWorker implements EnhancementWorker
 31   
 {
 32   
     private ErrorLog _errorLog;
 33   
 
 34  465
     public void performEnhancement(EnhancementOperation op, IComponentSpecification spec)
 35   
     {
 36  465
         Iterator i = spec.getAssetNames().iterator();
 37  465
         while (i.hasNext())
 38   
         {
 39  41
             String name = (String) i.next();
 40   
 
 41  41
             IAssetSpecification as = spec.getAsset(name);
 42   
 
 43  41
             String propertyName = as.getPropertyName();
 44   
 
 45  41
             if (propertyName != null)
 46   
             {
 47  2
                 try
 48   
                 {
 49  2
                     injectAsset(op, name, propertyName);
 50   
                 }
 51   
                 catch (Exception ex)
 52   
                 {
 53  1
                     _errorLog.error(EnhanceMessages.errorAddingProperty(propertyName, op
 54   
                             .getBaseClass(), ex), as.getLocation(), ex);
 55   
                 }
 56   
             }
 57   
         }
 58   
     }
 59   
 
 60  2
     private void injectAsset(EnhancementOperation op, String assetName, String propertyName)
 61   
     {
 62  2
         Class propertyType = EnhanceUtils.extractPropertyType(op, propertyName, null);
 63   
 
 64   
         // TODO: Should be compatible with IAsset.
 65   
 
 66  2
         op.claimProperty(propertyName);
 67   
 
 68  1
         String fieldName = "_$" + propertyName;
 69   
 
 70  1
         op.addField(fieldName, propertyType);
 71   
 
 72  1
         EnhanceUtils.createSimpleAccessor(op, fieldName, propertyName, propertyType);
 73   
 
 74   
         // i.e. _$fred = getAsset("barney");
 75   
         
 76  1
         String code = fieldName + " = getAsset(\"" + assetName + "\");";
 77   
 
 78  1
         op.extendMethodImplementation(IComponent.class, EnhanceUtils.FINISH_LOAD_SIGNATURE, code);
 79   
     }
 80   
 
 81  46
     public void setErrorLog(ErrorLog errorLog)
 82   
     {
 83  46
         _errorLog = errorLog;
 84   
     }
 85   
 }