|
1 |
| |
|
2 |
| |
|
3 |
| |
|
4 |
| |
|
5 |
| |
|
6 |
| |
|
7 |
| |
|
8 |
| |
|
9 |
| |
|
10 |
| |
|
11 |
| |
|
12 |
| |
|
13 |
| |
|
14 |
| |
|
15 |
| package org.apache.tapestry.enhance; |
|
16 |
| |
|
17 |
| import java.lang.reflect.Modifier; |
|
18 |
| import java.util.Iterator; |
|
19 |
| |
|
20 |
| import org.apache.hivemind.ErrorLog; |
|
21 |
| import org.apache.hivemind.Location; |
|
22 |
| import org.apache.hivemind.service.ClassFabUtils; |
|
23 |
| import org.apache.hivemind.service.MethodSignature; |
|
24 |
| import org.apache.hivemind.util.Defense; |
|
25 |
| import org.apache.tapestry.spec.IBeanSpecification; |
|
26 |
| import org.apache.tapestry.spec.IComponentSpecification; |
|
27 |
| |
|
28 |
| |
|
29 |
| |
|
30 |
| |
|
31 |
| |
|
32 |
| |
|
33 |
| |
|
34 |
| public class InjectBeanWorker implements EnhancementWorker |
|
35 |
| { |
|
36 |
| private ErrorLog _errorLog; |
|
37 |
| |
|
38 |
1176
| public void performEnhancement(EnhancementOperation op, IComponentSpecification spec)
|
|
39 |
| { |
|
40 |
1176
| Iterator i = spec.getBeanNames().iterator();
|
|
41 |
| |
|
42 |
1176
| while (i.hasNext())
|
|
43 |
| { |
|
44 |
75
| String name = (String) i.next();
|
|
45 |
| |
|
46 |
75
| IBeanSpecification bs = spec.getBeanSpecification(name);
|
|
47 |
| |
|
48 |
75
| String propertyName = bs.getPropertyName();
|
|
49 |
75
| if (propertyName != null)
|
|
50 |
| { |
|
51 |
18
| try
|
|
52 |
| { |
|
53 |
18
| injectBean(op, name, propertyName, bs.getLocation());
|
|
54 |
| } |
|
55 |
| catch (Exception ex) |
|
56 |
| { |
|
57 |
3
| _errorLog.error(EnhanceMessages.errorAddingProperty(propertyName, op
|
|
58 |
| .getBaseClass(), ex), bs.getLocation(), ex); |
|
59 |
| } |
|
60 |
| } |
|
61 |
| } |
|
62 |
| } |
|
63 |
| |
|
64 |
18
| public void injectBean(EnhancementOperation op, String beanName, String propertyName,
|
|
65 |
| Location location) |
|
66 |
| { |
|
67 |
18
| Defense.notNull(op, "op");
|
|
68 |
18
| Defense.notNull(beanName, "beanName");
|
|
69 |
18
| Defense.notNull(propertyName, "propertyName");
|
|
70 |
| |
|
71 |
18
| op.claimReadonlyProperty(propertyName);
|
|
72 |
| |
|
73 |
15
| Class propertyType = EnhanceUtils.extractPropertyType(op, propertyName, null);
|
|
74 |
| |
|
75 |
15
| String methodName = op.getAccessorMethodName(propertyName);
|
|
76 |
| |
|
77 |
15
| MethodSignature sig = new MethodSignature(propertyType, methodName, null, null);
|
|
78 |
| |
|
79 |
| |
|
80 |
| |
|
81 |
| |
|
82 |
15
| op.addMethod(Modifier.PUBLIC, sig, "return ("
|
|
83 |
| + ClassFabUtils.getJavaClassName(propertyType) + ") getBeans().getBean(\"" |
|
84 |
| + beanName + "\");", location); |
|
85 |
| } |
|
86 |
| |
|
87 |
120
| public void setErrorLog(ErrorLog errorLog)
|
|
88 |
| { |
|
89 |
120
| _errorLog = errorLog;
|
|
90 |
| } |
|
91 |
| } |