01: /* DelegatingVariableResolver.java
02:
03: {{IS_NOTE
04: Purpose:
05:
06: Description:
07:
08: History:
09: Aug 2 12:12:33 2007, Created by Dennis Chen
10: }}IS_NOTE
11:
12: Copyright (C) 2007 Potix Corporation. All Rights Reserved.
13:
14: {{IS_RIGHT
15: }}IS_RIGHT
16: */
17: package org.zkoss.zkplus.seasar;
18:
19: import org.seasar.framework.container.ComponentNotFoundRuntimeException;
20: import org.seasar.framework.container.S2Container;
21: import org.seasar.framework.container.factory.SingletonS2ContainerFactory;
22: import org.zkoss.xel.VariableResolver;
23:
24: /**
25: * DelegatingVariableResolver, a seasar2 bean variable resolver.
26: *
27: * <p>It defines a variable called <code>_container</code> to represent
28: * the instance of <code>org.seasar.framework.container.S2Container</code>.
29: * The _container is get from <code>SingletonS2ContainerFactory.getContainer()</code>.
30: *
31: * <p>Usage:<br/>
32: *
33: * in your zul file:<br/>
34: * <code><?variable-resolver class="org.zkoss.zkplus.seasar.DelegatingVariableResolver"?></code>
35: *
36: * @author Dennis.Chen
37: * @since 3.0.0
38: */
39: public class DelegatingVariableResolver implements VariableResolver {
40: protected S2Container _container;
41:
42: /**
43: * Get the seasar component by the specified name.
44: */
45: public Object resolveVariable(String name) {
46: if (_container == null) {
47: _container = SingletonS2ContainerFactory.getContainer();
48: }
49: if (_container != null) {
50: try {
51: return _container.getComponent(name);
52: } catch (ComponentNotFoundRuntimeException ex) {
53: //do nothing.
54: }
55: }
56: return null;
57: }
58: }
|