1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.commons.chain.web.servlet;
18
19
20 import java.util.ArrayList;
21 import java.util.Collection;
22 import java.util.Enumeration;
23 import java.util.HashSet;
24 import java.util.Iterator;
25 import java.util.List;
26 import java.util.Map;
27 import java.util.Set;
28 import javax.servlet.ServletContext;
29 import org.apache.commons.chain.web.MapEntry;
30
31
32
33
34
35
36
37
38
39
40 final class ServletInitParamMap implements Map {
41
42
43 public ServletInitParamMap(ServletContext context) {
44 this.context = context;
45 }
46
47
48 private ServletContext context = null;
49
50
51 public void clear() {
52 throw new UnsupportedOperationException();
53 }
54
55
56 public boolean containsKey(Object key) {
57 return (context.getInitParameter(key(key)) != null);
58 }
59
60
61 public boolean containsValue(Object value) {
62 Iterator values = values().iterator();
63 while (values.hasNext()) {
64 if (value.equals(values.next())) {
65 return (true);
66 }
67 }
68 return (false);
69 }
70
71
72 public Set entrySet() {
73 Set set = new HashSet();
74 Enumeration keys = context.getInitParameterNames();
75 String key;
76 while (keys.hasMoreElements()) {
77 key = (String) keys.nextElement();
78 set.add(new MapEntry(key, context.getInitParameter(key), false));
79 }
80 return (set);
81 }
82
83
84 public boolean equals(Object o) {
85 return (context.equals(o));
86 }
87
88
89 public Object get(Object key) {
90 return (context.getInitParameter(key(key)));
91 }
92
93
94 public int hashCode() {
95 return (context.hashCode());
96 }
97
98
99 public boolean isEmpty() {
100 return (size() < 1);
101 }
102
103
104 public Set keySet() {
105 Set set = new HashSet();
106 Enumeration keys = context.getInitParameterNames();
107 while (keys.hasMoreElements()) {
108 set.add(keys.nextElement());
109 }
110 return (set);
111 }
112
113
114 public Object put(Object key, Object value) {
115 throw new UnsupportedOperationException();
116 }
117
118
119 public void putAll(Map map) {
120 throw new UnsupportedOperationException();
121 }
122
123
124 public Object remove(Object key) {
125 throw new UnsupportedOperationException();
126 }
127
128
129 public int size() {
130 int n = 0;
131 Enumeration keys = context.getInitParameterNames();
132 while (keys.hasMoreElements()) {
133 keys.nextElement();
134 n++;
135 }
136 return (n);
137 }
138
139
140 public Collection values() {
141 List list = new ArrayList();
142 Enumeration keys = context.getInitParameterNames();
143 while (keys.hasMoreElements()) {
144 list.add(context.getInitParameter((String) keys.nextElement()));
145 }
146 return (list);
147 }
148
149
150 private String key(Object key) {
151 if (key == null) {
152 throw new IllegalArgumentException();
153 } else if (key instanceof String) {
154 return ((String) key);
155 } else {
156 return (key.toString());
157 }
158 }
159
160
161 }