|
|||||||||||||||||||
30 day Evaluation License registered to hlship@comcast.net Your 30 day evaluation period has expired. Please visit http://www.cenqua.com to obtain a licensed version of Clover | |||||||||||||||||||
Source file | Conditionals | Statements | Methods | TOTAL | |||||||||||||||
ParameterAnnotationWorker.java | 83.3% | 95.2% | 100% | 92.9% |
|
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.HiveMind; | |
20 | import org.apache.hivemind.Location; | |
21 | import org.apache.tapestry.enhance.EnhancementOperation; | |
22 | import org.apache.tapestry.spec.IComponentSpecification; | |
23 | import org.apache.tapestry.spec.IParameterSpecification; | |
24 | import org.apache.tapestry.spec.ParameterSpecification; | |
25 | ||
26 | /** | |
27 | * Generates a {@link org.apache.tapestry.spec.IParameterSpecification} from a | |
28 | * {@link org.apache.tapestry.annotations.Parameter} annotation and adds it to the | |
29 | * {@link org.apache.tapestry.spec.IComponentSpecification}. | |
30 | * | |
31 | * @author Howard M. Lewis Ship | |
32 | * @since 4.0 | |
33 | */ | |
34 | public class ParameterAnnotationWorker implements MethodAnnotationEnhancementWorker | |
35 | { | |
36 | ||
37 | 7 | public void performEnhancement(EnhancementOperation op, IComponentSpecification spec, |
38 | Method method, Location location) | |
39 | { | |
40 | 7 | Parameter parameter = method.getAnnotation(Parameter.class); |
41 | ||
42 | 7 | String propertyName = AnnotationUtils.getPropertyName(method); |
43 | ||
44 | 7 | boolean deprecated = method.isAnnotationPresent(Deprecated.class); |
45 | ||
46 | 7 | IParameterSpecification ps = new ParameterSpecification(); |
47 | ||
48 | 7 | String parameterName = parameter.name(); |
49 | ||
50 | 7 | if (HiveMind.isBlank(parameterName)) |
51 | 6 | parameterName = propertyName; |
52 | ||
53 | 7 | Class propertyType = op.getPropertyType(propertyName); |
54 | ||
55 | 7 | ps.setAliases(parameter.aliases()); |
56 | 7 | ps.setCache(parameter.cache()); |
57 | ||
58 | 7 | if (HiveMind.isNonBlank(parameter.defaultBinding())) |
59 | 1 | ps.setDefaultBindingType(parameter.defaultBinding()); |
60 | ||
61 | 7 | if (HiveMind.isNonBlank(parameter.defaultValue())) |
62 | 0 | ps.setDefaultValue(parameter.defaultValue()); |
63 | ||
64 | 7 | ps.setDeprecated(deprecated); |
65 | 7 | ps.setParameterName(parameterName); |
66 | 7 | ps.setPropertyName(propertyName); |
67 | 7 | ps.setRequired(parameter.required()); |
68 | 7 | ps.setType(propertyType.getName()); |
69 | 7 | ps.setLocation(location); |
70 | ||
71 | 7 | spec.addParameter(ps); |
72 | } | |
73 | } |
|