01: /* AttributesMap.java
02:
03: {{IS_NOTE
04: Purpose:
05:
06: Description:
07:
08: History:
09: Tue Dec 6 22:40:23 2005, Created by tomyeh
10: }}IS_NOTE
11:
12: Copyright (C) 2005 Potix Corporation. All Rights Reserved.
13:
14: {{IS_RIGHT
15: This program is distributed under GPL Version 2.0 in the hope that
16: it will be useful, but WITHOUT ANY WARRANTY.
17: }}IS_RIGHT
18: */
19: package org.zkoss.web.servlet.xel;
20:
21: import java.util.Set;
22: import java.util.AbstractSet;
23: import java.util.Map;
24: import java.util.Iterator;
25: import java.util.Enumeration;
26:
27: /**
28: * A sketetal implementation for Map to wrap something with enumeration of
29: * attributes, which must be String.
30: *
31: * <p>It is mainly used to implement sessionScope and requestScope in EL.
32: *
33: * @author tomyeh
34: * @since 3.0.0
35: */
36: public abstract class AttributesMap extends StringKeysMap {
37: private Set _entries;
38:
39: public Set entrySet() {
40: if (_entries == null) {
41: _entries = new AbstractSet() {
42: public int size() {
43: return AttributesMap.this .size();
44: }
45:
46: public boolean contains(Object o) {
47: return AttributesMap.this .containsKey(o);
48: }
49:
50: public boolean isEmpty() {
51: return AttributesMap.this .isEmpty();
52: }
53:
54: public Iterator iterator() {
55: return new EntryIter();
56: }
57: };
58: }
59: return _entries;
60: }
61:
62: public int size() {
63: int sz = 0;
64: for (Enumeration e = getKeys(); e.hasMoreElements(); ++sz)
65: e.nextElement();
66: return sz;
67: }
68:
69: public boolean isEmpty() {
70: return !getKeys().hasMoreElements();
71: }
72:
73: public Object put(Object key, Object val) {
74: final Object o = getValue((String) key);
75: setValue((String) key, val);
76: return o;
77: }
78:
79: public Object remove(Object key) {
80: final Object o = getValue((String) key);
81: removeValue((String) key);
82: return o;
83: }
84: }
|