1 28 29 package com.caucho.loader; 30 31 import java.util.Collection ; 32 import java.util.HashMap ; 33 import java.util.Map ; 34 import java.util.Set ; 35 36 39 public class EnvironmentMap extends HashMap { 40 private EnvironmentLocal<HashMap > _envMap = new EnvironmentLocal<HashMap >(); 41 42 private HashMap _global; 43 44 47 public EnvironmentMap(HashMap global) 48 { 49 _global = global; 50 } 51 52 public EnvironmentMap() 53 { 54 this(new HashMap ()); 55 } 56 57 public HashMap getGlobal() 58 { 59 return _global; 60 } 61 62 public HashMap setGlobal(HashMap global) 63 { 64 HashMap old = _global; 65 66 _global = global; 67 68 return old; 69 } 70 71 public int size() 72 { 73 return getEnvironmentMap().size(); 74 } 75 76 public boolean isEmpty() 77 { 78 return getEnvironmentMap().isEmpty(); 79 } 80 81 public boolean containsValue(Object value) 82 { 83 return getEnvironmentMap().containsValue(value); 84 } 85 86 public boolean containsKey(Object value) 87 { 88 return getEnvironmentMap().containsKey(value); 89 } 90 91 public Object get(Object key) 92 { 93 Map map = getEnvironmentMap(); 94 95 Object value = map.get(key); 96 97 if (value != null) 98 return value; 99 else 100 return _global.get(key); 101 } 102 103 public Object put(Object key, Object value) 104 { 105 return getPutEnvironmentMap().put(key, value); 106 } 107 108 public Object remove(Object key) 109 { 110 return getPutEnvironmentMap().remove(key); 111 } 112 113 public void putAll(Map map) 114 { 115 getPutEnvironmentMap().putAll(map); 116 } 117 118 public void clear() 119 { 120 getPutEnvironmentMap().clear(); 121 } 122 123 public Object clone() 124 { 125 return getEnvironmentMap().clone(); 126 } 127 128 public String toString() 129 { 130 return getEnvironmentMap().toString(); 131 } 132 133 public Set keySet() 134 { 135 return getPutEnvironmentMap().keySet(); 136 } 137 138 public Set entrySet() 139 { 140 return getPutEnvironmentMap().entrySet(); 141 } 142 143 public Collection values() 144 { 145 return getPutEnvironmentMap().values(); 146 } 147 148 public boolean equals(Object o) 149 { 150 return getEnvironmentMap().equals(o); 151 } 152 153 public int hashCode() 154 { 155 return getEnvironmentMap().hashCode(); 156 } 157 158 private HashMap getEnvironmentMap() 159 { 160 HashMap map = _envMap.get(); 161 162 if (map != null) 163 return map; 164 else 165 return _global; 166 } 167 168 private synchronized HashMap getPutEnvironmentMap() 169 { 170 HashMap map = _envMap.getLevel(); 171 172 if (map == null) { 173 map = new HashMap (); 174 HashMap parentMap = _envMap.get(); 175 if (parentMap == null) 176 parentMap = _global; 177 178 map.putAll(parentMap); 179 180 _envMap.set(map); 181 182 return map; 183 } 184 else 185 return map; 186 } 187 } 188 | Popular Tags |