1 17 package org.alfresco.web.bean.repository; 18 19 import java.util.Collection ; 20 import java.util.HashMap ; 21 import java.util.Map ; 22 import java.util.Set ; 23 24 import org.apache.commons.logging.Log; 25 import org.apache.commons.logging.LogFactory; 26 27 33 public final class QNameMap<K,V> implements Map 34 { 35 private Log logger = LogFactory.getLog(QNameMap.class); 36 private Map <String , Object > contents = new HashMap <String , Object >(7, 1.0f); 37 private Node parent; 38 private Map <String , NodePropertyResolver> resolvers = new HashMap <String , NodePropertyResolver>(7, 1.0f); 39 40 45 public QNameMap(Node parent) 46 { 47 if (parent == null) 48 { 49 throw new IllegalArgumentException ("Parent Node cannot be null!"); 50 } 51 this.parent = parent; 52 } 53 54 60 public void addPropertyResolver(String name, NodePropertyResolver resolver) 61 { 62 this.resolvers.put(name, resolver); 63 } 64 65 68 public int size() 69 { 70 return this.contents.size(); 71 } 72 73 76 public boolean isEmpty() 77 { 78 return this.contents.isEmpty(); 79 } 80 81 84 public boolean containsKey(Object key) 85 { 86 return this.contents.containsKey(Repository.resolveToQNameString((String )key)); 87 } 88 89 92 public boolean containsValue(Object value) 93 { 94 return this.contents.containsValue(value); 95 } 96 97 100 public Object get(Object key) 101 { 102 String qnameKey = Repository.resolveToQNameString((String )key); 103 Object obj = this.contents.get(qnameKey); 104 if (obj == null) 105 { 106 NodePropertyResolver resolver = this.resolvers.get((String )key); 108 if (resolver != null) 109 { 110 obj = resolver.get(this.parent); 111 this.contents.put(qnameKey, obj); 114 } 115 } 116 117 return obj; 118 } 119 120 126 public Object getRaw(Object key) 127 { 128 return this.contents.get(Repository.resolveToQNameString((String )key)); 129 } 130 131 134 public Object put(Object key, Object value) 135 { 136 return this.contents.put(Repository.resolveToQNameString((String )key), value); 137 } 138 139 142 public Object remove(Object key) 143 { 144 return this.contents.remove(Repository.resolveToQNameString((String )key)); 145 } 146 147 150 public void putAll(Map t) 151 { 152 for (Object key : t.keySet()) 153 { 154 this.put(key, t.get(key)); 155 } 156 } 157 158 161 public void clear() 162 { 163 this.contents.clear(); 164 } 165 166 169 public Set keySet() 170 { 171 return this.contents.keySet(); 172 } 173 174 177 public Collection values() 178 { 179 return this.contents.values(); 180 } 181 182 185 public Set entrySet() 186 { 187 return this.contents.entrySet(); 188 } 189 190 193 public String toString() 194 { 195 return this.contents.toString(); 196 } 197 } 198 | Popular Tags |