KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > ejen > EjenContextsStack


1 //
2
// Ejen (code generation system)
3
// Copyright (C) 2001, 2002 François Wolff (ejen@noos.fr).
4
//
5
// This file is part of Ejen.
6
//
7
// Ejen is free software; you can redistribute it and/or modify
8
// it under the terms of the GNU General Public License as published by
9
// the Free Software Foundation; either version 2 of the License, or
10
// (at your option) any later version.
11
//
12
// Ejen is distributed in the hope that it will be useful,
13
// but WITHOUT ANY WARRANTY; without even the implied warranty of
14
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
// GNU General Public License for more details.
16
//
17
// You should have received a copy of the GNU General Public License
18
// along with Ejen; if not, write to the Free Software
19
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20
//
21
package org.ejen;
22
23 import java.util.Stack JavaDoc;
24 import java.util.Hashtable JavaDoc;
25
26 /**
27  * Ejen context stack class. Defines a global context (an Hashtable)
28  * and a stack of local contexts.
29  * @author F. Wolff
30  * @version 1.0
31  */

32 public class EjenContextsStack extends Stack JavaDoc {
33     private Hashtable JavaDoc _globalContext = new Hashtable JavaDoc();
34
35     /**
36      * Looks at the EjenContext at the top of this EjenContextsStack without
37      * removing it from the stack.
38      * @return the EjenContext at the top of this EjenContextsStack.
39      * @throws java.util.EmptyStackException if this EjenContextsStack is empty.
40      */

41     public EjenContext peekContext() {
42         return (EjenContext) peek();
43     }
44
45     /**
46      * Returns the EjenContext at the specified position in this EjenContextsStack.
47      * @param index index of EjenContext to return.
48      * @return the EjenContext at the top of this EjenContextsStack.
49      * @throws java.lang.ArrayIndexOutOfBoundsException index is out of range
50      * (index < 0 || index >= size()).
51      */

52     public EjenContext peekContext(int index) {
53         return (EjenContext) elementAt(index);
54     }
55
56     /**
57      * Removes the EjenContext at the top of this EjenContextsStack and returns
58      * that EjenContext as the value of this function.
59      * @return the EjenContext at the top of this EjenContextsStack.
60      * @throws java.util.EmptyStackException if this EjenContextsStack is empty.
61      */

62     public EjenContext popContext() {
63         return (EjenContext) pop();
64     }
65
66     /**
67      * Pushes an EjenContext onto the top of this EjenContextsStack.
68      * @param ctx the EjenContext to be pushed onto this EjenContextsStack.
69      * @return the ctx argument.
70      */

71     public EjenContext pushContext(EjenContext ctx) {
72         return (EjenContext) (super.push(ctx));
73     }
74
75     /**
76      * Returns the value to which the specified name is mapped in the
77      * global context of this EjenContextsStack.
78      * @param name a name (key) in the global context (which is an Hashtable).
79      * @return the value to which the name is mapped in this global context; null
80      * if the name is not mapped to any value in this global context.
81      */

82     public Object JavaDoc globalGet(String JavaDoc name) {
83         return _globalContext.get(name);
84     }
85
86     /**
87      * Maps the specified name to the specified value in the global context of this
88      * EjenContextsStack. Neither the name nor the value can be null.
89      * @param name a name (key) in the global context.
90      * @param value the value.
91      * @return the previous value of the specified name in this global context, or
92      * null if it did not have one.
93      */

94     public Object JavaDoc globalPut(String JavaDoc name, Object JavaDoc value) {
95         return _globalContext.put(name, value);
96     }
97 }
98
Popular Tags