01: /* SimpleResolver.java
02:
03: {{IS_NOTE
04: Purpose:
05:
06: Description:
07:
08: History:
09: Thu Oct 28 15:15:04 2004, Created by tomyeh
10: }}IS_NOTE
11:
12: Copyright (C) 2004 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.xel.util;
20:
21: import java.util.Map;
22:
23: import org.zkoss.xel.VariableResolver;
24: import org.zkoss.xel.XelException;
25:
26: /**
27: * A simple resolver that retrieve variable from a map.
28: *
29: * @author tomyeh
30: * @since 3.0.0
31: */
32: public class SimpleResolver implements VariableResolver {
33: /** The parent resolver. */
34: private VariableResolver _parent;
35: /** The variable maps. */
36: protected Map _vars;
37:
38: /** Constructs a resolver. */
39: public SimpleResolver() {
40: this (null, null);
41: }
42:
43: /** Constructs a resolver with a parent.
44: * @param parent the parent resolver (null means ignored).
45: */
46: public SimpleResolver(VariableResolver parent) {
47: this (parent, null);
48: }
49:
50: /** Constructs a resolver with a parent and an object map.
51: * @param parent the parent resolver (null means ignored).
52: * @param vars the object map (null means ignored)
53: */
54: public SimpleResolver(VariableResolver parent, Map vars) {
55: _parent = parent;
56: _vars = vars;
57: }
58:
59: /** Constructs a resolver with an object map.
60: * @param vars the object map (null means ignored)
61: */
62: public SimpleResolver(Map vars) {
63: this (null, vars);
64: }
65:
66: /** Returns the parent, or null if no parent at all.
67: */
68: public VariableResolver getParent() {
69: return _parent;
70: }
71:
72: /** Sets the parent.
73: *
74: * @param parent the parent resolver, or null if no parent.
75: */
76: public void setParent(VariableResolver parent) {
77: _parent = parent;
78: }
79:
80: //-- VariableResolver --//
81: public Object resolveVariable(String name) throws XelException {
82: if (_vars != null) {
83: final Object o = _vars.get(name);
84: if (o != null)
85: return o;
86: }
87: return _parent != null ? _parent.resolveVariable(name) : null;
88: }
89: }
|