Tue, 06 Mar 2012 16:09:35 -0800
7150322: Stop using drop source bundles in jaxws
Reviewed-by: darcy, ohrstrom
aoqi@0 | 1 | /* |
aoqi@0 | 2 | * Copyright (c) 2004, 2011, Oracle and/or its affiliates. All rights reserved. |
aoqi@0 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
aoqi@0 | 4 | * |
aoqi@0 | 5 | * This code is free software; you can redistribute it and/or modify it |
aoqi@0 | 6 | * under the terms of the GNU General Public License version 2 only, as |
aoqi@0 | 7 | * published by the Free Software Foundation. Oracle designates this |
aoqi@0 | 8 | * particular file as subject to the "Classpath" exception as provided |
aoqi@0 | 9 | * by Oracle in the LICENSE file that accompanied this code. |
aoqi@0 | 10 | * |
aoqi@0 | 11 | * This code is distributed in the hope that it will be useful, but WITHOUT |
aoqi@0 | 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
aoqi@0 | 13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
aoqi@0 | 14 | * version 2 for more details (a copy is included in the LICENSE file that |
aoqi@0 | 15 | * accompanied this code). |
aoqi@0 | 16 | * |
aoqi@0 | 17 | * You should have received a copy of the GNU General Public License version |
aoqi@0 | 18 | * 2 along with this work; if not, write to the Free Software Foundation, |
aoqi@0 | 19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
aoqi@0 | 20 | * |
aoqi@0 | 21 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
aoqi@0 | 22 | * or visit www.oracle.com if you need additional information or have any |
aoqi@0 | 23 | * questions. |
aoqi@0 | 24 | * |
aoqi@0 | 25 | * THIS FILE WAS MODIFIED BY SUN MICROSYSTEMS, INC. |
aoqi@0 | 26 | */ |
aoqi@0 | 27 | |
aoqi@0 | 28 | package com.sun.xml.internal.fastinfoset.util; |
aoqi@0 | 29 | |
aoqi@0 | 30 | import com.sun.xml.internal.fastinfoset.EncodingConstants; |
aoqi@0 | 31 | import com.sun.xml.internal.fastinfoset.CommonResourceBundle; |
aoqi@0 | 32 | import java.util.Iterator; |
aoqi@0 | 33 | import java.util.NoSuchElementException; |
aoqi@0 | 34 | import com.sun.xml.internal.org.jvnet.fastinfoset.FastInfosetException; |
aoqi@0 | 35 | |
aoqi@0 | 36 | public class PrefixArray extends ValueArray { |
aoqi@0 | 37 | public static final int PREFIX_MAP_SIZE = 64; |
aoqi@0 | 38 | |
aoqi@0 | 39 | private int _initialCapacity; |
aoqi@0 | 40 | |
aoqi@0 | 41 | public String[] _array; |
aoqi@0 | 42 | |
aoqi@0 | 43 | private PrefixArray _readOnlyArray; |
aoqi@0 | 44 | |
aoqi@0 | 45 | private static class PrefixEntry { |
aoqi@0 | 46 | private PrefixEntry next; |
aoqi@0 | 47 | private int prefixId; |
aoqi@0 | 48 | } |
aoqi@0 | 49 | |
aoqi@0 | 50 | private PrefixEntry[] _prefixMap = new PrefixEntry[PREFIX_MAP_SIZE]; |
aoqi@0 | 51 | |
aoqi@0 | 52 | private PrefixEntry _prefixPool; |
aoqi@0 | 53 | |
aoqi@0 | 54 | private static class NamespaceEntry { |
aoqi@0 | 55 | private NamespaceEntry next; |
aoqi@0 | 56 | private int declarationId; |
aoqi@0 | 57 | private int namespaceIndex; |
aoqi@0 | 58 | |
aoqi@0 | 59 | private String prefix; |
aoqi@0 | 60 | private String namespaceName; |
aoqi@0 | 61 | private int prefixEntryIndex; |
aoqi@0 | 62 | } |
aoqi@0 | 63 | |
aoqi@0 | 64 | private NamespaceEntry _namespacePool; |
aoqi@0 | 65 | |
aoqi@0 | 66 | private NamespaceEntry[] _inScopeNamespaces; |
aoqi@0 | 67 | |
aoqi@0 | 68 | public int[] _currentInScope; |
aoqi@0 | 69 | |
aoqi@0 | 70 | public int _declarationId; |
aoqi@0 | 71 | |
aoqi@0 | 72 | public PrefixArray(int initialCapacity, int maximumCapacity) { |
aoqi@0 | 73 | _initialCapacity = initialCapacity; |
aoqi@0 | 74 | _maximumCapacity = maximumCapacity; |
aoqi@0 | 75 | |
aoqi@0 | 76 | _array = new String[initialCapacity]; |
aoqi@0 | 77 | // Sizes of _inScopeNamespaces and _currentInScope need to be two |
aoqi@0 | 78 | // greater than _array because 0 represents the empty string and |
aoqi@0 | 79 | // 1 represents the xml prefix |
aoqi@0 | 80 | _inScopeNamespaces = new NamespaceEntry[initialCapacity + 2]; |
aoqi@0 | 81 | _currentInScope = new int[initialCapacity + 2]; |
aoqi@0 | 82 | |
aoqi@0 | 83 | increaseNamespacePool(initialCapacity); |
aoqi@0 | 84 | increasePrefixPool(initialCapacity); |
aoqi@0 | 85 | |
aoqi@0 | 86 | initializeEntries(); |
aoqi@0 | 87 | } |
aoqi@0 | 88 | |
aoqi@0 | 89 | public PrefixArray() { |
aoqi@0 | 90 | this(DEFAULT_CAPACITY, MAXIMUM_CAPACITY); |
aoqi@0 | 91 | } |
aoqi@0 | 92 | |
aoqi@0 | 93 | private final void initializeEntries() { |
aoqi@0 | 94 | _inScopeNamespaces[0] = _namespacePool; |
aoqi@0 | 95 | _namespacePool = _namespacePool.next; |
aoqi@0 | 96 | _inScopeNamespaces[0].next = null; |
aoqi@0 | 97 | _inScopeNamespaces[0].prefix = ""; |
aoqi@0 | 98 | _inScopeNamespaces[0].namespaceName = ""; |
aoqi@0 | 99 | _inScopeNamespaces[0].namespaceIndex = _currentInScope[0] = 0; |
aoqi@0 | 100 | |
aoqi@0 | 101 | int index = KeyIntMap.indexFor(KeyIntMap.hashHash(_inScopeNamespaces[0].prefix.hashCode()), _prefixMap.length); |
aoqi@0 | 102 | _prefixMap[index] = _prefixPool; |
aoqi@0 | 103 | _prefixPool = _prefixPool.next; |
aoqi@0 | 104 | _prefixMap[index].next = null; |
aoqi@0 | 105 | _prefixMap[index].prefixId = 0; |
aoqi@0 | 106 | |
aoqi@0 | 107 | |
aoqi@0 | 108 | _inScopeNamespaces[1] = _namespacePool; |
aoqi@0 | 109 | _namespacePool = _namespacePool.next; |
aoqi@0 | 110 | _inScopeNamespaces[1].next = null; |
aoqi@0 | 111 | _inScopeNamespaces[1].prefix = EncodingConstants.XML_NAMESPACE_PREFIX; |
aoqi@0 | 112 | _inScopeNamespaces[1].namespaceName = EncodingConstants.XML_NAMESPACE_NAME; |
aoqi@0 | 113 | _inScopeNamespaces[1].namespaceIndex = _currentInScope[1] = 1; |
aoqi@0 | 114 | |
aoqi@0 | 115 | index = KeyIntMap.indexFor(KeyIntMap.hashHash(_inScopeNamespaces[1].prefix.hashCode()), _prefixMap.length); |
aoqi@0 | 116 | if (_prefixMap[index] == null) { |
aoqi@0 | 117 | _prefixMap[index] = _prefixPool; |
aoqi@0 | 118 | _prefixPool = _prefixPool.next; |
aoqi@0 | 119 | _prefixMap[index].next = null; |
aoqi@0 | 120 | } else { |
aoqi@0 | 121 | final PrefixEntry e = _prefixMap[index]; |
aoqi@0 | 122 | _prefixMap[index] = _prefixPool; |
aoqi@0 | 123 | _prefixPool = _prefixPool.next; |
aoqi@0 | 124 | _prefixMap[index].next = e; |
aoqi@0 | 125 | } |
aoqi@0 | 126 | _prefixMap[index].prefixId = 1; |
aoqi@0 | 127 | } |
aoqi@0 | 128 | |
aoqi@0 | 129 | private final void increaseNamespacePool(int capacity) { |
aoqi@0 | 130 | if (_namespacePool == null) { |
aoqi@0 | 131 | _namespacePool = new NamespaceEntry(); |
aoqi@0 | 132 | } |
aoqi@0 | 133 | |
aoqi@0 | 134 | for (int i = 0; i < capacity; i++) { |
aoqi@0 | 135 | NamespaceEntry ne = new NamespaceEntry(); |
aoqi@0 | 136 | ne.next = _namespacePool; |
aoqi@0 | 137 | _namespacePool = ne; |
aoqi@0 | 138 | } |
aoqi@0 | 139 | } |
aoqi@0 | 140 | |
aoqi@0 | 141 | private final void increasePrefixPool(int capacity) { |
aoqi@0 | 142 | if (_prefixPool == null) { |
aoqi@0 | 143 | _prefixPool = new PrefixEntry(); |
aoqi@0 | 144 | } |
aoqi@0 | 145 | |
aoqi@0 | 146 | for (int i = 0; i < capacity; i++) { |
aoqi@0 | 147 | PrefixEntry pe = new PrefixEntry(); |
aoqi@0 | 148 | pe.next = _prefixPool; |
aoqi@0 | 149 | _prefixPool = pe; |
aoqi@0 | 150 | } |
aoqi@0 | 151 | } |
aoqi@0 | 152 | |
aoqi@0 | 153 | public int countNamespacePool() { |
aoqi@0 | 154 | int i = 0; |
aoqi@0 | 155 | NamespaceEntry e = _namespacePool; |
aoqi@0 | 156 | while (e != null) { |
aoqi@0 | 157 | i++; |
aoqi@0 | 158 | e = e.next; |
aoqi@0 | 159 | } |
aoqi@0 | 160 | return i; |
aoqi@0 | 161 | } |
aoqi@0 | 162 | |
aoqi@0 | 163 | public int countPrefixPool() { |
aoqi@0 | 164 | int i = 0; |
aoqi@0 | 165 | PrefixEntry e = _prefixPool; |
aoqi@0 | 166 | while (e != null) { |
aoqi@0 | 167 | i++; |
aoqi@0 | 168 | e = e.next; |
aoqi@0 | 169 | } |
aoqi@0 | 170 | return i; |
aoqi@0 | 171 | } |
aoqi@0 | 172 | |
aoqi@0 | 173 | public final void clear() { |
aoqi@0 | 174 | for (int i = _readOnlyArraySize; i < _size; i++) { |
aoqi@0 | 175 | _array[i] = null; |
aoqi@0 | 176 | } |
aoqi@0 | 177 | _size = _readOnlyArraySize; |
aoqi@0 | 178 | } |
aoqi@0 | 179 | |
aoqi@0 | 180 | public final void clearCompletely() { |
aoqi@0 | 181 | _prefixPool = null; |
aoqi@0 | 182 | _namespacePool = null; |
aoqi@0 | 183 | |
aoqi@0 | 184 | for (int i = 0; i < _size + 2; i++) { |
aoqi@0 | 185 | _currentInScope[i] = 0; |
aoqi@0 | 186 | _inScopeNamespaces[i] = null; |
aoqi@0 | 187 | } |
aoqi@0 | 188 | |
aoqi@0 | 189 | for (int i = 0; i < _prefixMap.length; i++) { |
aoqi@0 | 190 | _prefixMap[i] = null; |
aoqi@0 | 191 | } |
aoqi@0 | 192 | |
aoqi@0 | 193 | increaseNamespacePool(_initialCapacity); |
aoqi@0 | 194 | increasePrefixPool(_initialCapacity); |
aoqi@0 | 195 | |
aoqi@0 | 196 | initializeEntries(); |
aoqi@0 | 197 | |
aoqi@0 | 198 | _declarationId = 0; |
aoqi@0 | 199 | |
aoqi@0 | 200 | clear(); |
aoqi@0 | 201 | } |
aoqi@0 | 202 | |
aoqi@0 | 203 | /** |
aoqi@0 | 204 | * Returns cloned version of internal String[]. |
aoqi@0 | 205 | * @return cloned version of internal String[]. |
aoqi@0 | 206 | */ |
aoqi@0 | 207 | public final String[] getArray() { |
aoqi@0 | 208 | if (_array == null) return null; |
aoqi@0 | 209 | |
aoqi@0 | 210 | final String[] clonedArray = new String[_array.length]; |
aoqi@0 | 211 | System.arraycopy(_array, 0, clonedArray, 0, _array.length); |
aoqi@0 | 212 | return clonedArray; |
aoqi@0 | 213 | } |
aoqi@0 | 214 | |
aoqi@0 | 215 | public final void setReadOnlyArray(ValueArray readOnlyArray, boolean clear) { |
aoqi@0 | 216 | if (!(readOnlyArray instanceof PrefixArray)) { |
aoqi@0 | 217 | throw new IllegalArgumentException(CommonResourceBundle.getInstance(). |
aoqi@0 | 218 | getString("message.illegalClass", new Object[]{readOnlyArray})); |
aoqi@0 | 219 | } |
aoqi@0 | 220 | |
aoqi@0 | 221 | setReadOnlyArray((PrefixArray)readOnlyArray, clear); |
aoqi@0 | 222 | } |
aoqi@0 | 223 | |
aoqi@0 | 224 | public final void setReadOnlyArray(PrefixArray readOnlyArray, boolean clear) { |
aoqi@0 | 225 | if (readOnlyArray != null) { |
aoqi@0 | 226 | _readOnlyArray = readOnlyArray; |
aoqi@0 | 227 | _readOnlyArraySize = readOnlyArray.getSize(); |
aoqi@0 | 228 | |
aoqi@0 | 229 | clearCompletely(); |
aoqi@0 | 230 | |
aoqi@0 | 231 | // Resize according to size of read only arrays |
aoqi@0 | 232 | _inScopeNamespaces = new NamespaceEntry[_readOnlyArraySize + _inScopeNamespaces.length]; |
aoqi@0 | 233 | _currentInScope = new int[_readOnlyArraySize + _currentInScope.length]; |
aoqi@0 | 234 | // Intialize first two entries |
aoqi@0 | 235 | initializeEntries(); |
aoqi@0 | 236 | |
aoqi@0 | 237 | if (clear) { |
aoqi@0 | 238 | clear(); |
aoqi@0 | 239 | } |
aoqi@0 | 240 | |
aoqi@0 | 241 | _array = getCompleteArray(); |
aoqi@0 | 242 | _size = _readOnlyArraySize; |
aoqi@0 | 243 | } |
aoqi@0 | 244 | } |
aoqi@0 | 245 | |
aoqi@0 | 246 | public final String[] getCompleteArray() { |
aoqi@0 | 247 | if (_readOnlyArray == null) { |
aoqi@0 | 248 | // Return cloned version of internal _array |
aoqi@0 | 249 | return getArray(); |
aoqi@0 | 250 | // return _array; |
aoqi@0 | 251 | } else { |
aoqi@0 | 252 | final String[] ra = _readOnlyArray.getCompleteArray(); |
aoqi@0 | 253 | final String[] a = new String[_readOnlyArraySize + _array.length]; |
aoqi@0 | 254 | System.arraycopy(ra, 0, a, 0, _readOnlyArraySize); |
aoqi@0 | 255 | return a; |
aoqi@0 | 256 | } |
aoqi@0 | 257 | } |
aoqi@0 | 258 | |
aoqi@0 | 259 | public final String get(int i) { |
aoqi@0 | 260 | return _array[i]; |
aoqi@0 | 261 | } |
aoqi@0 | 262 | |
aoqi@0 | 263 | public final int add(String s) { |
aoqi@0 | 264 | if (_size == _array.length) { |
aoqi@0 | 265 | resize(); |
aoqi@0 | 266 | } |
aoqi@0 | 267 | |
aoqi@0 | 268 | _array[_size++] = s; |
aoqi@0 | 269 | return _size; |
aoqi@0 | 270 | } |
aoqi@0 | 271 | |
aoqi@0 | 272 | protected final void resize() { |
aoqi@0 | 273 | if (_size == _maximumCapacity) { |
aoqi@0 | 274 | throw new ValueArrayResourceException(CommonResourceBundle.getInstance().getString("message.arrayMaxCapacity")); |
aoqi@0 | 275 | } |
aoqi@0 | 276 | |
aoqi@0 | 277 | int newSize = _size * 3 / 2 + 1; |
aoqi@0 | 278 | if (newSize > _maximumCapacity) { |
aoqi@0 | 279 | newSize = _maximumCapacity; |
aoqi@0 | 280 | } |
aoqi@0 | 281 | |
aoqi@0 | 282 | final String[] newArray = new String[newSize]; |
aoqi@0 | 283 | System.arraycopy(_array, 0, newArray, 0, _size); |
aoqi@0 | 284 | _array = newArray; |
aoqi@0 | 285 | |
aoqi@0 | 286 | newSize += 2; |
aoqi@0 | 287 | final NamespaceEntry[] newInScopeNamespaces = new NamespaceEntry[newSize]; |
aoqi@0 | 288 | System.arraycopy(_inScopeNamespaces, 0, newInScopeNamespaces, 0, _inScopeNamespaces.length); |
aoqi@0 | 289 | _inScopeNamespaces = newInScopeNamespaces; |
aoqi@0 | 290 | |
aoqi@0 | 291 | final int[] newCurrentInScope = new int[newSize]; |
aoqi@0 | 292 | System.arraycopy(_currentInScope, 0, newCurrentInScope, 0, _currentInScope.length); |
aoqi@0 | 293 | _currentInScope = newCurrentInScope; |
aoqi@0 | 294 | } |
aoqi@0 | 295 | |
aoqi@0 | 296 | public final void clearDeclarationIds() { |
aoqi@0 | 297 | for (int i = 0; i < _size; i++) { |
aoqi@0 | 298 | final NamespaceEntry e = _inScopeNamespaces[i]; |
aoqi@0 | 299 | if (e != null) { |
aoqi@0 | 300 | e.declarationId = 0; |
aoqi@0 | 301 | } |
aoqi@0 | 302 | } |
aoqi@0 | 303 | |
aoqi@0 | 304 | _declarationId = 1; |
aoqi@0 | 305 | } |
aoqi@0 | 306 | |
aoqi@0 | 307 | public final void pushScope(int prefixIndex, int namespaceIndex) throws FastInfosetException { |
aoqi@0 | 308 | if (_namespacePool == null) { |
aoqi@0 | 309 | increaseNamespacePool(16); |
aoqi@0 | 310 | } |
aoqi@0 | 311 | |
aoqi@0 | 312 | final NamespaceEntry e = _namespacePool; |
aoqi@0 | 313 | _namespacePool = e.next; |
aoqi@0 | 314 | |
aoqi@0 | 315 | final NamespaceEntry current = _inScopeNamespaces[++prefixIndex]; |
aoqi@0 | 316 | if (current == null) { |
aoqi@0 | 317 | e.declarationId = _declarationId; |
aoqi@0 | 318 | e.namespaceIndex = _currentInScope[prefixIndex] = ++namespaceIndex; |
aoqi@0 | 319 | e.next = null; |
aoqi@0 | 320 | |
aoqi@0 | 321 | _inScopeNamespaces[prefixIndex] = e; |
aoqi@0 | 322 | } else if (current.declarationId < _declarationId) { |
aoqi@0 | 323 | e.declarationId = _declarationId; |
aoqi@0 | 324 | e.namespaceIndex = _currentInScope[prefixIndex] = ++namespaceIndex; |
aoqi@0 | 325 | e.next = current; |
aoqi@0 | 326 | |
aoqi@0 | 327 | current.declarationId = 0; |
aoqi@0 | 328 | _inScopeNamespaces[prefixIndex] = e; |
aoqi@0 | 329 | } else { |
aoqi@0 | 330 | throw new FastInfosetException(CommonResourceBundle.getInstance().getString("message.duplicateNamespaceAttribute")); |
aoqi@0 | 331 | } |
aoqi@0 | 332 | } |
aoqi@0 | 333 | |
aoqi@0 | 334 | public final void pushScopeWithPrefixEntry(String prefix, String namespaceName, |
aoqi@0 | 335 | int prefixIndex, int namespaceIndex) throws FastInfosetException { |
aoqi@0 | 336 | if (_namespacePool == null) { |
aoqi@0 | 337 | increaseNamespacePool(16); |
aoqi@0 | 338 | } |
aoqi@0 | 339 | if (_prefixPool == null) { |
aoqi@0 | 340 | increasePrefixPool(16); |
aoqi@0 | 341 | } |
aoqi@0 | 342 | |
aoqi@0 | 343 | final NamespaceEntry e = _namespacePool; |
aoqi@0 | 344 | _namespacePool = e.next; |
aoqi@0 | 345 | |
aoqi@0 | 346 | final NamespaceEntry current = _inScopeNamespaces[++prefixIndex]; |
aoqi@0 | 347 | if (current == null) { |
aoqi@0 | 348 | e.declarationId = _declarationId; |
aoqi@0 | 349 | e.namespaceIndex = _currentInScope[prefixIndex] = ++namespaceIndex; |
aoqi@0 | 350 | e.next = null; |
aoqi@0 | 351 | |
aoqi@0 | 352 | _inScopeNamespaces[prefixIndex] = e; |
aoqi@0 | 353 | } else if (current.declarationId < _declarationId) { |
aoqi@0 | 354 | e.declarationId = _declarationId; |
aoqi@0 | 355 | e.namespaceIndex = _currentInScope[prefixIndex] = ++namespaceIndex; |
aoqi@0 | 356 | e.next = current; |
aoqi@0 | 357 | |
aoqi@0 | 358 | current.declarationId = 0; |
aoqi@0 | 359 | _inScopeNamespaces[prefixIndex] = e; |
aoqi@0 | 360 | } else { |
aoqi@0 | 361 | throw new FastInfosetException(CommonResourceBundle.getInstance().getString("message.duplicateNamespaceAttribute")); |
aoqi@0 | 362 | } |
aoqi@0 | 363 | |
aoqi@0 | 364 | final PrefixEntry p = _prefixPool; |
aoqi@0 | 365 | _prefixPool = _prefixPool.next; |
aoqi@0 | 366 | p.prefixId = prefixIndex; |
aoqi@0 | 367 | |
aoqi@0 | 368 | e.prefix = prefix; |
aoqi@0 | 369 | e.namespaceName = namespaceName; |
aoqi@0 | 370 | e.prefixEntryIndex = KeyIntMap.indexFor(KeyIntMap.hashHash(prefix.hashCode()), _prefixMap.length); |
aoqi@0 | 371 | |
aoqi@0 | 372 | final PrefixEntry pCurrent = _prefixMap[e.prefixEntryIndex]; |
aoqi@0 | 373 | p.next = pCurrent; |
aoqi@0 | 374 | _prefixMap[e.prefixEntryIndex] = p; |
aoqi@0 | 375 | } |
aoqi@0 | 376 | |
aoqi@0 | 377 | public final void popScope(int prefixIndex) { |
aoqi@0 | 378 | final NamespaceEntry e = _inScopeNamespaces[++prefixIndex]; |
aoqi@0 | 379 | _inScopeNamespaces[prefixIndex] = e.next; |
aoqi@0 | 380 | _currentInScope[prefixIndex] = (e.next != null) ? e.next.namespaceIndex : 0; |
aoqi@0 | 381 | |
aoqi@0 | 382 | e.next = _namespacePool; |
aoqi@0 | 383 | _namespacePool = e; |
aoqi@0 | 384 | } |
aoqi@0 | 385 | |
aoqi@0 | 386 | public final void popScopeWithPrefixEntry(int prefixIndex) { |
aoqi@0 | 387 | final NamespaceEntry e = _inScopeNamespaces[++prefixIndex]; |
aoqi@0 | 388 | |
aoqi@0 | 389 | _inScopeNamespaces[prefixIndex] = e.next; |
aoqi@0 | 390 | _currentInScope[prefixIndex] = (e.next != null) ? e.next.namespaceIndex : 0; |
aoqi@0 | 391 | |
aoqi@0 | 392 | e.prefix = e.namespaceName = null; |
aoqi@0 | 393 | e.next = _namespacePool; |
aoqi@0 | 394 | _namespacePool = e; |
aoqi@0 | 395 | |
aoqi@0 | 396 | PrefixEntry current = _prefixMap[e.prefixEntryIndex]; |
aoqi@0 | 397 | if (current.prefixId == prefixIndex) { |
aoqi@0 | 398 | _prefixMap[e.prefixEntryIndex] = current.next; |
aoqi@0 | 399 | current.next = _prefixPool; |
aoqi@0 | 400 | _prefixPool = current; |
aoqi@0 | 401 | } else { |
aoqi@0 | 402 | PrefixEntry prev = current; |
aoqi@0 | 403 | current = current.next; |
aoqi@0 | 404 | while (current != null) { |
aoqi@0 | 405 | if (current.prefixId == prefixIndex) { |
aoqi@0 | 406 | prev.next = current.next; |
aoqi@0 | 407 | current.next = _prefixPool; |
aoqi@0 | 408 | _prefixPool = current; |
aoqi@0 | 409 | break; |
aoqi@0 | 410 | } |
aoqi@0 | 411 | prev = current; |
aoqi@0 | 412 | current = current.next; |
aoqi@0 | 413 | } |
aoqi@0 | 414 | } |
aoqi@0 | 415 | } |
aoqi@0 | 416 | |
aoqi@0 | 417 | public final String getNamespaceFromPrefix(String prefix) { |
aoqi@0 | 418 | final int index = KeyIntMap.indexFor(KeyIntMap.hashHash(prefix.hashCode()), _prefixMap.length); |
aoqi@0 | 419 | PrefixEntry pe = _prefixMap[index]; |
aoqi@0 | 420 | while (pe != null) { |
aoqi@0 | 421 | final NamespaceEntry ne = _inScopeNamespaces[pe.prefixId]; |
aoqi@0 | 422 | if (prefix == ne.prefix || prefix.equals(ne.prefix)) { |
aoqi@0 | 423 | return ne.namespaceName; |
aoqi@0 | 424 | } |
aoqi@0 | 425 | pe = pe.next; |
aoqi@0 | 426 | } |
aoqi@0 | 427 | |
aoqi@0 | 428 | return null; |
aoqi@0 | 429 | } |
aoqi@0 | 430 | |
aoqi@0 | 431 | public final String getPrefixFromNamespace(String namespaceName) { |
aoqi@0 | 432 | int position = 0; |
aoqi@0 | 433 | while (++position < _size + 2) { |
aoqi@0 | 434 | final NamespaceEntry ne = _inScopeNamespaces[position]; |
aoqi@0 | 435 | if (ne != null && namespaceName.equals(ne.namespaceName)) { |
aoqi@0 | 436 | return ne.prefix; |
aoqi@0 | 437 | } |
aoqi@0 | 438 | } |
aoqi@0 | 439 | |
aoqi@0 | 440 | return null; |
aoqi@0 | 441 | } |
aoqi@0 | 442 | |
aoqi@0 | 443 | public final Iterator getPrefixes() { |
aoqi@0 | 444 | return new Iterator() { |
aoqi@0 | 445 | int _position = 1; |
aoqi@0 | 446 | NamespaceEntry _ne = _inScopeNamespaces[_position]; |
aoqi@0 | 447 | |
aoqi@0 | 448 | public boolean hasNext() { |
aoqi@0 | 449 | return _ne != null; |
aoqi@0 | 450 | } |
aoqi@0 | 451 | |
aoqi@0 | 452 | public Object next() { |
aoqi@0 | 453 | if (_position == _size + 2) { |
aoqi@0 | 454 | throw new NoSuchElementException(); |
aoqi@0 | 455 | } |
aoqi@0 | 456 | |
aoqi@0 | 457 | final String prefix = _ne.prefix; |
aoqi@0 | 458 | moveToNext(); |
aoqi@0 | 459 | return prefix; |
aoqi@0 | 460 | } |
aoqi@0 | 461 | |
aoqi@0 | 462 | public void remove() { |
aoqi@0 | 463 | throw new UnsupportedOperationException(); |
aoqi@0 | 464 | } |
aoqi@0 | 465 | |
aoqi@0 | 466 | private final void moveToNext() { |
aoqi@0 | 467 | while (++_position < _size + 2) { |
aoqi@0 | 468 | _ne = _inScopeNamespaces[_position]; |
aoqi@0 | 469 | if (_ne != null) { |
aoqi@0 | 470 | return; |
aoqi@0 | 471 | } |
aoqi@0 | 472 | } |
aoqi@0 | 473 | _ne = null; |
aoqi@0 | 474 | } |
aoqi@0 | 475 | |
aoqi@0 | 476 | }; |
aoqi@0 | 477 | } |
aoqi@0 | 478 | |
aoqi@0 | 479 | public final Iterator getPrefixesFromNamespace(final String namespaceName) { |
aoqi@0 | 480 | return new Iterator() { |
aoqi@0 | 481 | String _namespaceName = namespaceName; |
aoqi@0 | 482 | int _position = 0; |
aoqi@0 | 483 | NamespaceEntry _ne; |
aoqi@0 | 484 | |
aoqi@0 | 485 | { |
aoqi@0 | 486 | moveToNext(); |
aoqi@0 | 487 | } |
aoqi@0 | 488 | |
aoqi@0 | 489 | public boolean hasNext() { |
aoqi@0 | 490 | return _ne != null; |
aoqi@0 | 491 | } |
aoqi@0 | 492 | |
aoqi@0 | 493 | public Object next() { |
aoqi@0 | 494 | if (_position == _size + 2) { |
aoqi@0 | 495 | throw new NoSuchElementException(); |
aoqi@0 | 496 | } |
aoqi@0 | 497 | |
aoqi@0 | 498 | final String prefix = _ne.prefix; |
aoqi@0 | 499 | moveToNext(); |
aoqi@0 | 500 | return prefix; |
aoqi@0 | 501 | } |
aoqi@0 | 502 | |
aoqi@0 | 503 | public void remove() { |
aoqi@0 | 504 | throw new UnsupportedOperationException(); |
aoqi@0 | 505 | } |
aoqi@0 | 506 | |
aoqi@0 | 507 | private final void moveToNext() { |
aoqi@0 | 508 | while (++_position < _size + 2) { |
aoqi@0 | 509 | _ne = _inScopeNamespaces[_position]; |
aoqi@0 | 510 | if (_ne != null && _namespaceName.equals(_ne.namespaceName)) { |
aoqi@0 | 511 | return; |
aoqi@0 | 512 | } |
aoqi@0 | 513 | } |
aoqi@0 | 514 | _ne = null; |
aoqi@0 | 515 | } |
aoqi@0 | 516 | }; |
aoqi@0 | 517 | } |
aoqi@0 | 518 | } |