01: /* InterpretResolver.java
02:
03: {{IS_NOTE
04: Purpose:
05:
06: Description:
07:
08: History:
09: Sat Sep 17 17:03:58 2005, 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.web.servlet.dsp.impl;
20:
21: import java.util.Map;
22: import java.util.HashMap;
23: import java.util.Collections;
24:
25: import org.zkoss.lang.D;
26: import org.zkoss.xel.VariableResolver;
27: import org.zkoss.xel.XelException;
28: import org.zkoss.web.servlet.dsp.*;
29: import org.zkoss.web.servlet.dsp.action.ActionContext;
30:
31: /**
32: * The resolver used to interpret an {@link Interpretation}.
33: *
34: * @author tomyeh
35: */
36: class InterpretResolver implements VariableResolver {
37: private final VariableResolver _parent;
38: private final Map _attrs = new HashMap();
39:
40: InterpretResolver(VariableResolver parent) {
41: assert D.OFF || !(parent instanceof InterpretResolver);
42: _parent = parent;
43: }
44:
45: /** Returns the attributes of the given scope. */
46: Map getAttributes(int scope) throws XelException {
47: if (scope == ActionContext.PAGE_SCOPE)
48: return _attrs;
49:
50: Map attrs = null;
51: if (_parent != null) {
52: switch (scope) {
53: case ActionContext.REQUEST_SCOPE:
54: attrs = (Map) _parent.resolveVariable("requestScope");
55: break;
56: case ActionContext.SESSION_SCOPE:
57: attrs = (Map) _parent.resolveVariable("sessionScope");
58: break;
59: case ActionContext.APPLICATION_SCOPE:
60: attrs = (Map) _parent
61: .resolveVariable("applicationScope");
62: break;
63: }
64: }
65: return attrs != null ? attrs : Collections.EMPTY_MAP;
66: }
67:
68: //-- VariableResolver --//
69: public Object resolveVariable(String name) throws XelException {
70: if ("pageScope".equals(name))
71: return _attrs;
72: final Object o = _attrs.get(name);
73: if (o != null)
74: return o;
75: return _parent != null ? _parent.resolveVariable(name) : null;
76: }
77: }
|