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.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 |
| |
31 |
| |
32 |
| |
33 |
| |
34 |
| |
35 |
| |
36 |
| |
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 |
| } |