|
1 |
| |
|
2 |
| |
|
3 |
| |
|
4 |
| |
|
5 |
| |
|
6 |
| |
|
7 |
| |
|
8 |
| |
|
9 |
| |
|
10 |
| |
|
11 |
| |
|
12 |
| |
|
13 |
| |
|
14 |
| |
|
15 |
| package org.apache.tapestry.enhance; |
|
16 |
| |
|
17 |
| import java.lang.reflect.Modifier; |
|
18 |
| |
|
19 |
| import org.apache.hivemind.ApplicationRuntimeException; |
|
20 |
| import org.apache.hivemind.Location; |
|
21 |
| import org.apache.hivemind.service.BodyBuilder; |
|
22 |
| import org.apache.hivemind.service.MethodSignature; |
|
23 |
| import org.apache.hivemind.util.Defense; |
|
24 |
| import org.apache.tapestry.engine.state.ApplicationStateManager; |
|
25 |
| import org.apache.tapestry.spec.InjectSpecification; |
|
26 |
| |
|
27 |
| |
|
28 |
| |
|
29 |
| |
|
30 |
| |
|
31 |
| |
|
32 |
| |
|
33 |
| |
|
34 |
| |
|
35 |
| public class InjectStateFlagWorker implements InjectEnhancementWorker |
|
36 |
| { |
|
37 |
| private ApplicationStateManager _applicationStateManager; |
|
38 |
| |
|
39 |
9
| public void performEnhancement(EnhancementOperation op, InjectSpecification spec)
|
|
40 |
| { |
|
41 |
9
| injectStateFlag(op, spec.getObject(), spec.getProperty(), spec.getLocation());
|
|
42 |
| } |
|
43 |
| |
|
44 |
9
| void injectStateFlag(EnhancementOperation op, String objectName, String propertyName,
|
|
45 |
| Location location) |
|
46 |
| { |
|
47 |
9
| Defense.notNull(op, "op");
|
|
48 |
9
| Defense.notNull(objectName, "objectName");
|
|
49 |
9
| Defense.notNull(propertyName, "propertyName");
|
|
50 |
| |
|
51 |
9
| Class propertyType = op.getPropertyType(propertyName);
|
|
52 |
| |
|
53 |
| |
|
54 |
| |
|
55 |
| |
|
56 |
9
| if (propertyType != null && propertyType != boolean.class)
|
|
57 |
3
| throw new ApplicationRuntimeException(EnhanceMessages.mustBeBoolean(propertyName),
|
|
58 |
| location, null); |
|
59 |
| |
|
60 |
6
| op.claimReadonlyProperty(propertyName);
|
|
61 |
| |
|
62 |
6
| String managerField = op.addInjectedField(
|
|
63 |
| "_$applicationStateManager", |
|
64 |
| ApplicationStateManager.class, |
|
65 |
| _applicationStateManager); |
|
66 |
| |
|
67 |
6
| BodyBuilder builder = new BodyBuilder();
|
|
68 |
6
| builder.begin();
|
|
69 |
6
| builder.add("return {0}.exists(", managerField);
|
|
70 |
6
| builder.addQuoted(objectName);
|
|
71 |
6
| builder.addln(");");
|
|
72 |
6
| builder.end();
|
|
73 |
| |
|
74 |
6
| String methodName = op.getAccessorMethodName(propertyName);
|
|
75 |
| |
|
76 |
6
| MethodSignature sig = new MethodSignature(boolean.class, methodName, null, null);
|
|
77 |
| |
|
78 |
6
| op.addMethod(Modifier.PUBLIC, sig, builder.toString(), location);
|
|
79 |
| } |
|
80 |
| |
|
81 |
9
| public void setApplicationStateManager(ApplicationStateManager applicationStateManager)
|
|
82 |
| { |
|
83 |
9
| _applicationStateManager = applicationStateManager;
|
|
84 |
| } |
|
85 |
| |
|
86 |
| } |