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