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