KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > cocoon > components > xscript > XScriptVariableScope


1 /*
2  * Copyright 1999-2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 package org.apache.cocoon.components.xscript;
17
18 import java.util.HashMap JavaDoc;
19
20 /**
21  * <code>XScriptVariableScope</code> maintains variables in a given
22  * scope. A variable has a unique name within a scope, but multiple
23  * variables with the same name can exist within different scopes.
24  *
25  * @author <a HREF="mailto:ovidiu@cup.hp.com">Ovidiu Predescu</a>
26  * @version CVS $Id: XScriptVariableScope.java 30932 2004-07-29 17:35:38Z vgritsenko $
27  * @since August 4, 2001
28  */

29 public class XScriptVariableScope {
30     /**
31      * The variables store; each entry is <code>String</code>
32      * representing the name of the variable, with the corresponding
33      * value an {@link XScriptObject}.
34      */

35     HashMap JavaDoc variables = new HashMap JavaDoc();
36
37     /**
38      * Define a new variable or overwrite the value of an existing
39      * variable in this scope.
40      *
41      * @param name a <code>String</code> value
42      * @param value a <code>{@link XScriptObject}</code> value
43      */

44     public synchronized void put(String JavaDoc name, XScriptObject value) {
45         variables.put(name, value);
46     }
47
48     /**
49      * Obtains the value of the XScript <code>name</code> variable.
50      *
51      * @param name a <code>String</code> value
52      * @return a <code>{@link XScriptObject}</code> value
53      */

54     public synchronized XScriptObject get(String JavaDoc name) {
55         return (XScriptObject) variables.get(name);
56     }
57
58     /**
59      * Removes the XScript variable that's accessible via
60      * <code>name</code>.
61      *
62      * @param name a <code>String</code> value
63      */

64     public synchronized XScriptObject remove(String JavaDoc name) {
65         return (XScriptObject) variables.remove(name);
66     }
67
68     public synchronized boolean defines(String JavaDoc name) {
69         return variables.containsKey(name);
70     }
71 }
72
Popular Tags