1 16 package org.directwebremoting.impl; 17 18 import java.util.AbstractMap ; 19 import java.util.Collection ; 20 import java.util.HashMap ; 21 import java.util.Iterator ; 22 import java.util.Map ; 23 import java.util.Set ; 24 25 import org.directwebremoting.Container; 26 27 31 public class ContainerMap extends AbstractMap implements Map 32 { 33 38 public ContainerMap(Container container, boolean filterNonStringValues) 39 { 40 this.container = container; 41 this.filterNonStringValues = filterNonStringValues; 42 } 43 44 47 private void init() 48 { 49 if (proxy == null) 50 { 51 proxy = new HashMap (); 52 for (Iterator it = container.getBeanNames().iterator(); it.hasNext();) 53 { 54 String name = (String ) it.next(); 55 Object value = container.getBean(name); 56 57 if (!filterNonStringValues || value instanceof String ) 58 { 59 proxy.put(name, value); 60 } 61 } 62 } 63 } 64 65 68 public Object get(Object key) 69 { 70 init(); 71 return proxy.get(key); 72 } 73 74 77 public Set entrySet() 78 { 79 init(); 80 return proxy.entrySet(); 81 } 82 83 86 public boolean containsKey(Object key) 87 { 88 init(); 89 return proxy.containsKey(key); 90 } 91 92 95 public boolean containsValue(Object value) 96 { 97 init(); 98 return proxy.containsValue(value); 99 } 100 101 104 public boolean equals(Object o) 105 { 106 init(); 107 return proxy.equals(o); 108 } 109 110 113 public int hashCode() 114 { 115 init(); 116 return proxy.hashCode(); 117 } 118 119 122 public boolean isEmpty() 123 { 124 init(); 125 return proxy.isEmpty(); 126 } 127 128 131 public Set keySet() 132 { 133 init(); 134 return proxy.keySet(); 135 } 136 137 140 public int size() 141 { 142 init(); 143 return proxy.size(); 144 } 145 146 149 public Collection values() 150 { 151 init(); 152 return proxy.values(); 153 } 154 155 158 public String toString() 159 { 160 init(); 161 return proxy.toString(); 162 } 163 164 167 public Object put(Object key, Object value) 168 { 169 throw new UnsupportedOperationException ("ContainerMaps are read only"); 170 } 171 172 175 public void putAll(Map t) 176 { 177 throw new UnsupportedOperationException ("ContainerMaps are read only"); 178 } 179 180 183 public Object remove(Object key) 184 { 185 throw new UnsupportedOperationException ("ContainerMaps are read only"); 186 } 187 188 191 public void clear() 192 { 193 throw new UnsupportedOperationException ("ContainerMaps are read only"); 194 } 195 196 199 private boolean filterNonStringValues; 200 201 204 private Container container; 205 206 209 protected Map proxy; 210 } 211 | Popular Tags |