01: /* MultiComposer.java
02:
03: {{IS_NOTE
04: Purpose:
05:
06: Description:
07:
08: History:
09: Nov 12, 2007 3:10:19 PM 2007, Created by IAN
10: }}IS_NOTE
11:
12: Copyright (C) 2007 Potix Corporation. All Rights Reserved.
13:
14: {{IS_RIGHT
15: This program is distributed under GPL Version 2.0 in the hope that
16: it will be useful, but WITHOUT ANY WARRANTY.
17: }}IS_RIGHT
18: */
19: package org.zkoss.jsf.zul.impl;
20:
21: import org.zkoss.lang.Classes;
22: import org.zkoss.zk.ui.Component;
23: import org.zkoss.zk.ui.Page;
24: import org.zkoss.zk.ui.metainfo.ComponentInfo;
25: import org.zkoss.zk.ui.util.Composer;
26: import org.zkoss.zk.ui.util.ComposerExt;
27:
28: /**
29: * @author IAN
30: */
31: /*package*/class MultiComposer implements Composer, ComposerExt {
32: private final Composer[] _cs;
33:
34: /*package*/MultiComposer(Object[] cs) throws Exception {
35: if (cs instanceof Composer[]) {
36: _cs = (Composer[]) cs;
37: } else {
38: _cs = new Composer[cs.length];
39: for (int j = cs.length; --j >= 0;) {
40: final Object o = cs[j];
41: _cs[j] = (Composer) (o instanceof String ? Classes
42: .newInstanceByThread(((String) o).trim())
43: : o instanceof Class ? ((Class) o)
44: .newInstance() : (Composer) o);
45: }
46: }
47: }
48:
49: public void doAfterCompose(Component comp) throws Exception {
50: for (int j = 0; j < _cs.length; ++j)
51: _cs[j].doAfterCompose(comp);
52: }
53:
54: public ComponentInfo doBeforeCompose(Page page, Component parent,
55: ComponentInfo compInfo) {
56: for (int j = 0; j < _cs.length; ++j)
57: if (_cs[j] instanceof ComposerExt) {
58: compInfo = ((ComposerExt) _cs[j]).doBeforeCompose(page,
59: parent, compInfo);
60: if (compInfo == null)
61: return null;
62: }
63: return compInfo;
64: }
65:
66: public void doBeforeComposeChildren(Component comp)
67: throws Exception {
68: for (int j = 0; j < _cs.length; ++j)
69: if (_cs[j] instanceof ComposerExt)
70: ((ComposerExt) _cs[j]).doBeforeComposeChildren(comp);
71: }
72:
73: public boolean doCatch(Throwable ex) throws Exception {
74: for (int j = 0; j < _cs.length; ++j)
75: if (_cs[j] instanceof ComposerExt)
76: if (((ComposerExt) _cs[j]).doCatch(ex))
77: return true; //caught (eat it)
78: return false;
79: }
80:
81: public void doFinally() throws Exception {
82: for (int j = 0; j < _cs.length; ++j)
83: if (_cs[j] instanceof ComposerExt)
84: ((ComposerExt) _cs[j]).doFinally();
85: }
86: }
|