Clover coverage report - Code Coverage for tapestry-annotations release 4.0-beta-12
Coverage timestamp: Sun Oct 30 2005 16:28:56 EST
file stats: LOC: 71   Methods: 2
NCLOC: 31   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
InitialValueAnnotationWorker.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.annotations;
 16   
 17    import java.lang.reflect.Method;
 18   
 19    import org.apache.hivemind.Location;
 20    import org.apache.hivemind.Resource;
 21    import org.apache.tapestry.enhance.EnhancementOperation;
 22    import org.apache.tapestry.spec.IComponentSpecification;
 23    import org.apache.tapestry.spec.IPropertySpecification;
 24    import org.apache.tapestry.spec.PropertySpecification;
 25   
 26    /**
 27    * Looks for {@link org.apache.tapestry.annotations.InitialValue} annotations on methods that don't
 28    * have a {@link org.apache.tapestry.annotations.Persist} annotation (that's handled by
 29    * {@link org.apache.tapestry.annotations.PersistAnnotationWorker}); adds an
 30    * {@link org.apache.tapestry.spec.IPropertySpecification} for the property, so that its initial
 31    * value may be set.
 32    *
 33    * @author Howard M. Lewis Ship
 34    * @since 4.0
 35    */
 36    public class InitialValueAnnotationWorker implements SecondaryAnnotationWorker
 37    {
 38    /**
 39    * Returns true if the method has the InitialValue annotation.
 40    */
 41  2 public boolean canEnhance(Method method)
 42    {
 43  2 return method.getAnnotation(InitialValue.class) != null;
 44    }
 45   
 46  3 public void peformEnhancement(EnhancementOperation op, IComponentSpecification spec,
 47    Method method, Resource classResource)
 48    {
 49  3 InitialValue iv = method.getAnnotation(InitialValue.class);
 50   
 51  3 if (iv == null)
 52  1 return;
 53   
 54  2 if (method.getAnnotation(Persist.class) != null)
 55  1 return;
 56   
 57  1 Location location = AnnotationUtils.buildLocationForAnnotation(method, iv, classResource);
 58   
 59  1 String propertyName = AnnotationUtils.getPropertyName(method);
 60   
 61    // Define a transient property
 62   
 63  1 IPropertySpecification pspec = new PropertySpecification();
 64   
 65  1 pspec.setName(propertyName);
 66  1 pspec.setLocation(location);
 67  1 pspec.setInitialValue(iv.value());
 68   
 69  1 spec.addPropertySpecification(pspec);
 70    }
 71    }