1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
package javax.faces.component; |
17 | |
|
18 | |
import java.io.IOException; |
19 | |
import java.lang.reflect.Array; |
20 | |
import java.util.ArrayList; |
21 | |
import java.util.HashMap; |
22 | |
import java.util.Iterator; |
23 | |
import java.util.List; |
24 | |
import java.util.Map; |
25 | |
|
26 | |
import javax.faces.context.FacesContext; |
27 | |
import javax.faces.el.ValueBinding; |
28 | |
import javax.faces.event.AbortProcessingException; |
29 | |
import javax.faces.event.FacesEvent; |
30 | |
import javax.faces.event.FacesListener; |
31 | |
import javax.faces.internal.AttachedObjectStateWrapper; |
32 | |
import javax.faces.internal.ComponentAttributesMap; |
33 | |
import javax.faces.internal.ComponentChildrenListWrapper; |
34 | |
import javax.faces.internal.ComponentFacetAndChildrenIterator; |
35 | |
import javax.faces.internal.ComponentFacetMapWrapper; |
36 | |
import javax.faces.internal.SerializableStateHolder; |
37 | |
import javax.faces.internal.UIComponentUtil; |
38 | |
import javax.faces.render.Renderer; |
39 | |
|
40 | |
import org.seasar.framework.util.AssertionUtil; |
41 | |
|
42 | |
|
43 | |
|
44 | |
|
45 | |
|
46 | 8970 | public abstract class UIComponentBase extends UIComponent { |
47 | |
|
48 | |
private String id; |
49 | |
|
50 | 8970 | private ComponentAttributesMap attributesMap = null; |
51 | |
|
52 | 8970 | private Map bindingMap = new HashMap(); |
53 | |
|
54 | |
private UIComponent parent; |
55 | |
|
56 | 8970 | private String clientId = null; |
57 | |
|
58 | |
private Boolean isRendered; |
59 | |
|
60 | 8970 | private String renderType = null; |
61 | |
|
62 | 8970 | private List childrenList = null; |
63 | |
|
64 | 8970 | private Map facetMap = null; |
65 | |
|
66 | 8970 | private List listeners = null; |
67 | |
|
68 | 8970 | private boolean isTransient = false; |
69 | |
|
70 | |
private String uniqueId; |
71 | |
|
72 | |
private static final String RENDERED = "rendered"; |
73 | |
|
74 | |
private static final String RENDERER_TYPE = "rendererType"; |
75 | |
|
76 | |
private static final int LIST_NULL_SIZE = 0; |
77 | |
|
78 | |
public Map getAttributes() { |
79 | 2305 | if (attributesMap == null) { |
80 | 650 | attributesMap = new ComponentAttributesMap(this); |
81 | |
} |
82 | 2305 | return attributesMap; |
83 | |
} |
84 | |
|
85 | |
public ValueBinding getValueBinding(String name) { |
86 | 12846 | AssertionUtil.assertNotNull("name", name); |
87 | 12802 | return (ValueBinding) bindingMap.get(name); |
88 | |
} |
89 | |
|
90 | |
public void setValueBinding(String name, ValueBinding binding) { |
91 | 1112 | AssertionUtil.assertNotNull("name", name); |
92 | 1071 | if (name.equals("id") || name.equals("parent")) { |
93 | 91 | throw new IllegalArgumentException("invalid name is specified"); |
94 | |
} |
95 | 980 | if (binding != null) { |
96 | 976 | bindingMap.put(name, binding); |
97 | |
} else { |
98 | 4 | bindingMap.remove(name); |
99 | |
} |
100 | 980 | } |
101 | |
|
102 | |
public String getClientId(FacesContext context) { |
103 | 1252 | AssertionUtil.assertNotNull("context", context); |
104 | 1211 | if (clientId == null) { |
105 | 825 | clientId = createClientId(context); |
106 | |
} |
107 | 1211 | return clientId; |
108 | |
} |
109 | |
|
110 | |
private String createClientId(FacesContext context) { |
111 | 825 | StringBuffer buf = new StringBuffer(32); |
112 | 954 | for (UIComponent component = getParent(); component != null; component = component |
113 | |
.getParent()) { |
114 | 228 | if (component instanceof NamingContainer) { |
115 | 99 | buf.append(component.getClientId(context)).append( |
116 | |
NamingContainer.SEPARATOR_CHAR); |
117 | 99 | break; |
118 | |
} |
119 | |
} |
120 | 825 | buf.append(context.getExternalContext().encodeNamespace( |
121 | |
(id != null) ? id : getUniqueId(context))); |
122 | 825 | String clientId = buf.toString(); |
123 | 825 | Renderer renderer = getRenderer(context); |
124 | 825 | if (renderer != null) { |
125 | 267 | clientId = renderer.convertClientId(context, clientId); |
126 | |
} |
127 | 825 | return clientId; |
128 | |
} |
129 | |
|
130 | |
private String getUniqueId(FacesContext context) { |
131 | 375 | if (uniqueId == null) { |
132 | 350 | uniqueId = context.getViewRoot().createUniqueId(); |
133 | |
} |
134 | 375 | return uniqueId; |
135 | |
} |
136 | |
|
137 | |
public String getId() { |
138 | 2431 | return id; |
139 | |
} |
140 | |
|
141 | |
public void setId(String id) { |
142 | 2006 | validateId(id); |
143 | 1830 | this.id = id; |
144 | 1830 | clientId = null; |
145 | 1830 | } |
146 | |
|
147 | |
public UIComponent getParent() { |
148 | 2476 | return parent; |
149 | |
} |
150 | |
|
151 | |
public void setParent(UIComponent parent) { |
152 | 1245 | this.parent = parent; |
153 | 1245 | } |
154 | |
|
155 | |
public boolean isRendered() { |
156 | 1301 | if (isRendered != null) { |
157 | 117 | return isRendered.booleanValue(); |
158 | |
} |
159 | 1184 | Boolean v = null; |
160 | 1184 | ValueBinding vb = getValueBinding(RENDERED); |
161 | 1184 | if (vb != null) { |
162 | 44 | v = ((Boolean) this.getValueFromBinding(vb)); |
163 | |
} |
164 | 1184 | if (v != null) { |
165 | 44 | return v.booleanValue(); |
166 | |
} else { |
167 | 1140 | return true; |
168 | |
} |
169 | |
} |
170 | |
|
171 | |
public void setRendered(boolean isRendered) { |
172 | 144 | this.isRendered = Boolean.valueOf(isRendered); |
173 | 144 | } |
174 | |
|
175 | |
public String getRendererType() { |
176 | 1187 | if (renderType != null) { |
177 | 897 | return renderType; |
178 | |
} |
179 | 290 | ValueBinding vb = getValueBinding(RENDERER_TYPE); |
180 | 290 | String result = null; |
181 | 290 | if (vb != null) { |
182 | 44 | result = (String) this.getValueFromBinding(vb); |
183 | |
} |
184 | 290 | return result; |
185 | |
} |
186 | |
|
187 | |
public void setRendererType(String renderType) { |
188 | 14300 | this.renderType = renderType; |
189 | 14300 | } |
190 | |
|
191 | |
private Object getValueFromBinding(ValueBinding vb) { |
192 | 88 | return vb.getValue(getFacesContext()); |
193 | |
} |
194 | |
|
195 | |
public boolean getRendersChildren() { |
196 | 252 | boolean result = false; |
197 | 252 | Renderer renderer = getRenderer(getFacesContext()); |
198 | 252 | if (getRendererType() != null && renderer != null) { |
199 | 140 | result = renderer.getRendersChildren(); |
200 | |
} |
201 | 252 | return result; |
202 | |
} |
203 | |
|
204 | |
public List getChildren() { |
205 | 3228 | if (childrenList == null) { |
206 | 1524 | childrenList = new ComponentChildrenListWrapper(this); |
207 | |
} |
208 | 3228 | return childrenList; |
209 | |
} |
210 | |
|
211 | |
public int getChildCount() { |
212 | 442 | return (childrenList != null) ? childrenList.size() : LIST_NULL_SIZE; |
213 | |
} |
214 | |
|
215 | |
public UIComponent findComponent(String expr) { |
216 | 707 | AssertionUtil.assertNotNull("expr", expr); |
217 | 663 | UIComponent base = this; |
218 | 663 | if (expr.charAt(0) == NamingContainer.SEPARATOR_CHAR) { |
219 | 44 | getComponentRoot(base); |
220 | 44 | expr = expr.substring(1); |
221 | |
} else { |
222 | 1077 | for (; base.getParent() != null; base = base.getParent()) { |
223 | 347 | if (base instanceof NamingContainer) { |
224 | 118 | break; |
225 | |
} |
226 | |
} |
227 | |
} |
228 | |
|
229 | 663 | UIComponent result = null; |
230 | 663 | while (expr.length() > 0) { |
231 | 663 | String id = null; |
232 | 663 | int separator = expr.indexOf(NamingContainer.SEPARATOR_CHAR); |
233 | 663 | if (separator >= 0) { |
234 | 252 | id = expr.substring(0, separator); |
235 | 252 | expr = expr.substring(separator + 1); |
236 | |
} else { |
237 | 411 | id = expr; |
238 | 411 | expr = null; |
239 | |
} |
240 | |
|
241 | 663 | result = findComponent(base, id); |
242 | 663 | if (result == null || expr == null) { |
243 | 353 | break; |
244 | |
} |
245 | 234 | if (result instanceof NamingContainer) { |
246 | 196 | result = result.findComponent(expr); |
247 | 158 | break; |
248 | |
} else { |
249 | 38 | throw new IllegalArgumentException(id); |
250 | |
} |
251 | |
} |
252 | 587 | return result; |
253 | |
} |
254 | |
|
255 | |
private UIComponent findComponent(UIComponent base, String id) { |
256 | 1000 | if (containsSameId(base, id)) { |
257 | 505 | return base; |
258 | |
} |
259 | |
|
260 | 495 | UIComponent child = null; |
261 | 495 | UIComponent result = null; |
262 | 495 | for (Iterator itr = base.getFacetsAndChildren(); itr.hasNext();) { |
263 | 463 | child = (UIComponent) itr.next(); |
264 | 463 | if (!(child instanceof NamingContainer)) { |
265 | 337 | result = findComponent(child, id); |
266 | 337 | if (result != null) { |
267 | 259 | break; |
268 | |
} |
269 | 126 | } else if (containsSameId(child, id)) { |
270 | 82 | result = child; |
271 | 82 | break; |
272 | |
} |
273 | |
} |
274 | 495 | return result; |
275 | |
} |
276 | |
|
277 | |
protected boolean containsSameId(UIComponent base, String id) { |
278 | 1126 | return id.equals(base.getId()); |
279 | |
} |
280 | |
|
281 | |
protected UIComponent getComponentRoot(UIComponent base) { |
282 | |
UIComponent parent; |
283 | 44 | for (parent = base; parent.getParent() != null; parent = parent |
284 | |
.getParent()) { |
285 | |
; |
286 | |
} |
287 | 44 | return parent; |
288 | |
} |
289 | |
|
290 | |
public Map getFacets() { |
291 | 734 | if (facetMap == null) { |
292 | 422 | facetMap = new ComponentFacetMapWrapper(this); |
293 | |
} |
294 | 734 | return facetMap; |
295 | |
} |
296 | |
|
297 | |
public UIComponent getFacet(String name) { |
298 | 270 | return (facetMap != null) ? (UIComponent) facetMap.get(name) : null; |
299 | |
} |
300 | |
|
301 | |
public Iterator getFacetsAndChildren() { |
302 | 1140 | return new ComponentFacetAndChildrenIterator(facetMap, childrenList); |
303 | |
} |
304 | |
|
305 | |
public void broadcast(FacesEvent event) throws AbortProcessingException { |
306 | 109 | AssertionUtil.assertNotNull("event", event); |
307 | 68 | if (listeners != null) { |
308 | 44 | for (Iterator itr = listeners.iterator(); itr.hasNext();) { |
309 | 88 | FacesListener listener = (FacesListener) itr.next(); |
310 | 88 | if (event.isAppropriateListener(listener)) { |
311 | 88 | event.processListener(listener); |
312 | |
} |
313 | |
} |
314 | |
} |
315 | 68 | } |
316 | |
|
317 | |
public void decode(FacesContext context) { |
318 | 56 | AssertionUtil.assertNotNull("context", context); |
319 | 12 | Renderer renderer = getRendererForEncodeOrDecode(context); |
320 | 12 | renderer.decode(context, this); |
321 | 12 | } |
322 | |
|
323 | |
public void encodeBegin(FacesContext context) throws IOException { |
324 | 209 | AssertionUtil.assertNotNull("context", context); |
325 | 168 | if (!isRendered()) { |
326 | 3 | return; |
327 | |
} |
328 | |
|
329 | 165 | Renderer renderer = getRendererForEncodeOrDecode(context); |
330 | 165 | renderer.encodeBegin(context, this); |
331 | 165 | } |
332 | |
|
333 | |
public void encodeChildren(FacesContext context) throws IOException { |
334 | 53 | AssertionUtil.assertNotNull("context", context); |
335 | 9 | if (!isRendered()) { |
336 | 1 | return; |
337 | |
} |
338 | 8 | Renderer renderer = getRendererForEncodeOrDecode(context); |
339 | 8 | renderer.encodeChildren(context, this); |
340 | 8 | } |
341 | |
|
342 | |
public void encodeEnd(FacesContext context) throws IOException { |
343 | 205 | AssertionUtil.assertNotNull("context", context); |
344 | 161 | if (!isRendered()) { |
345 | 3 | return; |
346 | |
} |
347 | 158 | Renderer renderer = getRendererForEncodeOrDecode(context); |
348 | 158 | renderer.encodeEnd(context, this); |
349 | 158 | } |
350 | |
|
351 | |
private Renderer getRendererForEncodeOrDecode(FacesContext context) { |
352 | 343 | Renderer renderer = getRenderer(context); |
353 | 343 | if (renderer == null) { |
354 | 54 | renderer = new NullRenderer(); |
355 | |
} |
356 | 343 | return renderer; |
357 | |
} |
358 | |
|
359 | |
protected void addFacesListener(FacesListener listener) { |
360 | 409 | AssertionUtil.assertNotNull("listener", listener); |
361 | 321 | if (listeners == null) { |
362 | 153 | listeners = new ArrayList(); |
363 | |
} |
364 | 321 | listeners.add(listener); |
365 | 321 | } |
366 | |
|
367 | |
protected FacesListener[] getFacesListeners(Class clazz) { |
368 | 384 | AssertionUtil.assertNotNull("class", clazz); |
369 | 341 | if (!FacesListener.class.isAssignableFrom(clazz)) { |
370 | 44 | throw new IllegalArgumentException(clazz.getName() |
371 | |
+ " is not FacesListener"); |
372 | |
} |
373 | |
|
374 | 296 | if (listeners == null) { |
375 | 18 | return (FacesListener[]) Array.newInstance(clazz, 0); |
376 | |
} |
377 | |
|
378 | 278 | List result = new ArrayList(); |
379 | 278 | FacesListener listener = null; |
380 | 278 | for (Iterator itr = listeners.iterator(); itr.hasNext();) { |
381 | 500 | listener = (FacesListener) itr.next(); |
382 | 500 | if (clazz.isAssignableFrom(listener.getClass())) { |
383 | 412 | result.add(listener); |
384 | |
} |
385 | |
} |
386 | |
|
387 | 278 | Object[] args = (Object[]) Array.newInstance(clazz, result.size()); |
388 | 278 | return (FacesListener[]) result.toArray(args); |
389 | |
} |
390 | |
|
391 | |
protected void removeFacesListener(FacesListener listener) { |
392 | 139 | AssertionUtil.assertNotNull("listener", listener); |
393 | |
|
394 | 80 | if (listeners != null) { |
395 | 80 | listeners.remove(listener); |
396 | |
} |
397 | 80 | } |
398 | |
|
399 | |
public void queueEvent(FacesEvent event) { |
400 | 140 | AssertionUtil.assertNotNull("event", event); |
401 | 100 | UIComponent parent = getParent(); |
402 | 100 | if (parent == null) { |
403 | 43 | throw new IllegalStateException("parent not found"); |
404 | |
} |
405 | 57 | parent.queueEvent(event); |
406 | 57 | } |
407 | |
|
408 | |
public void processDecodes(FacesContext context) { |
409 | 35 | AssertionUtil.assertNotNull("context", context); |
410 | 11 | if (!isRendered()) { |
411 | 1 | return; |
412 | |
} |
413 | 10 | UIComponent component = null; |
414 | 10 | for (Iterator itr = getFacetsAndChildren(); itr.hasNext();) { |
415 | 5 | component = (UIComponent) itr.next(); |
416 | 5 | component.processDecodes(context); |
417 | |
} |
418 | |
try { |
419 | 10 | decode(context); |
420 | 1 | } catch (RuntimeException e) { |
421 | 1 | context.renderResponse(); |
422 | 1 | throw e; |
423 | 9 | } |
424 | 9 | } |
425 | |
|
426 | |
public void processValidators(FacesContext context) { |
427 | 35 | AssertionUtil.assertNotNull("context", context); |
428 | 11 | if (!isRendered()) { |
429 | 1 | return; |
430 | |
} |
431 | 10 | UIComponent component = null; |
432 | 10 | for (Iterator itr = getFacetsAndChildren(); itr.hasNext();) { |
433 | 4 | component = (UIComponent) itr.next(); |
434 | 4 | component.processValidators(context); |
435 | |
} |
436 | 10 | } |
437 | |
|
438 | |
public void processUpdates(FacesContext context) { |
439 | 32 | AssertionUtil.assertNotNull("context", context); |
440 | 8 | if (!isRendered()) { |
441 | 1 | return; |
442 | |
} |
443 | 7 | UIComponent component = null; |
444 | 7 | for (Iterator itr = getFacetsAndChildren(); itr.hasNext();) { |
445 | 4 | component = (UIComponent) itr.next(); |
446 | 4 | component.processUpdates(context); |
447 | |
} |
448 | 7 | } |
449 | |
|
450 | |
public Object processSaveState(FacesContext context) { |
451 | 138 | AssertionUtil.assertNotNull("context", context); |
452 | |
|
453 | 94 | if (isTransient()) { |
454 | 44 | return null; |
455 | |
} |
456 | |
|
457 | 50 | Map facetMap = new HashMap(); |
458 | 50 | for (Iterator itr = getFacets().entrySet().iterator(); itr.hasNext();) { |
459 | 88 | Map.Entry entry = (Map.Entry) itr.next(); |
460 | 88 | String key = (String) entry.getKey(); |
461 | 88 | UIComponent component = (UIComponent) entry.getValue(); |
462 | 88 | if (!component.isTransient()) { |
463 | 88 | facetMap.put(key, component.processSaveState(context)); |
464 | |
} |
465 | |
} |
466 | |
|
467 | 50 | List children = new ArrayList(); |
468 | 50 | for (Iterator itr = getChildren().iterator(); itr.hasNext();) { |
469 | 89 | UIComponent component = (UIComponent) itr.next(); |
470 | 89 | if (!component.isTransient()) { |
471 | 89 | children.add(component.processSaveState(context)); |
472 | |
} |
473 | |
} |
474 | |
|
475 | 50 | return new SerializableStateHolder(saveState(context), facetMap, |
476 | |
children); |
477 | |
} |
478 | |
|
479 | |
public void processRestoreState(FacesContext context, Object state) { |
480 | 91 | AssertionUtil.assertNotNull("context", context); |
481 | 47 | if (!(state instanceof SerializableStateHolder)) { |
482 | 44 | throw new IllegalArgumentException(); |
483 | |
} |
484 | |
|
485 | 3 | SerializableStateHolder holder = (SerializableStateHolder) state; |
486 | |
|
487 | 3 | Object thisState = holder.getState(); |
488 | 3 | Map facetMap = holder.getFacetMap(); |
489 | 3 | List children = holder.getChildren(); |
490 | |
|
491 | 3 | for (Iterator itr = getFacets().entrySet().iterator(); itr.hasNext();) { |
492 | 2 | Map.Entry entry = (Map.Entry) itr.next(); |
493 | 2 | UIComponent component = (UIComponent) entry.getValue(); |
494 | 2 | if (!component.isTransient()) { |
495 | 2 | Object facetState = facetMap.get(entry.getKey()); |
496 | 2 | if (facetState != null) { |
497 | 2 | component.processRestoreState(context, facetState); |
498 | |
} |
499 | |
} |
500 | |
} |
501 | |
|
502 | 3 | int index = 0; |
503 | 3 | for (Iterator itr = getChildren().iterator(); itr.hasNext();) { |
504 | 2 | UIComponent component = (UIComponent) itr.next(); |
505 | 2 | if (!component.isTransient()) { |
506 | 2 | Object childrenState = children.get(index++); |
507 | 2 | if (childrenState != null) { |
508 | 2 | component.processRestoreState(context, childrenState); |
509 | |
} |
510 | |
} |
511 | |
} |
512 | |
|
513 | 3 | restoreState(context, thisState); |
514 | 3 | } |
515 | |
|
516 | |
protected FacesContext getFacesContext() { |
517 | 1347 | return FacesContext.getCurrentInstance(); |
518 | |
} |
519 | |
|
520 | |
protected Renderer getRenderer(FacesContext context) { |
521 | 716 | return UIComponentUtil.getRenderer(context, this); |
522 | |
} |
523 | |
|
524 | |
public boolean isTransient() { |
525 | 280 | return isTransient; |
526 | |
} |
527 | |
|
528 | |
public void setTransient(boolean transientFlag) { |
529 | 133 | isTransient = transientFlag; |
530 | 133 | } |
531 | |
|
532 | |
public Object saveState(FacesContext context) { |
533 | 180 | Object[] values = new Object[7]; |
534 | 180 | values[0] = id; |
535 | 180 | values[1] = isRendered; |
536 | 180 | values[2] = renderType; |
537 | 180 | values[3] = clientId; |
538 | 180 | values[4] = saveAttributesMap(); |
539 | 180 | values[5] = saveAttachedState(context, listeners); |
540 | 180 | values[6] = saveValueBindingMap(context); |
541 | |
|
542 | 180 | return (Object) values; |
543 | |
} |
544 | |
|
545 | |
public void restoreState(FacesContext context, Object state) { |
546 | 133 | Object[] values = (Object[]) state; |
547 | 133 | id = (String) values[0]; |
548 | 133 | isRendered = (Boolean) values[1]; |
549 | 133 | renderType = (String) values[2]; |
550 | 133 | clientId = (String) values[3]; |
551 | 133 | restoreAttributeMap(values[4]); |
552 | 133 | listeners = (List) restoreAttachedState(context, values[5]); |
553 | 133 | restoreValueBindingMap(context, values[6]); |
554 | 133 | } |
555 | |
|
556 | |
public static Object saveAttachedState(FacesContext context, |
557 | |
Object attachedObject) { |
558 | 620 | AssertionUtil.assertNotNull("context", context); |
559 | |
|
560 | 619 | if (attachedObject == null) { |
561 | 529 | return null; |
562 | |
} |
563 | |
|
564 | 90 | if (attachedObject instanceof List) { |
565 | 19 | List attachedList = (List) attachedObject; |
566 | 19 | List resultList = new ArrayList(attachedList.size()); |
567 | 19 | for (Iterator itr = attachedList.iterator(); itr.hasNext();) { |
568 | 35 | Object obj = itr.next(); |
569 | 35 | resultList.add(new AttachedObjectStateWrapper(context, obj)); |
570 | |
} |
571 | 19 | return resultList; |
572 | |
} else { |
573 | 71 | return new AttachedObjectStateWrapper(context, attachedObject); |
574 | |
} |
575 | |
} |
576 | |
|
577 | |
public static Object restoreAttachedState(FacesContext context, |
578 | |
Object stateObject) { |
579 | 546 | AssertionUtil.assertNotNull("context", context); |
580 | |
|
581 | 546 | if (stateObject == null) { |
582 | 411 | return null; |
583 | |
} |
584 | |
|
585 | 135 | if (stateObject instanceof List) { |
586 | 63 | List list = (List) stateObject; |
587 | 63 | List restoredList = new ArrayList(list.size()); |
588 | 63 | for (Iterator itr = list.iterator(); itr.hasNext();) { |
589 | 79 | AttachedObjectStateWrapper wrapper = (AttachedObjectStateWrapper) itr |
590 | |
.next(); |
591 | 79 | Object restoredObject = wrapper.restore(context); |
592 | 79 | if (restoredObject != null) { |
593 | 79 | restoredList.add(restoredObject); |
594 | |
} |
595 | |
} |
596 | 63 | return restoredList; |
597 | 72 | } else if (stateObject instanceof AttachedObjectStateWrapper) { |
598 | 71 | AttachedObjectStateWrapper wrapper = (AttachedObjectStateWrapper) stateObject; |
599 | 71 | return wrapper.restore(context); |
600 | |
} else { |
601 | 1 | throw new IllegalStateException("Unsupported:" + stateObject); |
602 | |
} |
603 | |
} |
604 | |
|
605 | |
private Object saveAttributesMap() { |
606 | 180 | return (attributesMap != null) ? attributesMap.getAttributesActual() |
607 | |
: null; |
608 | |
} |
609 | |
|
610 | |
private void restoreAttributeMap(Object state) { |
611 | 133 | if (state != null) { |
612 | 43 | attributesMap = new ComponentAttributesMap(this, (Map) state); |
613 | |
} else { |
614 | 90 | clearAttributeMap(); |
615 | |
} |
616 | 133 | } |
617 | |
|
618 | |
private Object saveValueBindingMap(FacesContext context) { |
619 | 180 | Map states = null; |
620 | 180 | if (bindingMap != null) { |
621 | 180 | states = new HashMap(); |
622 | 180 | for (Iterator itr = bindingMap.entrySet().iterator(); itr.hasNext();) { |
623 | 43 | Map.Entry entry = (Map.Entry) itr.next(); |
624 | 43 | states.put(entry.getKey(), saveAttachedState(context, entry |
625 | |
.getValue())); |
626 | |
} |
627 | |
} |
628 | 180 | return states; |
629 | |
} |
630 | |
|
631 | |
private void restoreValueBindingMap(FacesContext context, Object state) { |
632 | 133 | bindingMap = null; |
633 | 133 | if (state != null) { |
634 | 133 | Map stateMap = (Map) state; |
635 | 133 | bindingMap = new HashMap(); |
636 | 133 | for (Iterator itr = stateMap.entrySet().iterator(); itr.hasNext();) { |
637 | 43 | Map.Entry entry = (Map.Entry) itr.next(); |
638 | 43 | bindingMap.put(entry.getKey(), restoreAttachedState(context, |
639 | |
entry.getValue())); |
640 | |
} |
641 | |
} |
642 | 133 | } |
643 | |
|
644 | |
private void clearAttributeMap() { |
645 | 90 | attributesMap = null; |
646 | 90 | } |
647 | |
|
648 | |
private void validateId(String id) { |
649 | 2006 | if (id == null) { |
650 | 197 | return; |
651 | |
} |
652 | 1809 | if (id.length() < 1) { |
653 | 44 | throw new IllegalArgumentException("UIComponentBase"); |
654 | |
} |
655 | |
char ch; |
656 | 5431 | for (int i = 0; i < id.length(); i++) { |
657 | 3798 | ch = id.charAt(i); |
658 | 3798 | if (i == 0 && !Character.isLetter(ch) && ch != '_') { |
659 | 88 | throw new IllegalArgumentException( |
660 | |
"The first character is invalid(id = " + id + ")"); |
661 | 3710 | } else if (!Character.isDigit(ch) && !Character.isLetter(ch) |
662 | |
&& ch != '-' && ch != '_') { |
663 | 44 | throw new IllegalArgumentException( |
664 | |
"Subsequent character is invalid(id = " + id + ")"); |
665 | |
} |
666 | |
} |
667 | 1633 | } |
668 | |
|
669 | 8970 | private static class NullRenderer extends Renderer { |
670 | 54 | public NullRenderer() { |
671 | 54 | } |
672 | |
} |
673 | |
|
674 | |
} |