Coverage Report - org.apache.tapestry.annotations.ParameterAnnotationWorker
 
Classes in this File Line Coverage Branch Coverage Complexity
ParameterAnnotationWorker
0%
0/23
0%
0/6
5
 
 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.hivemind.HiveMind;
 21  
 import org.apache.hivemind.Location;
 22  
 import org.apache.tapestry.IPage;
 23  
 import org.apache.tapestry.enhance.EnhancementOperation;
 24  
 import org.apache.tapestry.spec.IComponentSpecification;
 25  
 import org.apache.tapestry.spec.IParameterSpecification;
 26  
 import org.apache.tapestry.spec.ParameterSpecification;
 27  
 
 28  
 /**
 29  
  * Generates a {@link org.apache.tapestry.spec.IParameterSpecification} from a
 30  
  * {@link org.apache.tapestry.annotations.Parameter} annotation and adds it to the
 31  
  * {@link org.apache.tapestry.spec.IComponentSpecification}.
 32  
  * 
 33  
  * @author Howard M. Lewis Ship
 34  
  * @since 4.0
 35  
  */
 36  0
 public class ParameterAnnotationWorker implements MethodAnnotationEnhancementWorker
 37  
 {
 38  
 
 39  
     public void performEnhancement(EnhancementOperation op, IComponentSpecification spec,
 40  
             Method method, Location location)
 41  
     {
 42  0
         if (IPage.class.isAssignableFrom(method.getDeclaringClass()))
 43  
         {
 44  0
             throw new ApplicationRuntimeException(
 45  
                     AnnotationMessages.invalidAnnotationInClass(Parameter.class, method.getDeclaringClass()));
 46  
         }       
 47  
         
 48  0
         Parameter parameter = method.getAnnotation(Parameter.class);
 49  
 
 50  0
         String propertyName = AnnotationUtils.getPropertyName(method);
 51  
 
 52  0
         boolean deprecated = method.isAnnotationPresent(Deprecated.class);
 53  
 
 54  0
         IParameterSpecification ps = new ParameterSpecification();
 55  
 
 56  0
         String parameterName = parameter.name();
 57  
 
 58  0
         if (HiveMind.isBlank(parameterName))
 59  0
             parameterName = propertyName;
 60  
 
 61  0
         Class propertyType = op.getPropertyType(propertyName);
 62  
 
 63  0
         ps.setAliases(parameter.aliases());
 64  0
         ps.setCache(parameter.cache());
 65  
 
 66  0
         if (HiveMind.isNonBlank(parameter.defaultValue()))
 67  0
             ps.setDefaultValue(parameter.defaultValue());
 68  
 
 69  0
         ps.setDeprecated(deprecated);
 70  0
         ps.setParameterName(parameterName);
 71  0
         ps.setPropertyName(propertyName);
 72  0
         ps.setRequired(parameter.required());
 73  0
         ps.setType(propertyType.getName());
 74  0
         ps.setLocation(location);
 75  
 
 76  0
         spec.addParameter(ps);
 77  0
     }
 78  
 }