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.tapestry.IComponent; |
21 |
| import org.apache.tapestry.event.PageDetachListener; |
22 |
| import org.apache.tapestry.spec.IComponentSpecification; |
23 |
| |
24 |
| |
25 |
| |
26 |
| |
27 |
| |
28 |
| |
29 |
| |
30 |
| |
31 |
| public class AbstractPropertyWorker implements EnhancementWorker |
32 |
| { |
33 |
| private ErrorLog _errorLog; |
34 |
| |
35 |
542
| public void performEnhancement(EnhancementOperation op, IComponentSpecification spec)
|
36 |
| { |
37 |
542
| Iterator i = op.findUnclaimedAbstractProperties().iterator();
|
38 |
| |
39 |
542
| while (i.hasNext())
|
40 |
| { |
41 |
998
| String name = (String) i.next();
|
42 |
| |
43 |
998
| try
|
44 |
| { |
45 |
998
| createProperty(op, name);
|
46 |
| } |
47 |
| catch (Exception ex) |
48 |
| { |
49 |
1
| _errorLog.error(
|
50 |
| EnhanceMessages.errorAddingProperty(name, op.getBaseClass(), ex), |
51 |
| spec.getLocation(), |
52 |
| ex); |
53 |
| } |
54 |
| } |
55 |
| } |
56 |
| |
57 |
998
| private void createProperty(EnhancementOperation op, String name)
|
58 |
| { |
59 |
| |
60 |
| |
61 |
998
| Class propertyType = op.getPropertyType(name);
|
62 |
| |
63 |
997
| String fieldName = "_$" + name;
|
64 |
997
| String defaultFieldName = fieldName + "$defaultValue";
|
65 |
| |
66 |
997
| op.addField(fieldName, propertyType);
|
67 |
997
| op.addField(defaultFieldName, propertyType);
|
68 |
| |
69 |
997
| EnhanceUtils.createSimpleAccessor(op, fieldName, name, propertyType);
|
70 |
997
| EnhanceUtils.createSimpleMutator(op, fieldName, name, propertyType);
|
71 |
| |
72 |
| |
73 |
| |
74 |
| |
75 |
997
| op.extendMethodImplementation(
|
76 |
| IComponent.class, |
77 |
| EnhanceUtils.FINISH_LOAD_SIGNATURE, |
78 |
| defaultFieldName + " = " + fieldName + ";"); |
79 |
| |
80 |
| |
81 |
| |
82 |
997
| op.extendMethodImplementation(
|
83 |
| PageDetachListener.class, |
84 |
| EnhanceUtils.PAGE_DETACHED_SIGNATURE, |
85 |
| fieldName + " = " + defaultFieldName + ";"); |
86 |
| |
87 |
| |
88 |
| |
89 |
997
| op.claimProperty(name);
|
90 |
| } |
91 |
| |
92 |
41
| public void setErrorLog(ErrorLog errorLog)
|
93 |
| { |
94 |
41
| _errorLog = errorLog;
|
95 |
| } |
96 |
| } |