1 |
| |
2 |
| |
3 |
| |
4 |
| |
5 |
| |
6 |
| |
7 |
| |
8 |
| |
9 |
| |
10 |
| |
11 |
| |
12 |
| |
13 |
| |
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 |
| |
30 |
| |
31 |
| |
32 |
| |
33 |
| |
34 |
| |
35 |
| |
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 |
| } |