01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */
17: package org.apache.cocoon.components.expression;
18:
19: import java.util.HashMap;
20: import java.util.Map;
21:
22: import org.apache.cocoon.xml.NamespacesTable;
23:
24: /**
25: * @version $Id: ExpressionContext.java 449189 2006-09-23 06:52:29Z crossley $
26: */
27: public class ExpressionContext extends HashMap {
28:
29: private ExpressionContext closure;
30: private Object contextBean;
31: private NamespacesTable namespaces;
32:
33: public ExpressionContext() {
34: this (null);
35: }
36:
37: public ExpressionContext(ExpressionContext closure) {
38: this .closure = closure;
39: if (closure == null) {
40: this .namespaces = new NamespacesTable();
41: } else {
42: // Reuse the parent one. Users of the context should correctly enter and leave namespace scopes.
43: this .namespaces = closure.namespaces;
44: }
45: }
46:
47: /**
48: * Get the namespace table that tracks the applicable namespace prefix mappings
49: * for the expression context.
50: *
51: * @return the namespaces table
52: */
53: public NamespacesTable getNamespaces() {
54: return this .namespaces;
55: }
56:
57: public Object getContextBean() {
58: if (contextBean != null)
59: return contextBean;
60: else if (closure != null)
61: return closure.getContextBean();
62: else
63: return null;
64: }
65:
66: public void setContextBean(Object contextBean) {
67: this .contextBean = contextBean;
68: }
69:
70: public Map getVars() {
71: return this ;
72: }
73:
74: public void setVars(Map map) {
75: clear();
76: putAll(map);
77: }
78:
79: public boolean containsKey(Object key) {
80: return this .get(key) != null;
81: }
82:
83: public Object get(Object key) {
84: if (key.equals("this")) {
85: return this ;
86: }
87: Object result = super.get(key);
88: if (result == null && closure != null) {
89: result = closure.get(key);
90: }
91: return result;
92: }
93: }
|