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 |
| public class InjectSpecificationWorker implements EnhancementWorker |
29 |
| { |
30 |
| public static final String SPECIFICATION_PROPERTY_NAME = "specification"; |
31 |
| |
32 |
| private ErrorLog _errorLog; |
33 |
| |
34 |
438
| public void performEnhancement(EnhancementOperation op, IComponentSpecification spec)
|
35 |
| { |
36 |
438
| try
|
37 |
| { |
38 |
438
| injectSpecification(op, spec);
|
39 |
| } |
40 |
| catch (Exception ex) |
41 |
| { |
42 |
1
| _errorLog.error(EnhanceMessages.errorAddingProperty(SPECIFICATION_PROPERTY_NAME, op
|
43 |
| .getBaseClass(), ex), spec.getLocation(), ex); |
44 |
| } |
45 |
| } |
46 |
| |
47 |
438
| public void injectSpecification(EnhancementOperation op, IComponentSpecification spec)
|
48 |
| { |
49 |
438
| Defense.notNull(op, "op");
|
50 |
438
| Defense.notNull(spec, "spec");
|
51 |
| |
52 |
438
| op.claimReadonlyProperty(SPECIFICATION_PROPERTY_NAME);
|
53 |
| |
54 |
437
| String fieldName = op.addInjectedField(
|
55 |
| "_$" + SPECIFICATION_PROPERTY_NAME, |
56 |
| IComponentSpecification.class, |
57 |
| spec); |
58 |
| |
59 |
437
| EnhanceUtils.createSimpleAccessor(
|
60 |
| op, |
61 |
| fieldName, |
62 |
| SPECIFICATION_PROPERTY_NAME, |
63 |
| IComponentSpecification.class, |
64 |
| spec.getLocation()); |
65 |
| } |
66 |
| |
67 |
42
| public void setErrorLog(ErrorLog errorLog)
|
68 |
| { |
69 |
42
| _errorLog = errorLog;
|
70 |
| } |
71 |
| } |