This project has retired. For details please refer to its
Attic page.
TilesContextBeanELResolver xref
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 package org.apache.tiles.el;
22
23 import java.beans.FeatureDescriptor;
24 import java.util.ArrayList;
25 import java.util.Iterator;
26 import java.util.List;
27 import java.util.Map;
28
29 import javax.el.ELContext;
30 import javax.el.ELResolver;
31
32 import org.apache.tiles.request.Request;
33
34
35
36
37
38
39
40 public class TilesContextBeanELResolver extends ELResolver {
41
42
43 @Override
44 public Class<?> getCommonPropertyType(ELContext context, Object base) {
45
46 if (base != null) {
47 return null;
48 }
49
50 return String.class;
51 }
52
53
54 @Override
55 public Iterator<FeatureDescriptor> getFeatureDescriptors(ELContext context,
56 Object base) {
57 List<FeatureDescriptor> list = new ArrayList<FeatureDescriptor>();
58
59 Request request = (Request) context
60 .getContext(Request.class);
61 for (String scope : request.getAvailableScopes()) {
62 collectBeanInfo(request.getContext(scope), list);
63 }
64 return list.iterator();
65 }
66
67
68 @Override
69 public Class<?> getType(ELContext context, Object base, Object property) {
70 if (base != null) {
71 return null;
72 }
73
74 Object obj = findObjectByProperty(context, property);
75 if (obj != null) {
76 context.setPropertyResolved(true);
77 return obj.getClass();
78 }
79 return null;
80 }
81
82
83 @Override
84 public Object getValue(ELContext context, Object base, Object property) {
85 if (base != null) {
86 return null;
87 }
88
89 Object retValue = findObjectByProperty(context, property);
90
91 if (retValue != null) {
92 context.setPropertyResolved(true);
93 }
94
95 return retValue;
96 }
97
98
99 @Override
100 public boolean isReadOnly(ELContext context, Object base, Object property) {
101 if (context == null) {
102 throw new NullPointerException();
103 }
104
105 return true;
106 }
107
108
109 @Override
110 public void setValue(ELContext context, Object base, Object property,
111 Object value) {
112
113 }
114
115
116
117
118
119
120
121
122 protected void collectBeanInfo(Map<String, ? extends Object> map,
123 List<FeatureDescriptor> list) {
124 if (map == null || map.isEmpty()) {
125 return;
126 }
127
128 for (Map.Entry<String, ? extends Object> entry : map.entrySet()) {
129 FeatureDescriptor descriptor = new FeatureDescriptor();
130 descriptor.setDisplayName(entry.getKey());
131 descriptor.setExpert(false);
132 descriptor.setHidden(false);
133 descriptor.setName(entry.getKey());
134 descriptor.setPreferred(true);
135 descriptor.setShortDescription("");
136 descriptor.setValue("type", String.class);
137 descriptor.setValue("resolvableAtDesignTime", Boolean.FALSE);
138 list.add(descriptor);
139 }
140 }
141
142
143
144
145
146
147
148
149
150 protected Object findObjectByProperty(ELContext context, Object property) {
151 Object retValue = null;
152
153 Request request = (Request) context
154 .getContext(Request.class);
155
156 String prop = property.toString();
157
158 String[] scopes = request.getAvailableScopes().toArray(new String[0]);
159 int i = 0;
160 do {
161 retValue = getObject(request.getContext(scopes[i]), prop);
162 i++;
163 } while (retValue == null && i < scopes.length);
164
165 return retValue;
166 }
167
168
169
170
171
172
173
174
175
176 protected Object getObject(Map<String, ? extends Object> map,
177 String property) {
178 Object retValue = null;
179 if (map != null) {
180 retValue = map.get(property);
181 }
182 return retValue;
183 }
184 }