|
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.tapestry.IPage; |
|
24 |
| import org.apache.tapestry.spec.InjectSpecification; |
|
25 |
| |
|
26 |
| |
|
27 |
| |
|
28 |
| |
|
29 |
| |
|
30 |
| |
|
31 |
| |
|
32 |
| public class InjectPageWorker implements InjectEnhancementWorker |
|
33 |
| { |
|
34 |
9
| public void performEnhancement(EnhancementOperation op, InjectSpecification spec)
|
|
35 |
| { |
|
36 |
9
| performEnhancement(op, spec.getObject(), spec.getProperty(), spec.getLocation());
|
|
37 |
| } |
|
38 |
| |
|
39 |
9
| public void performEnhancement(EnhancementOperation op, String pageName, String propertyName,
|
|
40 |
| Location location) |
|
41 |
| { |
|
42 |
9
| Class propertyType = op.getPropertyType(propertyName);
|
|
43 |
| |
|
44 |
9
| if (propertyType == null)
|
|
45 |
3
| propertyType = Object.class;
|
|
46 |
6
| else if (propertyType.isPrimitive())
|
|
47 |
3
| throw new ApplicationRuntimeException(EnhanceMessages.wrongTypeForPageInjection(
|
|
48 |
| propertyName, |
|
49 |
| propertyType), null, location, null); |
|
50 |
| |
|
51 |
6
| op.claimReadonlyProperty(propertyName);
|
|
52 |
| |
|
53 |
6
| MethodSignature sig = new MethodSignature(propertyType, op
|
|
54 |
| .getAccessorMethodName(propertyName), null, null); |
|
55 |
| |
|
56 |
6
| BodyBuilder builder = new BodyBuilder();
|
|
57 |
| |
|
58 |
6
| builder.add("return ");
|
|
59 |
| |
|
60 |
| |
|
61 |
| |
|
62 |
| |
|
63 |
6
| if (!propertyType.isAssignableFrom(IPage.class))
|
|
64 |
3
| builder.add("({0})", propertyType.getName());
|
|
65 |
| |
|
66 |
6
| builder.add("getPage().getRequestCycle().getPage(\"{0}\");", pageName);
|
|
67 |
| |
|
68 |
6
| op.addMethod(Modifier.PUBLIC, sig, builder.toString(), location);
|
|
69 |
| } |
|
70 |
| } |