1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
package org.apache.tapestry.listener; |
16 |
|
|
17 |
|
import java.util.Map; |
18 |
|
|
19 |
|
import ognl.ObjectPropertyAccessor; |
20 |
|
import ognl.OgnlContext; |
21 |
|
import ognl.OgnlException; |
22 |
|
import ognl.OgnlRuntime; |
23 |
|
import ognl.PropertyAccessor; |
24 |
|
import ognl.enhance.ExpressionCompiler; |
25 |
|
import ognl.enhance.UnsupportedCompilationException; |
26 |
|
|
27 |
|
|
28 |
|
|
29 |
|
|
30 |
|
|
31 |
|
|
32 |
|
|
33 |
|
|
34 |
|
|
35 |
|
|
36 |
0 |
public class ListenerMapPropertyAccessor extends ObjectPropertyAccessor implements PropertyAccessor |
37 |
|
{ |
38 |
|
|
39 |
|
|
40 |
|
|
41 |
|
|
42 |
|
|
43 |
|
|
44 |
|
|
45 |
|
public Object getProperty(Map context, Object target, Object name) |
46 |
|
throws OgnlException |
47 |
|
{ |
48 |
0 |
ListenerMap map = (ListenerMap) target; |
49 |
0 |
String listenerName = (String) name; |
50 |
|
|
51 |
0 |
if (map.canProvideListener(listenerName)) |
52 |
0 |
return map.getListener(listenerName); |
53 |
|
|
54 |
0 |
return super.getProperty(context, target, name); |
55 |
|
} |
56 |
|
|
57 |
|
|
58 |
|
|
59 |
|
|
60 |
|
|
61 |
|
|
62 |
|
public boolean hasGetProperty(Map context, Object target, Object oname) |
63 |
|
throws OgnlException |
64 |
|
{ |
65 |
0 |
ListenerMap map = (ListenerMap) target; |
66 |
0 |
String listenerName = (String) oname; |
67 |
|
|
68 |
0 |
if (map.canProvideListener(listenerName)) return true; |
69 |
|
|
70 |
0 |
return super.hasGetProperty(context, target, oname); |
71 |
|
} |
72 |
|
|
73 |
|
public Class getPropertyClass(OgnlContext context, Object target, Object name) |
74 |
|
{ |
75 |
0 |
ListenerMap map = (ListenerMap) target; |
76 |
0 |
String listenerName = (String) name; |
77 |
|
|
78 |
0 |
if (map.canProvideListener(listenerName)) |
79 |
0 |
return map.getListener(listenerName).getClass(); |
80 |
|
|
81 |
0 |
return super.getPropertyClass(context, target, name); |
82 |
|
} |
83 |
|
|
84 |
|
public String getSourceAccessor(OgnlContext context, Object target, Object name) |
85 |
|
{ |
86 |
0 |
ListenerMap map = (ListenerMap) target; |
87 |
0 |
String listenerName = ((String)name).replaceAll("\"", ""); |
88 |
|
|
89 |
0 |
if (map.canProvideListener(listenerName)) { |
90 |
|
|
91 |
0 |
Class type = OgnlRuntime.getCompiler().getInterfaceClass(map.getListener(listenerName).getClass()); |
92 |
|
|
93 |
0 |
ExpressionCompiler.addCastString(context, "((" + type.getName() + ")"); |
94 |
|
|
95 |
0 |
context.setCurrentAccessor(ListenerMap.class); |
96 |
0 |
context.setCurrentType(type); |
97 |
|
|
98 |
0 |
return ".getListener(" + name + "))"; |
99 |
|
} |
100 |
|
|
101 |
0 |
return super.getSourceAccessor(context, target, name); |
102 |
|
} |
103 |
|
|
104 |
|
public String getSourceSetter(OgnlContext context, Object target, Object name) |
105 |
|
{ |
106 |
0 |
throw new UnsupportedCompilationException("Can't set listeners on ListenerMap."); |
107 |
|
} |
108 |
|
} |