1 17 package org.alfresco.service.namespace; 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.alfresco.service.ServiceRegistry; 25 import org.alfresco.util.ApplicationContextHelper; 26 import org.apache.commons.logging.Log; 27 import org.apache.commons.logging.LogFactory; 28 29 35 public class QNameMap<K,V> implements Map , Cloneable 36 { 37 protected static Log logger = LogFactory.getLog(QNameMap.class); 38 protected Map <String , Object > contents = new HashMap <String , Object >(11, 1.0f); 39 protected NamespacePrefixResolver resolver = null; 40 41 46 public QNameMap(NamespacePrefixResolver resolver) 47 { 48 if (resolver == null) 49 { 50 throw new IllegalArgumentException ("NamespacePrefixResolver is mandatory."); 51 } 52 this.resolver = resolver; 53 } 54 55 58 public final int size() 59 { 60 return this.contents.size(); 61 } 62 63 66 public boolean isEmpty() 67 { 68 return this.contents.isEmpty(); 69 } 70 71 74 public boolean containsKey(Object key) 75 { 76 return (this.contents.containsKey(QName.resolveToQNameString(resolver, key.toString()))); 77 } 78 79 82 public boolean containsValue(Object value) 83 { 84 return this.contents.containsValue(value); 85 } 86 87 90 public Object get(Object key) 91 { 92 String qnameKey = QName.resolveToQNameString(resolver, key.toString()); 93 Object obj = this.contents.get(qnameKey); 94 95 return obj; 96 } 97 98 101 public Object put(Object key, Object value) 102 { 103 return this.contents.put(QName.resolveToQNameString(resolver, key.toString()), value); 104 } 105 106 109 public Object remove(Object key) 110 { 111 return this.contents.remove(QName.resolveToQNameString(resolver, key.toString())); 112 } 113 114 117 public void putAll(Map t) 118 { 119 for (Object key : t.keySet()) 120 { 121 this.put(key, t.get(key)); 122 } 123 } 124 125 128 public void clear() 129 { 130 this.contents.clear(); 131 } 132 133 136 public Set keySet() 137 { 138 return this.contents.keySet(); 139 } 140 141 144 public Collection values() 145 { 146 return this.contents.values(); 147 } 148 149 152 public Set entrySet() 153 { 154 return this.contents.entrySet(); 155 } 156 157 160 public String toString() 161 { 162 return this.contents.toString(); 163 } 164 165 168 public Object clone() 169 { 170 QNameMap map = new QNameMap(resolver); 171 map.putAll(this); 172 173 return map; 174 } 175 } 176 | Popular Tags |