|
1 |
| |
|
2 |
| |
|
3 |
| |
|
4 |
| |
|
5 |
| |
|
6 |
| |
|
7 |
| |
|
8 |
| |
|
9 |
| |
|
10 |
| |
|
11 |
| |
|
12 |
| |
|
13 |
| |
|
14 |
| |
|
15 |
| package org.apache.tapestry.enhance; |
|
16 |
| |
|
17 |
| import java.util.Iterator; |
|
18 |
| |
|
19 |
| import org.apache.hivemind.ErrorLog; |
|
20 |
| import org.apache.hivemind.Location; |
|
21 |
| import org.apache.tapestry.IComponent; |
|
22 |
| import org.apache.tapestry.event.PageDetachListener; |
|
23 |
| import org.apache.tapestry.spec.IComponentSpecification; |
|
24 |
| |
|
25 |
| |
|
26 |
| |
|
27 |
| |
|
28 |
| |
|
29 |
| |
|
30 |
| |
|
31 |
| |
|
32 |
| public class AbstractPropertyWorker implements EnhancementWorker |
|
33 |
| { |
|
34 |
| private ErrorLog _errorLog; |
|
35 |
| |
|
36 |
1683
| public void performEnhancement(EnhancementOperation op, IComponentSpecification spec)
|
|
37 |
| { |
|
38 |
1683
| Location location = spec.getLocation();
|
|
39 |
| |
|
40 |
1683
| Iterator i = op.findUnclaimedAbstractProperties().iterator();
|
|
41 |
| |
|
42 |
1683
| while (i.hasNext())
|
|
43 |
| { |
|
44 |
4338
| String name = (String) i.next();
|
|
45 |
| |
|
46 |
4338
| try
|
|
47 |
| { |
|
48 |
4338
| createProperty(op, name, location);
|
|
49 |
| } |
|
50 |
| catch (Exception ex) |
|
51 |
| { |
|
52 |
3
| _errorLog.error(
|
|
53 |
| EnhanceMessages.errorAddingProperty(name, op.getBaseClass(), ex), |
|
54 |
| location, |
|
55 |
| ex); |
|
56 |
| } |
|
57 |
| } |
|
58 |
| } |
|
59 |
| |
|
60 |
4338
| private void createProperty(EnhancementOperation op, String name, Location location)
|
|
61 |
| { |
|
62 |
| |
|
63 |
| |
|
64 |
4338
| Class propertyType = op.getPropertyType(name);
|
|
65 |
| |
|
66 |
4335
| String fieldName = "_$" + name;
|
|
67 |
4335
| String defaultFieldName = fieldName + "$defaultValue";
|
|
68 |
| |
|
69 |
4335
| op.addField(fieldName, propertyType);
|
|
70 |
4335
| op.addField(defaultFieldName, propertyType);
|
|
71 |
| |
|
72 |
4335
| EnhanceUtils.createSimpleAccessor(op, fieldName, name, propertyType, location);
|
|
73 |
4335
| EnhanceUtils.createSimpleMutator(op, fieldName, name, propertyType, location);
|
|
74 |
| |
|
75 |
| |
|
76 |
| |
|
77 |
| |
|
78 |
4335
| op.extendMethodImplementation(
|
|
79 |
| IComponent.class, |
|
80 |
| EnhanceUtils.FINISH_LOAD_SIGNATURE, |
|
81 |
| defaultFieldName + " = " + fieldName + ";"); |
|
82 |
| |
|
83 |
| |
|
84 |
| |
|
85 |
4335
| op.extendMethodImplementation(
|
|
86 |
| PageDetachListener.class, |
|
87 |
| EnhanceUtils.PAGE_DETACHED_SIGNATURE, |
|
88 |
| fieldName + " = " + defaultFieldName + ";"); |
|
89 |
| |
|
90 |
| |
|
91 |
| |
|
92 |
4335
| op.claimProperty(name);
|
|
93 |
| } |
|
94 |
| |
|
95 |
120
| public void setErrorLog(ErrorLog errorLog)
|
|
96 |
| { |
|
97 |
120
| _errorLog = errorLog;
|
|
98 |
| } |
|
99 |
| } |