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.internal.event.IComponentEventInvoker; |
20 | |
import org.apache.tapestry.spec.IComponentSpecification; |
21 | |
|
22 | |
|
23 | |
|
24 | |
|
25 | |
|
26 | |
|
27 | |
|
28 | |
|
29 | 0 | public class InjectEventInvokerWorker implements EnhancementWorker |
30 | |
{ |
31 | |
|
32 | |
public static final String PROPERTY_NAME = "eventInvoker"; |
33 | |
|
34 | |
private ErrorLog _errorLog; |
35 | |
|
36 | |
private IComponentEventInvoker _invoker; |
37 | |
|
38 | |
public void performEnhancement(EnhancementOperation op, IComponentSpecification spec) |
39 | |
{ |
40 | |
try |
41 | |
{ |
42 | 0 | injectEventInvoker(op, spec); |
43 | |
} |
44 | 0 | catch (Exception ex) |
45 | |
{ |
46 | 0 | _errorLog.error(EnhanceMessages.errorAddingProperty( |
47 | |
PROPERTY_NAME, op.getBaseClass(), ex), spec |
48 | |
.getLocation(), ex); |
49 | 0 | } |
50 | 0 | } |
51 | |
|
52 | |
public void injectEventInvoker(EnhancementOperation op, IComponentSpecification spec) |
53 | |
{ |
54 | 0 | Defense.notNull(op, "op"); |
55 | 0 | Defense.notNull(spec, "spec"); |
56 | |
|
57 | 0 | op.claimReadonlyProperty(PROPERTY_NAME); |
58 | |
|
59 | 0 | String fieldName = op.addInjectedField("_$" |
60 | 0 | + PROPERTY_NAME, IComponentEventInvoker.class, |
61 | |
_invoker); |
62 | |
|
63 | 0 | EnhanceUtils.createSimpleAccessor(op, fieldName, |
64 | |
PROPERTY_NAME, IComponentEventInvoker.class, |
65 | |
spec.getLocation()); |
66 | 0 | } |
67 | |
|
68 | |
public void setErrorLog(ErrorLog errorLog) |
69 | |
{ |
70 | 0 | _errorLog = errorLog; |
71 | 0 | } |
72 | |
|
73 | |
public void setComponentEventInvoker(IComponentEventInvoker invoker) |
74 | |
{ |
75 | 0 | _invoker = invoker; |
76 | 0 | } |
77 | |
} |