1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
package org.apache.tapestry.contrib.inspector; |
16 |
|
|
17 |
|
import java.util.ArrayList; |
18 |
|
import java.util.Collection; |
19 |
|
import java.util.Collections; |
20 |
|
import java.util.Comparator; |
21 |
|
import java.util.List; |
22 |
|
import java.util.Map; |
23 |
|
|
24 |
|
import org.apache.tapestry.BaseComponent; |
25 |
|
import org.apache.tapestry.IAsset; |
26 |
|
import org.apache.tapestry.IBinding; |
27 |
|
import org.apache.tapestry.IComponent; |
28 |
|
import org.apache.tapestry.event.PageBeginRenderListener; |
29 |
|
import org.apache.tapestry.event.PageEndRenderListener; |
30 |
|
import org.apache.tapestry.event.PageEvent; |
31 |
|
import org.apache.tapestry.spec.IBeanSpecification; |
32 |
|
import org.apache.tapestry.spec.IComponentSpecification; |
33 |
|
import org.apache.tapestry.spec.IParameterSpecification; |
34 |
|
|
35 |
|
|
36 |
|
|
37 |
|
|
38 |
|
|
39 |
|
|
40 |
|
|
41 |
|
|
42 |
0 |
public abstract class ShowSpecification extends BaseComponent implements PageBeginRenderListener, |
43 |
|
PageEndRenderListener |
44 |
|
{ |
45 |
|
private IComponent _inspectedComponent; |
46 |
|
|
47 |
|
private IComponentSpecification _inspectedSpecification; |
48 |
|
|
49 |
|
private String _parameterName; |
50 |
|
|
51 |
|
private String _assetName; |
52 |
|
|
53 |
|
private List _sortedComponents; |
54 |
|
|
55 |
|
private List _assetNames; |
56 |
|
|
57 |
|
private List _formalParameterNames; |
58 |
|
|
59 |
|
private List _informalParameterNames; |
60 |
|
|
61 |
|
private List _sortedPropertyNames; |
62 |
|
|
63 |
|
private String _propertyName; |
64 |
|
|
65 |
|
private List _beanNames; |
66 |
|
|
67 |
|
private String _beanName; |
68 |
|
|
69 |
|
private IBeanSpecification _beanSpecification; |
70 |
|
|
71 |
|
|
72 |
|
|
73 |
|
|
74 |
|
|
75 |
0 |
private static class ComponentComparitor implements Comparator |
76 |
|
{ |
77 |
|
public int compare(Object left, Object right) |
78 |
|
{ |
79 |
|
IComponent leftComponent; |
80 |
|
String leftId; |
81 |
|
IComponent rightComponent; |
82 |
|
String rightId; |
83 |
|
|
84 |
0 |
if (left == right) |
85 |
0 |
return 0; |
86 |
|
|
87 |
0 |
leftComponent = (IComponent) left; |
88 |
0 |
rightComponent = (IComponent) right; |
89 |
|
|
90 |
0 |
leftId = leftComponent.getId(); |
91 |
0 |
rightId = rightComponent.getId(); |
92 |
|
|
93 |
0 |
return leftId.compareTo(rightId); |
94 |
|
} |
95 |
|
} |
96 |
|
|
97 |
|
|
98 |
|
|
99 |
|
|
100 |
|
|
101 |
|
|
102 |
|
|
103 |
|
|
104 |
|
public void pageEndRender(PageEvent event) |
105 |
|
{ |
106 |
0 |
_inspectedComponent = null; |
107 |
0 |
_inspectedSpecification = null; |
108 |
0 |
_parameterName = null; |
109 |
0 |
_assetName = null; |
110 |
0 |
_sortedComponents = null; |
111 |
0 |
_assetNames = null; |
112 |
0 |
_formalParameterNames = null; |
113 |
0 |
_informalParameterNames = null; |
114 |
0 |
_sortedPropertyNames = null; |
115 |
0 |
_propertyName = null; |
116 |
0 |
_beanNames = null; |
117 |
0 |
_beanName = null; |
118 |
0 |
_beanSpecification = null; |
119 |
0 |
} |
120 |
|
|
121 |
|
|
122 |
|
|
123 |
|
|
124 |
|
|
125 |
|
|
126 |
|
|
127 |
|
public void pageBeginRender(PageEvent event) |
128 |
|
{ |
129 |
0 |
Inspector inspector = (Inspector) getPage(); |
130 |
|
|
131 |
0 |
_inspectedComponent = inspector.getInspectedComponent(); |
132 |
0 |
_inspectedSpecification = _inspectedComponent.getSpecification(); |
133 |
0 |
} |
134 |
|
|
135 |
|
public IComponent getInspectedComponent() |
136 |
|
{ |
137 |
0 |
return _inspectedComponent; |
138 |
|
} |
139 |
|
|
140 |
|
public IComponentSpecification getInspectedSpecification() |
141 |
|
{ |
142 |
0 |
return _inspectedSpecification; |
143 |
|
} |
144 |
|
|
145 |
|
|
146 |
|
|
147 |
|
|
148 |
|
|
149 |
|
public List getFormalParameterNames() |
150 |
|
{ |
151 |
0 |
if (_formalParameterNames == null) |
152 |
0 |
_formalParameterNames = sort(_inspectedSpecification.getParameterNames()); |
153 |
|
|
154 |
0 |
return _formalParameterNames; |
155 |
|
} |
156 |
|
|
157 |
|
|
158 |
|
|
159 |
|
|
160 |
|
|
161 |
|
|
162 |
|
public List getInformalParameterNames() |
163 |
|
{ |
164 |
0 |
if (_informalParameterNames != null) |
165 |
0 |
return _informalParameterNames; |
166 |
|
|
167 |
0 |
Collection names = _inspectedComponent.getBindingNames(); |
168 |
0 |
if (names != null && names.size() > 0) |
169 |
|
{ |
170 |
0 |
_informalParameterNames = new ArrayList(names); |
171 |
|
|
172 |
|
|
173 |
|
|
174 |
|
|
175 |
|
|
176 |
|
|
177 |
0 |
names = _inspectedSpecification.getParameterNames(); |
178 |
0 |
if (names != null) |
179 |
0 |
_informalParameterNames.removeAll(names); |
180 |
|
|
181 |
0 |
Collections.sort(_informalParameterNames); |
182 |
|
} |
183 |
|
|
184 |
0 |
return _informalParameterNames; |
185 |
|
} |
186 |
|
|
187 |
|
public String getParameterName() |
188 |
|
{ |
189 |
0 |
return _parameterName; |
190 |
|
} |
191 |
|
|
192 |
|
public void setParameterName(String value) |
193 |
|
{ |
194 |
0 |
_parameterName = value; |
195 |
0 |
} |
196 |
|
|
197 |
|
|
198 |
|
|
199 |
|
|
200 |
|
|
201 |
|
|
202 |
|
public IParameterSpecification getParameterSpecification() |
203 |
|
{ |
204 |
0 |
return _inspectedSpecification.getParameter(_parameterName); |
205 |
|
} |
206 |
|
|
207 |
|
|
208 |
|
|
209 |
|
|
210 |
|
|
211 |
|
public IBinding getBinding() |
212 |
|
{ |
213 |
0 |
return _inspectedComponent.getBinding(_parameterName); |
214 |
|
} |
215 |
|
|
216 |
|
public void setAssetName(String value) |
217 |
|
{ |
218 |
0 |
_assetName = value; |
219 |
0 |
} |
220 |
|
|
221 |
|
public String getAssetName() |
222 |
|
{ |
223 |
0 |
return _assetName; |
224 |
|
} |
225 |
|
|
226 |
|
|
227 |
|
|
228 |
|
|
229 |
|
|
230 |
|
public IAsset getAsset() |
231 |
|
{ |
232 |
0 |
return (IAsset) _inspectedComponent.getAssets().get(_assetName); |
233 |
|
} |
234 |
|
|
235 |
|
|
236 |
|
|
237 |
|
|
238 |
|
|
239 |
|
public List getAssetNames() |
240 |
|
{ |
241 |
0 |
if (_assetNames == null) |
242 |
0 |
_assetNames = sort(_inspectedComponent.getAssets().keySet()); |
243 |
|
|
244 |
0 |
return _assetNames; |
245 |
|
} |
246 |
|
|
247 |
|
public List getSortedComponents() |
248 |
|
{ |
249 |
0 |
if (_sortedComponents != null) |
250 |
0 |
return _sortedComponents; |
251 |
|
|
252 |
0 |
Inspector inspector = (Inspector) getPage(); |
253 |
0 |
IComponent inspectedComponent = inspector.getInspectedComponent(); |
254 |
|
|
255 |
|
|
256 |
|
|
257 |
|
|
258 |
0 |
Map components = inspectedComponent.getComponents(); |
259 |
|
|
260 |
0 |
_sortedComponents = new ArrayList(components.values()); |
261 |
|
|
262 |
0 |
Collections.sort(_sortedComponents, new ComponentComparitor()); |
263 |
|
|
264 |
0 |
return _sortedComponents; |
265 |
|
} |
266 |
|
|
267 |
|
public abstract void setCurrentComponent(IComponent value); |
268 |
|
|
269 |
|
public abstract IComponent getCurrentComponent(); |
270 |
|
|
271 |
|
|
272 |
|
|
273 |
|
|
274 |
|
|
275 |
|
|
276 |
|
public List getSortedPropertyNames() |
277 |
|
{ |
278 |
0 |
if (_sortedPropertyNames == null) |
279 |
0 |
_sortedPropertyNames = sort(_inspectedSpecification.getPropertyNames()); |
280 |
|
|
281 |
0 |
return _sortedPropertyNames; |
282 |
|
} |
283 |
|
|
284 |
|
public void setPropertyName(String value) |
285 |
|
{ |
286 |
0 |
_propertyName = value; |
287 |
0 |
} |
288 |
|
|
289 |
|
public String getPropertyName() |
290 |
|
{ |
291 |
0 |
return _propertyName; |
292 |
|
} |
293 |
|
|
294 |
|
public String getPropertyValue() |
295 |
|
{ |
296 |
0 |
return _inspectedSpecification.getProperty(_propertyName); |
297 |
|
} |
298 |
|
|
299 |
|
public List getBeanNames() |
300 |
|
{ |
301 |
0 |
if (_beanNames == null) |
302 |
0 |
_beanNames = sort(_inspectedSpecification.getBeanNames()); |
303 |
|
|
304 |
0 |
return _beanNames; |
305 |
|
} |
306 |
|
|
307 |
|
public void setBeanName(String value) |
308 |
|
{ |
309 |
0 |
_beanName = value; |
310 |
0 |
_beanSpecification = _inspectedSpecification.getBeanSpecification(_beanName); |
311 |
0 |
} |
312 |
|
|
313 |
|
public String getBeanName() |
314 |
|
{ |
315 |
0 |
return _beanName; |
316 |
|
} |
317 |
|
|
318 |
|
public IBeanSpecification getBeanSpecification() |
319 |
|
{ |
320 |
0 |
return _beanSpecification; |
321 |
|
} |
322 |
|
|
323 |
|
private List sort(Collection c) |
324 |
|
{ |
325 |
0 |
if (c == null || c.size() == 0) |
326 |
0 |
return null; |
327 |
|
|
328 |
0 |
List result = new ArrayList(c); |
329 |
|
|
330 |
0 |
Collections.sort(result); |
331 |
|
|
332 |
0 |
return result; |
333 |
|
} |
334 |
|
} |