1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
package org.apache.tapestry.enhance; |
16 |
|
|
17 |
|
import org.apache.hivemind.ErrorLog; |
18 |
|
import org.apache.hivemind.util.Defense; |
19 |
|
import org.apache.tapestry.spec.IComponentSpecification; |
20 |
|
|
21 |
|
|
22 |
|
|
23 |
|
|
24 |
|
|
25 |
|
|
26 |
|
|
27 |
|
|
28 |
24 |
public class InjectSpecificationWorker implements EnhancementWorker |
29 |
|
{ |
30 |
|
|
31 |
|
public static final String SPECIFICATION_PROPERTY_NAME = "specification"; |
32 |
|
|
33 |
|
private ErrorLog _errorLog; |
34 |
|
|
35 |
|
public void performEnhancement(EnhancementOperation op, |
36 |
|
IComponentSpecification spec) |
37 |
|
{ |
38 |
|
try |
39 |
|
{ |
40 |
24 |
injectSpecification(op, spec); |
41 |
|
} |
42 |
1 |
catch (Exception ex) |
43 |
|
{ |
44 |
1 |
_errorLog.error(EnhanceMessages.errorAddingProperty( |
45 |
|
SPECIFICATION_PROPERTY_NAME, op.getBaseClass(), ex), spec |
46 |
|
.getLocation(), ex); |
47 |
23 |
} |
48 |
24 |
} |
49 |
|
|
50 |
|
public void injectSpecification(EnhancementOperation op, |
51 |
|
IComponentSpecification spec) |
52 |
|
{ |
53 |
24 |
Defense.notNull(op, "op"); |
54 |
24 |
Defense.notNull(spec, "spec"); |
55 |
|
|
56 |
24 |
op.claimReadonlyProperty(SPECIFICATION_PROPERTY_NAME); |
57 |
|
|
58 |
23 |
String fieldName = op.addInjectedField("_$" |
59 |
1 |
+ SPECIFICATION_PROPERTY_NAME, IComponentSpecification.class, |
60 |
|
spec); |
61 |
|
|
62 |
23 |
EnhanceUtils.createSimpleAccessor(op, fieldName, |
63 |
|
SPECIFICATION_PROPERTY_NAME, IComponentSpecification.class, |
64 |
|
spec.getLocation()); |
65 |
23 |
} |
66 |
|
|
67 |
|
public void setErrorLog(ErrorLog errorLog) |
68 |
|
{ |
69 |
1 |
_errorLog = errorLog; |
70 |
1 |
} |
71 |
|
} |