KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > tapestry > annotations > ParameterAnnotationWorker


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 JavaDoc;
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     public void performEnhancement(EnhancementOperation op, IComponentSpecification spec,
38             Method JavaDoc method, Location location)
39     {
40         Parameter parameter = method.getAnnotation(Parameter.class);
41
42         String JavaDoc propertyName = AnnotationUtils.getPropertyName(method);
43
44         boolean deprecated = method.isAnnotationPresent(Deprecated JavaDoc.class);
45
46         IParameterSpecification ps = new ParameterSpecification();
47
48         String JavaDoc parameterName = parameter.name();
49
50         if (HiveMind.isBlank(parameterName))
51             parameterName = propertyName;
52
53         Class JavaDoc propertyType = op.getPropertyType(propertyName);
54
55         ps.setAliases(parameter.aliases());
56         ps.setCache(parameter.cache());
57
58         if (HiveMind.isNonBlank(parameter.defaultBinding()))
59             ps.setDefaultBindingType(parameter.defaultBinding());
60
61         if (HiveMind.isNonBlank(parameter.defaultValue()))
62             ps.setDefaultValue(parameter.defaultValue());
63
64         ps.setDeprecated(deprecated);
65         ps.setParameterName(parameterName);
66         ps.setPropertyName(propertyName);
67         ps.setRequired(parameter.required());
68         ps.setType(propertyType.getName());
69         ps.setLocation(location);
70
71         spec.addParameter(ps);
72     }
73 }
74
Popular Tags