1 57 58 package com.sun.org.apache.xerces.internal.impl.xs.util; 59 60 import com.sun.org.apache.xerces.internal.util.SymbolHash; 61 import com.sun.org.apache.xerces.internal.xni.QName; 62 import com.sun.org.apache.xerces.internal.xs.*; 63 64 71 public class XSNamedMapImpl implements XSNamedMap { 72 73 String [] fNamespaces; 75 int fNSNum; 77 SymbolHash[] fMaps; 79 XSObject[] fArray = null; 82 int fLength = -1; 85 QName fName = new QName(); 87 88 94 public XSNamedMapImpl(String namespace, SymbolHash map) { 95 fNamespaces = new String [] {namespace}; 96 fMaps = new SymbolHash[] {map}; 97 fNSNum = 1; 98 } 99 100 107 public XSNamedMapImpl(String [] namespaces, SymbolHash[] maps, int num) { 108 fNamespaces = namespaces; 109 fMaps = maps; 110 fNSNum = num; 111 } 112 113 119 public XSNamedMapImpl(XSObject[] array, int length) { 120 if (length == 0) { 121 fNSNum = 0; 122 fLength = 0; 123 return; 124 } 125 fNamespaces = new String []{array[0].getNamespace()}; 128 fMaps = null; 129 fNSNum = 1; 130 fArray = array; 132 fLength = length; 133 } 134 135 140 public synchronized int getLength() { 141 if (fLength == -1) { 142 fLength = 0; 143 for (int i = 0; i < fNSNum; i++) 144 fLength += fMaps[i].getLength(); 145 } 146 return fLength; 147 } 148 149 159 public XSObject itemByName(String namespace, String localName) { 160 if (namespace != null) 161 namespace = namespace.intern(); 162 for (int i = 0; i < fNSNum; i++) { 163 if (namespace == fNamespaces[i]) { 164 if (fMaps != null) 167 return (XSObject)fMaps[i].get(localName); 168 XSObject ret; 171 for (int j = 0; j < fLength; j++) { 172 ret = fArray[j]; 173 if (ret.getName().equals(localName)) 174 return ret; 175 } 176 return null; 177 } 178 } 179 return null; 180 } 181 182 192 public synchronized XSObject item(int index) { 193 if (fArray == null) { 194 getLength(); 196 fArray = new XSObject[fLength]; 197 int pos = 0; 198 for (int i = 0; i < fNSNum; i++) { 200 pos += fMaps[i].getValues(fArray, pos); 201 } 202 } 203 if (index < 0 || index >= fLength) 204 return null; 205 return fArray[index]; 206 } 207 208 } | Popular Tags |