Clover coverage report - Code Coverage for tapestry-annotations release 4.0-beta-1
Coverage timestamp: Fri Jun 24 2005 14:37:32 EDT
file stats: LOC: 90   Methods: 3
NCLOC: 48   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
ComponentAnnotationWorker.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.ApplicationRuntimeException;
 20    import org.apache.tapestry.enhance.EnhancementOperation;
 21    import org.apache.tapestry.spec.BindingSpecification;
 22    import org.apache.tapestry.spec.BindingType;
 23    import org.apache.tapestry.spec.ContainedComponent;
 24    import org.apache.tapestry.spec.IBindingSpecification;
 25    import org.apache.tapestry.spec.IComponentSpecification;
 26    import org.apache.tapestry.spec.IContainedComponent;
 27   
 28    /**
 29    * Adds a {@link org.apache.tapestry.spec.IContainedComponent} to the
 30    * {@link org.apache.tapestry.spec.IComponentSpecification}.
 31    *
 32    * @author Howard Lewis Ship
 33    * @since 4.0
 34    * @see org.apache.tapestry.annotations.Component
 35    * @see org.apache.tapestry.annotations.Binding
 36    */
 37    public class ComponentAnnotationWorker implements MethodAnnotationEnhancementWorker
 38    {
 39   
 40  5 public void performEnhancement(EnhancementOperation op, IComponentSpecification spec,
 41    Method method)
 42    {
 43  5 Component component = method.getAnnotation(Component.class);
 44   
 45  5 String propertyName = AnnotationUtils.getPropertyName(method);
 46   
 47  5 IContainedComponent cc = new ContainedComponent();
 48   
 49  5 cc.setInheritInformalParameters(component.inheritInformalParameters());
 50  5 cc.setType(component.type());
 51  5 cc.setPropertyName(propertyName);
 52   
 53  5 for (String binding : component.bindings())
 54    {
 55  4 addBinding(cc, binding);
 56    }
 57   
 58  5 String id = component.id();
 59   
 60  5 if (id.equals(""))
 61  4 id = propertyName;
 62   
 63  5 spec.addComponent(id, cc);
 64    }
 65   
 66  7 void addBinding(IContainedComponent component, String binding)
 67    {
 68  7 int equalsx = binding.indexOf('=');
 69   
 70  7 if (equalsx < 1)
 71  2 invalidBinding(binding);
 72   
 73  5 if (equalsx + 1 >= binding.length())
 74  1 invalidBinding(binding);
 75   
 76  4 String name = binding.substring(0, equalsx).trim();
 77  4 String value = binding.substring(equalsx + 1).trim();
 78   
 79  4 IBindingSpecification bs = new BindingSpecification();
 80  4 bs.setType(BindingType.PREFIXED);
 81  4 bs.setValue(value);
 82   
 83  4 component.setBinding(name, bs);
 84    }
 85   
 86  3 private void invalidBinding(String binding)
 87    {
 88  3 throw new ApplicationRuntimeException(AnnotationMessages.bindingWrongFormat(binding));
 89    }
 90    }