01: package com.icesoft.faces.context;
02:
03: import java.util.Enumeration;
04: import java.util.HashMap;
05: import java.util.Iterator;
06: import java.util.Map;
07: import java.util.Collections;
08:
09: public abstract class AbstractCopyingAttributeMap extends HashMap {
10:
11: public AbstractCopyingAttributeMap() {
12: Enumeration e = getAttributeNames();
13: while (e.hasMoreElements()) {
14: String key = String.valueOf(e.nextElement());
15: Object value = getAttribute(key);
16: super .put(key, value);
17: }
18: }
19:
20: public Object put(Object o, Object o1) {
21: setAttribute(String.valueOf(o), o1);
22: return super .put(o, o1);
23: }
24:
25: public void putAll(Map map) {
26: Iterator i = map.entrySet().iterator();
27: while (i.hasNext()) {
28: Map.Entry entry = (Map.Entry) i.next();
29: setAttribute(String.valueOf(entry.getKey()), entry
30: .getValue());
31: }
32: super .putAll(map);
33: }
34:
35: public Object remove(Object o) {
36: removeAttribute((String) o);
37: return super .remove(o);
38: }
39:
40: public void clear() {
41: //copy the enumeration to avoid concurrency problems
42: Iterator i = Collections.list(getAttributeNames()).iterator();
43: while (i.hasNext()) {
44: removeAttribute(String.valueOf(i.next()));
45: }
46: super .clear();
47: }
48:
49: public abstract Enumeration getAttributeNames();
50:
51: public abstract Object getAttribute(String name);
52:
53: public abstract void setAttribute(String name, Object value);
54:
55: public abstract void removeAttribute(String name);
56: }
|