Clover coverage report - Code Coverage for tapestry release 4.0-beta-9
Coverage timestamp: Sat Oct 1 2005 08:36:20 EDT
file stats: LOC: 99   Methods: 3
NCLOC: 53   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
AbstractPropertyWorker.java 100% 100% 100% 100%
coverage
 1    // Copyright 2004, 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.tapestry.IComponent;
 22    import org.apache.tapestry.event.PageDetachListener;
 23    import org.apache.tapestry.spec.IComponentSpecification;
 24   
 25    /**
 26    * No, this class isn't abstract ... this worker locates abstract properties in the base component
 27    * class and provides a concrete implementation for them in the enhanced class.
 28    *
 29    * @author Howard M. Lewis Ship
 30    * @since 4.0
 31    */
 32    public class AbstractPropertyWorker implements EnhancementWorker
 33    {
 34    private ErrorLog _errorLog;
 35   
 36  583 public void performEnhancement(EnhancementOperation op, IComponentSpecification spec)
 37    {
 38  583 Location location = spec.getLocation();
 39   
 40  583 Iterator i = op.findUnclaimedAbstractProperties().iterator();
 41   
 42  583 while (i.hasNext())
 43    {
 44  1359 String name = (String) i.next();
 45   
 46  1359 try
 47    {
 48  1359 createProperty(op, name, location);
 49    }
 50    catch (Exception ex)
 51    {
 52  1 _errorLog.error(
 53    EnhanceMessages.errorAddingProperty(name, op.getBaseClass(), ex),
 54    location,
 55    ex);
 56    }
 57    }
 58    }
 59   
 60  1359 private void createProperty(EnhancementOperation op, String name, Location location)
 61    {
 62    // This won't be null because its always for existing properties.
 63   
 64  1359 Class propertyType = op.getPropertyType(name);
 65   
 66  1358 String fieldName = "_$" + name;
 67  1358 String defaultFieldName = fieldName + "$defaultValue";
 68   
 69  1358 op.addField(fieldName, propertyType);
 70  1358 op.addField(defaultFieldName, propertyType);
 71   
 72  1358 EnhanceUtils.createSimpleAccessor(op, fieldName, name, propertyType, location);
 73  1358 EnhanceUtils.createSimpleMutator(op, fieldName, name, propertyType, location);
 74   
 75    // Copy the real attribute into the default attribute inside finish load
 76    // (allowing a default value to be set inside finishLoad()).
 77   
 78  1358 op.extendMethodImplementation(
 79    IComponent.class,
 80    EnhanceUtils.FINISH_LOAD_SIGNATURE,
 81    defaultFieldName + " = " + fieldName + ";");
 82   
 83    // On page detach, restore the attribute to its default value.
 84   
 85  1358 op.extendMethodImplementation(
 86    PageDetachListener.class,
 87    EnhanceUtils.PAGE_DETACHED_SIGNATURE,
 88    fieldName + " = " + defaultFieldName + ";");
 89   
 90    // This is not all that necessary, but is proper.
 91   
 92  1358 op.claimProperty(name);
 93    }
 94   
 95  42 public void setErrorLog(ErrorLog errorLog)
 96    {
 97  42 _errorLog = errorLog;
 98    }
 99    }