KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > edu > neu > ccs > jmk > Global


1 // $Id: Global.java,v 1.2 2001/12/07 11:41:24 ramsdell Exp $
2

3 // Globals
4

5 /*
6  * Copyright 1999 by John D. Ramsdell
7  *
8  * This program is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Lesser General Public License
10  * as published by the Free Software Foundation; either version 2
11  * of the License, or (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU Lesser General Public License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public License
19  * along with this program; if not, write to the Free Software
20  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21  */

22
23 package edu.neu.ccs.jmk;
24
25 /**
26  * Global cells which are used to bind values to identifiers.
27  * As an expression, a global is a reference of a global identifier.
28  * @version May 1999
29  * @author John D. Ramsdell
30  */

31 final class Global
32 extends Expression
33 {
34   private /* final */ String JavaDoc identifier;
35   private Value value = null;
36
37   Global (String JavaDoc identifier) {
38     this.identifier = identifier;
39   }
40
41   String JavaDoc getIdentifier() {
42     return identifier;
43   }
44
45   Value eval(Environment env, StringList list)
46        throws StringListCastException
47   {
48     if (list == null)
49       return value;
50     else if (StringList.isStringList(value))
51       return StringList.append((StringList)value, list);
52     else {
53       String JavaDoc msg = "Append error: the value in " + identifier +
54     " is not a string list";
55       throw new StringListCastException(msg);
56     }
57   }
58
59   void setValue(Value value) {
60     this.value = value;
61   }
62 }
63
Popular Tags