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 | 0 | 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 | 0 | injectSpecification(op, spec); |
41 | |
} |
42 | 0 | catch (Exception ex) |
43 | |
{ |
44 | 0 | _errorLog.error(EnhanceMessages.errorAddingProperty( |
45 | |
SPECIFICATION_PROPERTY_NAME, op.getBaseClass(), ex), spec |
46 | |
.getLocation(), ex); |
47 | 0 | } |
48 | 0 | } |
49 | |
|
50 | |
public void injectSpecification(EnhancementOperation op, |
51 | |
IComponentSpecification spec) |
52 | |
{ |
53 | 0 | Defense.notNull(op, "op"); |
54 | 0 | Defense.notNull(spec, "spec"); |
55 | |
|
56 | 0 | op.claimReadonlyProperty(SPECIFICATION_PROPERTY_NAME); |
57 | |
|
58 | 0 | String fieldName = op.addInjectedField("_$" |
59 | 0 | + SPECIFICATION_PROPERTY_NAME, IComponentSpecification.class, |
60 | |
spec); |
61 | |
|
62 | 0 | EnhanceUtils.createSimpleAccessor(op, fieldName, |
63 | |
SPECIFICATION_PROPERTY_NAME, IComponentSpecification.class, |
64 | |
spec.getLocation()); |
65 | 0 | } |
66 | |
|
67 | |
public void setErrorLog(ErrorLog errorLog) |
68 | |
{ |
69 | 0 | _errorLog = errorLog; |
70 | 0 | } |
71 | |
} |