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.xscript;
18:
19: import java.util.HashMap;
20:
21: /**
22: * <code>XScriptVariableScope</code> maintains variables in a given
23: * scope. A variable has a unique name within a scope, but multiple
24: * variables with the same name can exist within different scopes.
25: *
26: * @author <a href="mailto:ovidiu@cup.hp.com">Ovidiu Predescu</a>
27: * @version CVS $Id: XScriptVariableScope.java 433543 2006-08-22 06:22:54Z crossley $
28: * @since August 4, 2001
29: */
30: public class XScriptVariableScope {
31: /**
32: * The variables store; each entry is <code>String</code>
33: * representing the name of the variable, with the corresponding
34: * value an {@link XScriptObject}.
35: */
36: HashMap variables = new HashMap();
37:
38: /**
39: * Define a new variable or overwrite the value of an existing
40: * variable in this scope.
41: *
42: * @param name a <code>String</code> value
43: * @param value a <code>{@link XScriptObject}</code> value
44: */
45: public synchronized void put(String name, XScriptObject value) {
46: variables.put(name, value);
47: }
48:
49: /**
50: * Obtains the value of the XScript <code>name</code> variable.
51: *
52: * @param name a <code>String</code> value
53: * @return a <code>{@link XScriptObject}</code> value
54: */
55: public synchronized XScriptObject get(String name) {
56: return (XScriptObject) variables.get(name);
57: }
58:
59: /**
60: * Removes the XScript variable that's accessible via
61: * <code>name</code>.
62: *
63: * @param name a <code>String</code> value
64: */
65: public synchronized XScriptObject remove(String name) {
66: return (XScriptObject) variables.remove(name);
67: }
68:
69: public synchronized boolean defines(String name) {
70: return variables.containsKey(name);
71: }
72: }
|