01: /*
02: * MapPackage.java
03: *
04: * Copyright (c) 2006 Sun Microsystems, Inc. All Rights Reserved.
05: *
06: * See the file "LICENSE.txt" for information on usage and redistribution
07: * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
08: */
09: package org.pnuts.lang;
10:
11: import pnuts.lang.Package;
12: import pnuts.lang.Context;
13: import pnuts.lang.NamedValue;
14: import java.util.*;
15:
16: public class MapPackage extends Package {
17:
18: private Map/*<String,Object>*/map;
19:
20: /*
21: * Constructor
22: *
23: * @param map the map
24: */
25: public MapPackage(Map/*<String,Object>*/map) {
26: super (null, null);
27: this .map = map;
28: }
29:
30: public Object get(String symbol) {
31: return map.get(symbol);
32: }
33:
34: public Object get(String symbol, Context context) {
35: return map.get(symbol);
36: }
37:
38: public void set(String symbol, Object value) {
39: map.put(symbol, value);
40: }
41:
42: public boolean defined(String name, Context context) {
43: return map.containsKey(name);
44: }
45:
46: public Enumeration keys() {
47: return Collections.enumeration(map.keySet());
48: }
49:
50: public Enumeration values() {
51: return Collections.enumeration(map.values());
52: }
53:
54: public int size() {
55: return map.size();
56: }
57:
58: public NamedValue lookup(final String symbol) {
59: if (map.containsKey(symbol)) {
60: final Object value = map.get(symbol);
61: return new NamedValue() {
62: public String getName() {
63: return symbol;
64: }
65:
66: public Object get() {
67: return value;
68: }
69:
70: public void set(Object value) {
71: map.put(symbol, value);
72: }
73: };
74: } else {
75: return null;
76: }
77: }
78:
79: public NamedValue lookup(final String symbol, Context context) {
80: return lookup(symbol);
81: }
82: }
|