1 16 17 package org.apache.xerces.impl.xs.util; 18 19 import org.apache.xerces.util.SymbolHash; 20 import org.apache.xerces.xni.QName; 21 import org.apache.xerces.xs.*; 22 23 32 public class XSNamedMapImpl implements XSNamedMap { 33 34 37 public static final XSNamedMap EMPTY_MAP = new XSNamedMap () { 38 public int getLength() { 39 return 0; 40 } 41 public XSObject itemByName(String namespace, String localName) { 42 return null; 43 } 44 public XSObject item(int index) { 45 return null; 46 } 47 }; 48 49 String [] fNamespaces; 51 int fNSNum; 53 SymbolHash[] fMaps; 55 XSObject[] fArray = null; 58 int fLength = -1; 61 QName fName = new QName(); 63 64 70 public XSNamedMapImpl(String namespace, SymbolHash map) { 71 fNamespaces = new String [] {namespace}; 72 fMaps = new SymbolHash[] {map}; 73 fNSNum = 1; 74 } 75 76 83 public XSNamedMapImpl(String [] namespaces, SymbolHash[] maps, int num) { 84 fNamespaces = namespaces; 85 fMaps = maps; 86 fNSNum = num; 87 } 88 89 95 public XSNamedMapImpl(XSObject[] array, int length) { 96 if (length == 0) { 97 fNSNum = 0; 98 fLength = 0; 99 return; 100 } 101 fNamespaces = new String []{array[0].getNamespace()}; 104 fMaps = null; 105 fNSNum = 1; 106 fArray = array; 108 fLength = length; 109 } 110 111 116 public synchronized int getLength() { 117 if (fLength == -1) { 118 fLength = 0; 119 for (int i = 0; i < fNSNum; i++) 120 fLength += fMaps[i].getLength(); 121 } 122 return fLength; 123 } 124 125 135 public XSObject itemByName(String namespace, String localName) { 136 if (namespace != null) 137 namespace = namespace.intern(); 138 for (int i = 0; i < fNSNum; i++) { 139 if (namespace == fNamespaces[i]) { 140 if (fMaps != null) 143 return (XSObject)fMaps[i].get(localName); 144 XSObject ret; 147 for (int j = 0; j < fLength; j++) { 148 ret = fArray[j]; 149 if (ret.getName().equals(localName)) 150 return ret; 151 } 152 return null; 153 } 154 } 155 return null; 156 } 157 158 168 public synchronized XSObject item(int index) { 169 if (fArray == null) { 170 getLength(); 172 fArray = new XSObject[fLength]; 173 int pos = 0; 174 for (int i = 0; i < fNSNum; i++) { 176 pos += fMaps[i].getValues(fArray, pos); 177 } 178 } 179 if (index < 0 || index >= fLength) 180 return null; 181 return fArray[index]; 182 } 183 184 } | Popular Tags |