feat(jdk8): move files to new folder to avoid resources compiled.

This commit is contained in:
2025-09-07 15:25:52 +08:00
parent 3f0047bf6f
commit 8c35cfb1c0
17415 changed files with 217 additions and 213 deletions

View File

@@ -0,0 +1,158 @@
/*
* Copyright (c) 2004, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*
* THIS FILE WAS MODIFIED BY SUN MICROSYSTEMS, INC.
*/
package com.sun.xml.internal.fastinfoset.util;
public class CharArray implements CharSequence {
public char[] ch;
public int start;
public int length;
protected int _hash;
protected CharArray() {
}
public CharArray(char[] _ch, int _start, int _length, boolean copy) {
set(_ch, _start, _length, copy);
}
public final void set(char[] _ch, int _start, int _length, boolean copy) {
if (copy) {
ch = new char[_length];
start = 0;
length = _length;
System.arraycopy(_ch, _start, ch, 0, _length);
} else {
ch = _ch;
start = _start;
length = _length;
}
_hash = 0;
}
public final void cloneArray() {
char[] _ch = new char[length];
System.arraycopy(ch, start, _ch, 0, length);
ch = _ch;
start = 0;
}
public String toString() {
return new String(ch, start, length);
}
public int hashCode() {
if (_hash == 0) {
// Same hash code algorithm as used for String
// s[0]*31^(n-1) + s[1]*31^(n-2) + ... + s[n-1]
for (int i = start; i < start + length; i++) {
_hash = 31*_hash + ch[i];
}
}
return _hash;
}
public static final int hashCode(char[] ch, int start, int length) {
// Same hash code algorithm as used for String
// s[0]*31^(n-1) + s[1]*31^(n-2) + ... + s[n-1]
int hash = 0;
for (int i = start; i < start + length; i++) {
hash = 31*hash + ch[i];
}
return hash;
}
public final boolean equalsCharArray(CharArray cha) {
if (this == cha) {
return true;
}
if (length == cha.length) {
int n = length;
int i = start;
int j = cha.start;
while (n-- != 0) {
if (ch[i++] != cha.ch[j++])
return false;
}
return true;
}
return false;
}
public final boolean equalsCharArray(char[] ch, int start, int length) {
if (this.length == length) {
int n = this.length;
int i = this.start;
int j = start;
while (n-- != 0) {
if (this.ch[i++] != ch[j++])
return false;
}
return true;
}
return false;
}
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj instanceof CharArray) {
CharArray cha = (CharArray)obj;
if (length == cha.length) {
int n = length;
int i = start;
int j = cha.start;
while (n-- != 0) {
if (ch[i++] != cha.ch[j++])
return false;
}
return true;
}
}
return false;
}
// CharSequence interface
public final int length() {
return length;
}
public final char charAt(int index) {
return ch[start + index];
}
public final CharSequence subSequence(int start, int end) {
return new CharArray(ch, this.start + start, end - start, false);
}
}

View File

@@ -0,0 +1,119 @@
/*
* Copyright (c) 2004, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*
* THIS FILE WAS MODIFIED BY SUN MICROSYSTEMS, INC.
*/
package com.sun.xml.internal.fastinfoset.util;
import com.sun.xml.internal.fastinfoset.CommonResourceBundle;
public class CharArrayArray extends ValueArray {
private CharArray[] _array;
private CharArrayArray _readOnlyArray;
public CharArrayArray(int initialCapacity, int maximumCapacity) {
_array = new CharArray[initialCapacity];
_maximumCapacity = maximumCapacity;
}
public CharArrayArray() {
this(DEFAULT_CAPACITY, MAXIMUM_CAPACITY);
}
public final void clear() {
for (int i = 0; i < _size; i++) {
_array[i] = null;
}
_size = 0;
}
/**
* Returns cloned version of internal CharArray[].
* @return cloned version of internal CharArray[].
*/
public final CharArray[] getArray() {
if (_array == null) return null;
final CharArray[] clonedArray = new CharArray[_array.length];
System.arraycopy(_array, 0, clonedArray, 0, _array.length);
return clonedArray;
}
public final void setReadOnlyArray(ValueArray readOnlyArray, boolean clear) {
if (!(readOnlyArray instanceof CharArrayArray)) {
throw new IllegalArgumentException(CommonResourceBundle.getInstance().getString("message.illegalClass", new Object[]{readOnlyArray}));
}
setReadOnlyArray((CharArrayArray)readOnlyArray, clear);
}
public final void setReadOnlyArray(CharArrayArray readOnlyArray, boolean clear) {
if (readOnlyArray != null) {
_readOnlyArray = readOnlyArray;
_readOnlyArraySize = readOnlyArray.getSize();
if (clear) {
clear();
}
}
}
public final CharArray get(int i) {
if (_readOnlyArray == null) {
return _array[i];
} else {
if (i < _readOnlyArraySize) {
return _readOnlyArray.get(i);
} else {
return _array[i - _readOnlyArraySize];
}
}
}
public final void add(CharArray s) {
if (_size == _array.length) {
resize();
}
_array[_size++] = s;
}
protected final void resize() {
if (_size == _maximumCapacity) {
throw new ValueArrayResourceException(CommonResourceBundle.getInstance().getString("message.arrayMaxCapacity"));
}
int newSize = _size * 3 / 2 + 1;
if (newSize > _maximumCapacity) {
newSize = _maximumCapacity;
}
final CharArray[] newArray = new CharArray[newSize];
System.arraycopy(_array, 0, newArray, 0, _size);
_array = newArray;
}
}

View File

@@ -0,0 +1,228 @@
/*
* Copyright (c) 2004, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*
* THIS FILE WAS MODIFIED BY SUN MICROSYSTEMS, INC.
*/
package com.sun.xml.internal.fastinfoset.util;
import com.sun.xml.internal.fastinfoset.CommonResourceBundle;
public class CharArrayIntMap extends KeyIntMap {
private CharArrayIntMap _readOnlyMap;
// Total character count of Map
protected int _totalCharacterCount;
static class Entry extends BaseEntry {
final char[] _ch;
final int _start;
final int _length;
Entry _next;
public Entry(char[] ch, int start, int length, int hash, int value, Entry next) {
super(hash, value);
_ch = ch;
_start = start;
_length = length;
_next = next;
}
public final boolean equalsCharArray(char[] ch, int start, int length) {
if (_length == length) {
int n = _length;
int i = _start;
int j = start;
while (n-- != 0) {
if (_ch[i++] != ch[j++])
return false;
}
return true;
}
return false;
}
}
private Entry[] _table;
public CharArrayIntMap(int initialCapacity, float loadFactor) {
super(initialCapacity, loadFactor);
_table = new Entry[_capacity];
}
public CharArrayIntMap(int initialCapacity) {
this(initialCapacity, DEFAULT_LOAD_FACTOR);
}
public CharArrayIntMap() {
this(DEFAULT_INITIAL_CAPACITY, DEFAULT_LOAD_FACTOR);
}
public final void clear() {
for (int i = 0; i < _table.length; i++) {
_table[i] = null;
}
_size = 0;
_totalCharacterCount = 0;
}
public final void setReadOnlyMap(KeyIntMap readOnlyMap, boolean clear) {
if (!(readOnlyMap instanceof CharArrayIntMap)) {
throw new IllegalArgumentException(CommonResourceBundle.getInstance().
getString("message.illegalClass", new Object[]{readOnlyMap}));
}
setReadOnlyMap((CharArrayIntMap)readOnlyMap, clear);
}
public final void setReadOnlyMap(CharArrayIntMap readOnlyMap, boolean clear) {
_readOnlyMap = readOnlyMap;
if (_readOnlyMap != null) {
_readOnlyMapSize = _readOnlyMap.size();
if (clear) {
clear();
}
} else {
_readOnlyMapSize = 0;
}
}
/**
* Method returns an index of the passed character buffer in
* <code>CharArrayIntMap</code>.
*
* @return index of character buffer in <code>CharArrayIntMap</code>,
* otherwise NOT_PRESENT.
*/
public final int get(char[] ch, int start, int length) {
final int hash = hashHash(CharArray.hashCode(ch, start, length));
return get(ch, start, length, hash);
}
/**
* Method returns an index of the passed character buffer in
* <code>CharArrayIntMap</code>. If character buffer is not in
* <code>CharArrayIntMap</code> - it will be added.
*
* @return index of character buffer in <code>CharArrayIntMap</code>, or
* NOT_PRESENT if character buffer was just added.
*/
public final int obtainIndex(char[] ch, int start, int length, boolean clone) {
final int hash = hashHash(CharArray.hashCode(ch, start, length));
if (_readOnlyMap != null) {
final int index = _readOnlyMap.get(ch, start, length, hash);
if (index != -1) {
return index;
}
}
final int tableIndex = indexFor(hash, _table.length);
for (Entry e = _table[tableIndex]; e != null; e = e._next) {
if (e._hash == hash && e.equalsCharArray(ch, start, length)) {
return e._value;
}
}
if (clone) {
char[] chClone = new char[length];
System.arraycopy(ch, start, chClone, 0, length);
ch = chClone;
start = 0;
}
addEntry(ch, start, length, hash, _size + _readOnlyMapSize, tableIndex);
return NOT_PRESENT;
}
public final int getTotalCharacterCount() {
return _totalCharacterCount;
}
private final int get(char[] ch, int start, int length, int hash) {
if (_readOnlyMap != null) {
final int i = _readOnlyMap.get(ch, start, length, hash);
if (i != -1) {
return i;
}
}
final int tableIndex = indexFor(hash, _table.length);
for (Entry e = _table[tableIndex]; e != null; e = e._next) {
if (e._hash == hash && e.equalsCharArray(ch, start, length)) {
return e._value;
}
}
return NOT_PRESENT;
}
private final void addEntry(char[] ch, int start, int length, int hash, int value, int bucketIndex) {
Entry e = _table[bucketIndex];
_table[bucketIndex] = new Entry(ch, start, length, hash, value, e);
_totalCharacterCount += length;
if (_size++ >= _threshold) {
resize(2 * _table.length);
}
}
private final void resize(int newCapacity) {
_capacity = newCapacity;
Entry[] oldTable = _table;
int oldCapacity = oldTable.length;
if (oldCapacity == MAXIMUM_CAPACITY) {
_threshold = Integer.MAX_VALUE;
return;
}
Entry[] newTable = new Entry[_capacity];
transfer(newTable);
_table = newTable;
_threshold = (int)(_capacity * _loadFactor);
}
private final void transfer(Entry[] newTable) {
Entry[] src = _table;
int newCapacity = newTable.length;
for (int j = 0; j < src.length; j++) {
Entry e = src[j];
if (e != null) {
src[j] = null;
do {
Entry next = e._next;
int i = indexFor(e._hash, newCapacity);
e._next = newTable[i];
newTable[i] = e;
e = next;
} while (e != null);
}
}
}
}

View File

@@ -0,0 +1,77 @@
/*
* Copyright (c) 2004, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*
* THIS FILE WAS MODIFIED BY SUN MICROSYSTEMS, INC.
*/
package com.sun.xml.internal.fastinfoset.util;
public class CharArrayString extends CharArray {
protected String _s;
public CharArrayString(String s) {
this(s, true);
}
public CharArrayString(String s, boolean createArray) {
_s = s;
if (createArray) {
ch = _s.toCharArray();
start = 0;
length = ch.length;
}
}
public String toString() {
return _s;
}
public int hashCode() {
return _s.hashCode();
}
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj instanceof CharArrayString) {
CharArrayString chas = (CharArrayString)obj;
return _s.equals(chas._s);
} else if (obj instanceof CharArray) {
CharArray cha = (CharArray)obj;
if (length == cha.length) {
int n = length;
int i = start;
int j = cha.start;
while (n-- != 0) {
if (ch[i++] != cha.ch[j++])
return false;
}
return true;
}
}
return false;
}
}

View File

@@ -0,0 +1,244 @@
/*
* Copyright (c) 2004, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*
* THIS FILE WAS MODIFIED BY SUN MICROSYSTEMS, INC.
*/
package com.sun.xml.internal.fastinfoset.util;
import com.sun.xml.internal.fastinfoset.CommonResourceBundle;
public class ContiguousCharArrayArray extends ValueArray {
public static final int INITIAL_CHARACTER_SIZE = 512;
public static final int MAXIMUM_CHARACTER_SIZE = Integer.MAX_VALUE;
protected int _maximumCharacterSize;
public int[] _offset;
public int[] _length;
public char[] _array;
public int _arrayIndex;
public int _readOnlyArrayIndex;
private String[] _cachedStrings;
public int _cachedIndex;
private ContiguousCharArrayArray _readOnlyArray;
public ContiguousCharArrayArray(int initialCapacity, int maximumCapacity,
int initialCharacterSize, int maximumCharacterSize) {
_offset = new int[initialCapacity];
_length = new int[initialCapacity];
_array = new char[initialCharacterSize];
_maximumCapacity = maximumCapacity;
_maximumCharacterSize = maximumCharacterSize;
}
public ContiguousCharArrayArray() {
this(DEFAULT_CAPACITY, MAXIMUM_CAPACITY,
INITIAL_CHARACTER_SIZE, MAXIMUM_CHARACTER_SIZE);
}
public final void clear() {
_arrayIndex = _readOnlyArrayIndex;
_size = _readOnlyArraySize;
if (_cachedStrings != null) {
for (int i = _readOnlyArraySize; i < _cachedStrings.length; i++) {
_cachedStrings[i] = null;
}
}
}
public final int getArrayIndex() {
return _arrayIndex;
}
public final void setReadOnlyArray(ValueArray readOnlyArray, boolean clear) {
if (!(readOnlyArray instanceof ContiguousCharArrayArray)) {
throw new IllegalArgumentException(CommonResourceBundle.getInstance().getString("message.illegalClass", new Object[]{readOnlyArray}));
}
setReadOnlyArray((ContiguousCharArrayArray)readOnlyArray, clear);
}
public final void setReadOnlyArray(ContiguousCharArrayArray readOnlyArray, boolean clear) {
if (readOnlyArray != null) {
_readOnlyArray = readOnlyArray;
_readOnlyArraySize = readOnlyArray.getSize();
_readOnlyArrayIndex = readOnlyArray.getArrayIndex();
if (clear) {
clear();
}
_array = getCompleteCharArray();
_offset = getCompleteOffsetArray();
_length = getCompleteLengthArray();
_size = _readOnlyArraySize;
_arrayIndex = _readOnlyArrayIndex;
}
}
public final char[] getCompleteCharArray() {
if (_readOnlyArray == null) {
if (_array == null) return null;
// Return cloned version of internal _array
final char[] clonedArray = new char[_array.length];
System.arraycopy(_array, 0, clonedArray, 0, _array.length);
return clonedArray;
// return _array;
} else {
final char[] ra = _readOnlyArray.getCompleteCharArray();
final char[] a = new char[_readOnlyArrayIndex + _array.length];
System.arraycopy(ra, 0, a, 0, _readOnlyArrayIndex);
return a;
}
}
public final int[] getCompleteOffsetArray() {
if (_readOnlyArray == null) {
if (_offset == null) return null;
// Return cloned version of internal _offset
final int[] clonedArray = new int[_offset.length];
System.arraycopy(_offset, 0, clonedArray, 0, _offset.length);
return clonedArray;
// return _offset;
} else {
final int[] ra = _readOnlyArray.getCompleteOffsetArray();
final int[] a = new int[_readOnlyArraySize + _offset.length];
System.arraycopy(ra, 0, a, 0, _readOnlyArraySize);
return a;
}
}
public final int[] getCompleteLengthArray() {
if (_readOnlyArray == null) {
if (_length == null) return null;
// Return cloned version of internal _length
final int[] clonedArray = new int[_length.length];
System.arraycopy(_length, 0, clonedArray, 0, _length.length);
return clonedArray;
// return _length;
} else {
final int[] ra = _readOnlyArray.getCompleteLengthArray();
final int[] a = new int[_readOnlyArraySize + _length.length];
System.arraycopy(ra, 0, a, 0, _readOnlyArraySize);
return a;
}
}
public final String getString(int i) {
if (_cachedStrings != null && i < _cachedStrings.length) {
final String s = _cachedStrings[i];
return (s != null) ? s : (_cachedStrings[i] = new String(_array, _offset[i], _length[i]));
}
final String[] newCachedStrings = new String[_offset.length];
if (_cachedStrings != null && i >= _cachedStrings.length) {
System.arraycopy(_cachedStrings, 0, newCachedStrings, 0, _cachedStrings.length);
}
_cachedStrings = newCachedStrings;
return _cachedStrings[i] = new String(_array, _offset[i], _length[i]);
}
public final void ensureSize(int l) {
if (_arrayIndex + l >= _array.length) {
resizeArray(_arrayIndex + l);
}
}
public final void add(int l) {
if (_size == _offset.length) {
resize();
}
_cachedIndex = _size;
_offset[_size] = _arrayIndex;
_length[_size++] = l;
_arrayIndex += l;
}
public final int add(char[] c, int l) {
if (_size == _offset.length) {
resize();
}
final int oldArrayIndex = _arrayIndex;
final int arrayIndex = oldArrayIndex + l;
_cachedIndex = _size;
_offset[_size] = oldArrayIndex;
_length[_size++] = l;
if (arrayIndex >= _array.length) {
resizeArray(arrayIndex);
}
System.arraycopy(c, 0, _array, oldArrayIndex, l);
_arrayIndex = arrayIndex;
return oldArrayIndex;
}
protected final void resize() {
if (_size == _maximumCapacity) {
throw new ValueArrayResourceException(CommonResourceBundle.getInstance().getString("message.arrayMaxCapacity"));
}
int newSize = _size * 3 / 2 + 1;
if (newSize > _maximumCapacity) {
newSize = _maximumCapacity;
}
final int[] offset = new int[newSize];
System.arraycopy(_offset, 0, offset, 0, _size);
_offset = offset;
final int[] length = new int[newSize];
System.arraycopy(_length, 0, length, 0, _size);
_length = length;
}
protected final void resizeArray(int requestedSize) {
if (_arrayIndex == _maximumCharacterSize) {
throw new ValueArrayResourceException(CommonResourceBundle.getInstance().getString("message.maxNumberOfCharacters"));
}
int newSize = requestedSize * 3 / 2 + 1;
if (newSize > _maximumCharacterSize) {
newSize = _maximumCharacterSize;
}
final char[] array = new char[newSize];
System.arraycopy(_array, 0, array, 0, _arrayIndex);
_array = array;
}
}

View File

@@ -0,0 +1,124 @@
/*
* Copyright (c) 2004, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*
* THIS FILE WAS MODIFIED BY SUN MICROSYSTEMS, INC.
*/
package com.sun.xml.internal.fastinfoset.util;
import com.sun.xml.internal.org.jvnet.fastinfoset.FastInfosetException;
import com.sun.xml.internal.fastinfoset.CommonResourceBundle;
public class DuplicateAttributeVerifier {
public static final int MAP_SIZE = 256;
public int _currentIteration;
public static class Entry {
private int iteration;
private int value;
private Entry hashNext;
private Entry poolNext;
}
private Entry[] _map;
public final Entry _poolHead;
public Entry _poolCurrent;
private Entry _poolTail;
public DuplicateAttributeVerifier() {
_poolTail = _poolHead = new Entry();
}
public final void clear() {
_currentIteration = 0;
Entry e = _poolHead;
while (e != null) {
e.iteration = 0;
e = e.poolNext;
}
reset();
}
public final void reset() {
_poolCurrent = _poolHead;
if (_map == null) {
_map = new Entry[MAP_SIZE];
}
}
private final void increasePool(int capacity) {
if (_map == null) {
_map = new Entry[MAP_SIZE];
_poolCurrent = _poolHead;
} else {
final Entry tail = _poolTail;
for (int i = 0; i < capacity; i++) {
final Entry e = new Entry();
_poolTail.poolNext = e;
_poolTail = e;
}
_poolCurrent = tail.poolNext;
}
}
public final void checkForDuplicateAttribute(int hash, int value) throws FastInfosetException {
if (_poolCurrent == null) {
increasePool(16);
}
// Get next free entry
final Entry newEntry = _poolCurrent;
_poolCurrent = _poolCurrent.poolNext;
final Entry head = _map[hash];
if (head == null || head.iteration < _currentIteration) {
newEntry.hashNext = null;
_map[hash] = newEntry;
newEntry.iteration = _currentIteration;
newEntry.value = value;
} else {
Entry e = head;
do {
if (e.value == value) {
reset();
throw new FastInfosetException(CommonResourceBundle.getInstance().getString("message.duplicateAttribute"));
}
} while ((e = e.hashNext) != null);
newEntry.hashNext = head;
_map[hash] = newEntry;
newEntry.iteration = _currentIteration;
newEntry.value = value;
}
}
}

View File

@@ -0,0 +1,115 @@
/*
* Copyright (c) 2004, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*
* THIS FILE WAS MODIFIED BY SUN MICROSYSTEMS, INC.
*/
package com.sun.xml.internal.fastinfoset.util;
import com.sun.xml.internal.fastinfoset.CommonResourceBundle;
public class FixedEntryStringIntMap extends StringIntMap {
private Entry _fixedEntry;
public FixedEntryStringIntMap(String fixedEntry, int initialCapacity, float loadFactor) {
super(initialCapacity, loadFactor);
// Add the fixed entry
final int hash = hashHash(fixedEntry.hashCode());
final int tableIndex = indexFor(hash, _table.length);
_table[tableIndex] = _fixedEntry = new Entry(fixedEntry, hash, _index++, null);
if (_size++ >= _threshold) {
resize(2 * _table.length);
}
}
public FixedEntryStringIntMap(String fixedEntry, int initialCapacity) {
this(fixedEntry, initialCapacity, DEFAULT_LOAD_FACTOR);
}
public FixedEntryStringIntMap(String fixedEntry) {
this(fixedEntry, DEFAULT_INITIAL_CAPACITY, DEFAULT_LOAD_FACTOR);
}
public final void clear() {
for (int i = 0; i < _table.length; i++) {
_table[i] = null;
}
_lastEntry = NULL_ENTRY;
if (_fixedEntry != null) {
final int tableIndex = indexFor(_fixedEntry._hash, _table.length);
_table[tableIndex] = _fixedEntry;
_fixedEntry._next = null;
_size = 1;
_index = _readOnlyMapSize + 1;
} else {
_size = 0;
_index = _readOnlyMapSize;
}
}
public final void setReadOnlyMap(KeyIntMap readOnlyMap, boolean clear) {
if (!(readOnlyMap instanceof FixedEntryStringIntMap)) {
throw new IllegalArgumentException(CommonResourceBundle.getInstance().
getString("message.illegalClass", new Object[]{readOnlyMap}));
}
setReadOnlyMap((FixedEntryStringIntMap)readOnlyMap, clear);
}
public final void setReadOnlyMap(FixedEntryStringIntMap readOnlyMap, boolean clear) {
_readOnlyMap = readOnlyMap;
if (_readOnlyMap != null) {
readOnlyMap.removeFixedEntry();
_readOnlyMapSize = readOnlyMap.size();
_index = _readOnlyMapSize + _size;
if (clear) {
clear();
}
} else {
_readOnlyMapSize = 0;
}
}
private final void removeFixedEntry() {
if (_fixedEntry != null) {
final int tableIndex = indexFor(_fixedEntry._hash, _table.length);
final Entry firstEntry = _table[tableIndex];
if (firstEntry == _fixedEntry) {
_table[tableIndex] = _fixedEntry._next;
} else {
Entry previousEntry = firstEntry;
while (previousEntry._next != _fixedEntry) {
previousEntry = previousEntry._next;
}
previousEntry._next = _fixedEntry._next;
}
_fixedEntry = null;
_size--;
}
}
}

View File

@@ -0,0 +1,136 @@
/*
* Copyright (c) 2004, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*
* THIS FILE WAS MODIFIED BY SUN MICROSYSTEMS, INC.
*/
package com.sun.xml.internal.fastinfoset.util;
import com.sun.xml.internal.fastinfoset.CommonResourceBundle;
public abstract class KeyIntMap {
public static final int NOT_PRESENT = -1;
/**
* The default initial capacity - MUST be a power of two.
*/
static final int DEFAULT_INITIAL_CAPACITY = 16;
/**
* The maximum capacity, used if a higher value is implicitly specified
* by either of the constructors with arguments.
* MUST be a power of two <= 1<<30.
*/
static final int MAXIMUM_CAPACITY = 1 << 20;
/**
* The load factor used when none specified in constructor.
**/
static final float DEFAULT_LOAD_FACTOR = 0.75f;
int _readOnlyMapSize;
/**
* The number of key-value mappings contained in this identity hash map.
*/
int _size;
int _capacity;
/**
* The next size value at which to resize (capacity * load factor).
*/
int _threshold;
/**
* The load factor for the hash table.
*/
final float _loadFactor;
static class BaseEntry {
final int _hash;
final int _value;
public BaseEntry(int hash, int value) {
_hash = hash;
_value = value;
}
}
public KeyIntMap(int initialCapacity, float loadFactor) {
if (initialCapacity < 0)
throw new IllegalArgumentException(CommonResourceBundle.getInstance().
getString("message.illegalInitialCapacity", new Object[]{Integer.valueOf(initialCapacity)}));
if (initialCapacity > MAXIMUM_CAPACITY)
initialCapacity = MAXIMUM_CAPACITY;
if (loadFactor <= 0 || Float.isNaN(loadFactor))
throw new IllegalArgumentException(CommonResourceBundle.getInstance().
getString("message.illegalLoadFactor", new Object[]{Float.valueOf(loadFactor)}));
// Find a power of 2 >= initialCapacity
if (initialCapacity != DEFAULT_INITIAL_CAPACITY) {
_capacity = 1;
while (_capacity < initialCapacity)
_capacity <<= 1;
_loadFactor = loadFactor;
_threshold = (int)(_capacity * _loadFactor);
} else {
_capacity = DEFAULT_INITIAL_CAPACITY;
_loadFactor = DEFAULT_LOAD_FACTOR;
_threshold = (int)(DEFAULT_INITIAL_CAPACITY * DEFAULT_LOAD_FACTOR);
}
}
public KeyIntMap(int initialCapacity) {
this(initialCapacity, DEFAULT_LOAD_FACTOR);
}
public KeyIntMap() {
_capacity = DEFAULT_INITIAL_CAPACITY;
_loadFactor = DEFAULT_LOAD_FACTOR;
_threshold = (int)(DEFAULT_INITIAL_CAPACITY * DEFAULT_LOAD_FACTOR);
}
public final int size() {
return _size + _readOnlyMapSize;
}
public abstract void clear();
public abstract void setReadOnlyMap(KeyIntMap readOnlyMap, boolean clear);
public static final int hashHash(int h) {
h += ~(h << 9);
h ^= (h >>> 14);
h += (h << 4);
h ^= (h >>> 10);
return h;
}
public static final int indexFor(int h, int length) {
return h & (length-1);
}
}

View File

@@ -0,0 +1,229 @@
/*
* Copyright (c) 2004, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*
* THIS FILE WAS MODIFIED BY SUN MICROSYSTEMS, INC.
*/
package com.sun.xml.internal.fastinfoset.util;
import com.sun.xml.internal.fastinfoset.QualifiedName;
import com.sun.xml.internal.fastinfoset.CommonResourceBundle;
public class LocalNameQualifiedNamesMap extends KeyIntMap {
private LocalNameQualifiedNamesMap _readOnlyMap;
private int _index;
public static class Entry {
final String _key;
final int _hash;
public QualifiedName[] _value;
public int _valueIndex;
Entry _next;
public Entry(String key, int hash, Entry next) {
_key = key;
_hash = hash;
_next = next;
_value = new QualifiedName[1];
}
public void addQualifiedName(QualifiedName name) {
if (_valueIndex < _value.length) {
_value[_valueIndex++] = name;
} else if (_valueIndex == _value.length) {
QualifiedName[] newValue = new QualifiedName[_valueIndex * 3 / 2 + 1];
System.arraycopy(_value, 0, newValue, 0, _valueIndex);
_value = newValue;
_value[_valueIndex++] = name;
}
}
}
private Entry[] _table;
public LocalNameQualifiedNamesMap(int initialCapacity, float loadFactor) {
super(initialCapacity, loadFactor);
_table = new Entry[_capacity];
}
public LocalNameQualifiedNamesMap(int initialCapacity) {
this(initialCapacity, DEFAULT_LOAD_FACTOR);
}
public LocalNameQualifiedNamesMap() {
this(DEFAULT_INITIAL_CAPACITY, DEFAULT_LOAD_FACTOR);
}
public final void clear() {
for (int i = 0; i < _table.length; i++) {
_table[i] = null;
}
_size = 0;
if (_readOnlyMap != null) {
_index = _readOnlyMap.getIndex();
} else {
_index = 0;
}
}
public final void setReadOnlyMap(KeyIntMap readOnlyMap, boolean clear) {
if (!(readOnlyMap instanceof LocalNameQualifiedNamesMap)) {
throw new IllegalArgumentException(CommonResourceBundle.getInstance().
getString("message.illegalClass", new Object[]{readOnlyMap}));
}
setReadOnlyMap((LocalNameQualifiedNamesMap)readOnlyMap, clear);
}
public final void setReadOnlyMap(LocalNameQualifiedNamesMap readOnlyMap, boolean clear) {
_readOnlyMap = readOnlyMap;
if (_readOnlyMap != null) {
_readOnlyMapSize = _readOnlyMap.size();
_index = _readOnlyMap.getIndex();
if (clear) {
clear();
}
} else {
_readOnlyMapSize = 0;
_index = 0;
}
}
public final boolean isQNameFromReadOnlyMap(QualifiedName name) {
return (_readOnlyMap != null && name.index <= _readOnlyMap.getIndex());
}
public final int getNextIndex() {
return _index++;
}
public final int getIndex() {
return _index;
}
public final Entry obtainEntry(String key) {
final int hash = hashHash(key.hashCode());
if (_readOnlyMap != null) {
final Entry entry = _readOnlyMap.getEntry(key, hash);
if (entry != null) {
return entry;
}
}
final int tableIndex = indexFor(hash, _table.length);
for (Entry e = _table[tableIndex]; e != null; e = e._next) {
if (e._hash == hash && eq(key, e._key)) {
return e;
}
}
return addEntry(key, hash, tableIndex);
}
public final Entry obtainDynamicEntry(String key) {
final int hash = hashHash(key.hashCode());
final int tableIndex = indexFor(hash, _table.length);
for (Entry e = _table[tableIndex]; e != null; e = e._next) {
if (e._hash == hash && eq(key, e._key)) {
return e;
}
}
return addEntry(key, hash, tableIndex);
}
private final Entry getEntry(String key, int hash) {
if (_readOnlyMap != null) {
final Entry entry = _readOnlyMap.getEntry(key, hash);
if (entry != null) {
return entry;
}
}
final int tableIndex = indexFor(hash, _table.length);
for (Entry e = _table[tableIndex]; e != null; e = e._next) {
if (e._hash == hash && eq(key, e._key)) {
return e;
}
}
return null;
}
private final Entry addEntry(String key, int hash, int bucketIndex) {
Entry e = _table[bucketIndex];
_table[bucketIndex] = new Entry(key, hash, e);
e = _table[bucketIndex];
if (_size++ >= _threshold) {
resize(2 * _table.length);
}
return e;
}
private final void resize(int newCapacity) {
_capacity = newCapacity;
Entry[] oldTable = _table;
int oldCapacity = oldTable.length;
if (oldCapacity == MAXIMUM_CAPACITY) {
_threshold = Integer.MAX_VALUE;
return;
}
Entry[] newTable = new Entry[_capacity];
transfer(newTable);
_table = newTable;
_threshold = (int)(_capacity * _loadFactor);
}
private final void transfer(Entry[] newTable) {
Entry[] src = _table;
int newCapacity = newTable.length;
for (int j = 0; j < src.length; j++) {
Entry e = src[j];
if (e != null) {
src[j] = null;
do {
Entry next = e._next;
int i = indexFor(e._hash, newCapacity);
e._next = newTable[i];
newTable[i] = e;
e = next;
} while (e != null);
}
}
}
private final boolean eq(String x, String y) {
return x == y || x.equals(y);
}
}

View File

@@ -0,0 +1,231 @@
/*
* Copyright (c) 2004, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*
* THIS FILE WAS MODIFIED BY SUN MICROSYSTEMS, INC.
*/
package com.sun.xml.internal.fastinfoset.util;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import javax.xml.namespace.NamespaceContext;
/**
*
* @author Paul.Sandoz@Sun.Com
*/
final public class NamespaceContextImplementation implements NamespaceContext {
private static int DEFAULT_SIZE = 8;
private String[] prefixes = new String[DEFAULT_SIZE];
private String[] namespaceURIs = new String[DEFAULT_SIZE];
private int namespacePosition;
private int[] contexts = new int[DEFAULT_SIZE];
private int contextPosition;
private int currentContext;
public NamespaceContextImplementation() {
prefixes[0] = "xml";
namespaceURIs[0] = "http://www.w3.org/XML/1998/namespace";
prefixes[1] = "xmlns";
namespaceURIs[1] = "http://www.w3.org/2000/xmlns/";
currentContext = namespacePosition = 2;
}
public String getNamespaceURI(String prefix) {
if (prefix == null) throw new IllegalArgumentException();
// prefix = prefix.intern();
for (int i = namespacePosition - 1; i >= 0; i--) {
final String declaredPrefix = prefixes[i];
if (declaredPrefix.equals(prefix)) {
return namespaceURIs[i];
}
}
return "";
}
public String getPrefix(String namespaceURI) {
if (namespaceURI == null) throw new IllegalArgumentException();
// namespaceURI = namespaceURI.intern();
for (int i = namespacePosition - 1; i >= 0; i--) {
final String declaredNamespaceURI = namespaceURIs[i];
if (declaredNamespaceURI.equals(namespaceURI)) {
final String declaredPrefix = prefixes[i];
// Check if prefix is out of scope
boolean isOutOfScope = false;
for (int j = i + 1; j < namespacePosition; j++)
if (declaredPrefix.equals(prefixes[j])) {
isOutOfScope = true;
break;
}
if (!isOutOfScope) {
return declaredPrefix;
}
}
}
return null;
}
public String getNonDefaultPrefix(String namespaceURI) {
if (namespaceURI == null) throw new IllegalArgumentException();
// namespaceURI = namespaceURI.intern();
for (int i = namespacePosition - 1; i >= 0; i--) {
final String declaredNamespaceURI = namespaceURIs[i];
if (declaredNamespaceURI.equals(namespaceURI) &&
prefixes[i].length() > 0){
final String declaredPrefix = prefixes[i];
// Check if prefix is out of scope
for (++i; i < namespacePosition; i++)
if (declaredPrefix.equals(prefixes[i]))
return null;
return declaredPrefix;
}
}
return null;
}
public Iterator getPrefixes(String namespaceURI) {
if (namespaceURI == null) throw new IllegalArgumentException();
// namespaceURI = namespaceURI.intern();
List l = new ArrayList();
NAMESPACE_LOOP: for (int i = namespacePosition - 1; i >= 0; i--) {
final String declaredNamespaceURI = namespaceURIs[i];
if (declaredNamespaceURI.equals(namespaceURI)) {
final String declaredPrefix = prefixes[i];
// Check if prefix is out of scope
for (int j = i + 1; j < namespacePosition; j++)
if (declaredPrefix.equals(prefixes[j]))
continue NAMESPACE_LOOP;
l.add(declaredPrefix);
}
}
return l.iterator();
}
public String getPrefix(int index) {
return prefixes[index];
}
public String getNamespaceURI(int index) {
return namespaceURIs[index];
}
public int getCurrentContextStartIndex() {
return currentContext;
}
public int getCurrentContextEndIndex() {
return namespacePosition;
}
public boolean isCurrentContextEmpty() {
return currentContext == namespacePosition;
}
public void declarePrefix(String prefix, String namespaceURI) {
prefix = prefix.intern();
namespaceURI = namespaceURI.intern();
// Ignore the "xml" or "xmlns" declarations
if (prefix == "xml" || prefix == "xmlns")
return;
// Replace any previous declaration
for (int i = currentContext; i < namespacePosition; i++) {
final String declaredPrefix = prefixes[i];
if (declaredPrefix == prefix) {
prefixes[i] = prefix;
namespaceURIs[i] = namespaceURI;
return;
}
}
if (namespacePosition == namespaceURIs.length)
resizeNamespaces();
// Add new declaration
prefixes[namespacePosition] = prefix;
namespaceURIs[namespacePosition++] = namespaceURI;
}
private void resizeNamespaces() {
final int newLength = namespaceURIs.length * 3 / 2 + 1;
String[] newPrefixes = new String[newLength];
System.arraycopy(prefixes, 0, newPrefixes, 0, prefixes.length);
prefixes = newPrefixes;
String[] newNamespaceURIs = new String[newLength];
System.arraycopy(namespaceURIs, 0, newNamespaceURIs, 0, namespaceURIs.length);
namespaceURIs = newNamespaceURIs;
}
public void pushContext() {
if (contextPosition == contexts.length)
resizeContexts();
contexts[contextPosition++] = currentContext = namespacePosition;
}
private void resizeContexts() {
int[] newContexts = new int[contexts.length * 3 / 2 + 1];
System.arraycopy(contexts, 0, newContexts, 0, contexts.length);
contexts = newContexts;
}
public void popContext() {
if (contextPosition > 0) {
namespacePosition = currentContext = contexts[--contextPosition];
}
}
public void reset() {
currentContext = namespacePosition = 2;
}
}

View File

@@ -0,0 +1,518 @@
/*
* Copyright (c) 2004, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*
* THIS FILE WAS MODIFIED BY SUN MICROSYSTEMS, INC.
*/
package com.sun.xml.internal.fastinfoset.util;
import com.sun.xml.internal.fastinfoset.EncodingConstants;
import com.sun.xml.internal.fastinfoset.CommonResourceBundle;
import java.util.Iterator;
import java.util.NoSuchElementException;
import com.sun.xml.internal.org.jvnet.fastinfoset.FastInfosetException;
public class PrefixArray extends ValueArray {
public static final int PREFIX_MAP_SIZE = 64;
private int _initialCapacity;
public String[] _array;
private PrefixArray _readOnlyArray;
private static class PrefixEntry {
private PrefixEntry next;
private int prefixId;
}
private PrefixEntry[] _prefixMap = new PrefixEntry[PREFIX_MAP_SIZE];
private PrefixEntry _prefixPool;
private static class NamespaceEntry {
private NamespaceEntry next;
private int declarationId;
private int namespaceIndex;
private String prefix;
private String namespaceName;
private int prefixEntryIndex;
}
private NamespaceEntry _namespacePool;
private NamespaceEntry[] _inScopeNamespaces;
public int[] _currentInScope;
public int _declarationId;
public PrefixArray(int initialCapacity, int maximumCapacity) {
_initialCapacity = initialCapacity;
_maximumCapacity = maximumCapacity;
_array = new String[initialCapacity];
// Sizes of _inScopeNamespaces and _currentInScope need to be two
// greater than _array because 0 represents the empty string and
// 1 represents the xml prefix
_inScopeNamespaces = new NamespaceEntry[initialCapacity + 2];
_currentInScope = new int[initialCapacity + 2];
increaseNamespacePool(initialCapacity);
increasePrefixPool(initialCapacity);
initializeEntries();
}
public PrefixArray() {
this(DEFAULT_CAPACITY, MAXIMUM_CAPACITY);
}
private final void initializeEntries() {
_inScopeNamespaces[0] = _namespacePool;
_namespacePool = _namespacePool.next;
_inScopeNamespaces[0].next = null;
_inScopeNamespaces[0].prefix = "";
_inScopeNamespaces[0].namespaceName = "";
_inScopeNamespaces[0].namespaceIndex = _currentInScope[0] = 0;
int index = KeyIntMap.indexFor(KeyIntMap.hashHash(_inScopeNamespaces[0].prefix.hashCode()), _prefixMap.length);
_prefixMap[index] = _prefixPool;
_prefixPool = _prefixPool.next;
_prefixMap[index].next = null;
_prefixMap[index].prefixId = 0;
_inScopeNamespaces[1] = _namespacePool;
_namespacePool = _namespacePool.next;
_inScopeNamespaces[1].next = null;
_inScopeNamespaces[1].prefix = EncodingConstants.XML_NAMESPACE_PREFIX;
_inScopeNamespaces[1].namespaceName = EncodingConstants.XML_NAMESPACE_NAME;
_inScopeNamespaces[1].namespaceIndex = _currentInScope[1] = 1;
index = KeyIntMap.indexFor(KeyIntMap.hashHash(_inScopeNamespaces[1].prefix.hashCode()), _prefixMap.length);
if (_prefixMap[index] == null) {
_prefixMap[index] = _prefixPool;
_prefixPool = _prefixPool.next;
_prefixMap[index].next = null;
} else {
final PrefixEntry e = _prefixMap[index];
_prefixMap[index] = _prefixPool;
_prefixPool = _prefixPool.next;
_prefixMap[index].next = e;
}
_prefixMap[index].prefixId = 1;
}
private final void increaseNamespacePool(int capacity) {
if (_namespacePool == null) {
_namespacePool = new NamespaceEntry();
}
for (int i = 0; i < capacity; i++) {
NamespaceEntry ne = new NamespaceEntry();
ne.next = _namespacePool;
_namespacePool = ne;
}
}
private final void increasePrefixPool(int capacity) {
if (_prefixPool == null) {
_prefixPool = new PrefixEntry();
}
for (int i = 0; i < capacity; i++) {
PrefixEntry pe = new PrefixEntry();
pe.next = _prefixPool;
_prefixPool = pe;
}
}
public int countNamespacePool() {
int i = 0;
NamespaceEntry e = _namespacePool;
while (e != null) {
i++;
e = e.next;
}
return i;
}
public int countPrefixPool() {
int i = 0;
PrefixEntry e = _prefixPool;
while (e != null) {
i++;
e = e.next;
}
return i;
}
public final void clear() {
for (int i = _readOnlyArraySize; i < _size; i++) {
_array[i] = null;
}
_size = _readOnlyArraySize;
}
public final void clearCompletely() {
_prefixPool = null;
_namespacePool = null;
for (int i = 0; i < _size + 2; i++) {
_currentInScope[i] = 0;
_inScopeNamespaces[i] = null;
}
for (int i = 0; i < _prefixMap.length; i++) {
_prefixMap[i] = null;
}
increaseNamespacePool(_initialCapacity);
increasePrefixPool(_initialCapacity);
initializeEntries();
_declarationId = 0;
clear();
}
/**
* Returns cloned version of internal String[].
* @return cloned version of internal String[].
*/
public final String[] getArray() {
if (_array == null) return null;
final String[] clonedArray = new String[_array.length];
System.arraycopy(_array, 0, clonedArray, 0, _array.length);
return clonedArray;
}
public final void setReadOnlyArray(ValueArray readOnlyArray, boolean clear) {
if (!(readOnlyArray instanceof PrefixArray)) {
throw new IllegalArgumentException(CommonResourceBundle.getInstance().
getString("message.illegalClass", new Object[]{readOnlyArray}));
}
setReadOnlyArray((PrefixArray)readOnlyArray, clear);
}
public final void setReadOnlyArray(PrefixArray readOnlyArray, boolean clear) {
if (readOnlyArray != null) {
_readOnlyArray = readOnlyArray;
_readOnlyArraySize = readOnlyArray.getSize();
clearCompletely();
// Resize according to size of read only arrays
_inScopeNamespaces = new NamespaceEntry[_readOnlyArraySize + _inScopeNamespaces.length];
_currentInScope = new int[_readOnlyArraySize + _currentInScope.length];
// Intialize first two entries
initializeEntries();
if (clear) {
clear();
}
_array = getCompleteArray();
_size = _readOnlyArraySize;
}
}
public final String[] getCompleteArray() {
if (_readOnlyArray == null) {
// Return cloned version of internal _array
return getArray();
// return _array;
} else {
final String[] ra = _readOnlyArray.getCompleteArray();
final String[] a = new String[_readOnlyArraySize + _array.length];
System.arraycopy(ra, 0, a, 0, _readOnlyArraySize);
return a;
}
}
public final String get(int i) {
return _array[i];
}
public final int add(String s) {
if (_size == _array.length) {
resize();
}
_array[_size++] = s;
return _size;
}
protected final void resize() {
if (_size == _maximumCapacity) {
throw new ValueArrayResourceException(CommonResourceBundle.getInstance().getString("message.arrayMaxCapacity"));
}
int newSize = _size * 3 / 2 + 1;
if (newSize > _maximumCapacity) {
newSize = _maximumCapacity;
}
final String[] newArray = new String[newSize];
System.arraycopy(_array, 0, newArray, 0, _size);
_array = newArray;
newSize += 2;
final NamespaceEntry[] newInScopeNamespaces = new NamespaceEntry[newSize];
System.arraycopy(_inScopeNamespaces, 0, newInScopeNamespaces, 0, _inScopeNamespaces.length);
_inScopeNamespaces = newInScopeNamespaces;
final int[] newCurrentInScope = new int[newSize];
System.arraycopy(_currentInScope, 0, newCurrentInScope, 0, _currentInScope.length);
_currentInScope = newCurrentInScope;
}
public final void clearDeclarationIds() {
for (int i = 0; i < _size; i++) {
final NamespaceEntry e = _inScopeNamespaces[i];
if (e != null) {
e.declarationId = 0;
}
}
_declarationId = 1;
}
public final void pushScope(int prefixIndex, int namespaceIndex) throws FastInfosetException {
if (_namespacePool == null) {
increaseNamespacePool(16);
}
final NamespaceEntry e = _namespacePool;
_namespacePool = e.next;
final NamespaceEntry current = _inScopeNamespaces[++prefixIndex];
if (current == null) {
e.declarationId = _declarationId;
e.namespaceIndex = _currentInScope[prefixIndex] = ++namespaceIndex;
e.next = null;
_inScopeNamespaces[prefixIndex] = e;
} else if (current.declarationId < _declarationId) {
e.declarationId = _declarationId;
e.namespaceIndex = _currentInScope[prefixIndex] = ++namespaceIndex;
e.next = current;
current.declarationId = 0;
_inScopeNamespaces[prefixIndex] = e;
} else {
throw new FastInfosetException(CommonResourceBundle.getInstance().getString("message.duplicateNamespaceAttribute"));
}
}
public final void pushScopeWithPrefixEntry(String prefix, String namespaceName,
int prefixIndex, int namespaceIndex) throws FastInfosetException {
if (_namespacePool == null) {
increaseNamespacePool(16);
}
if (_prefixPool == null) {
increasePrefixPool(16);
}
final NamespaceEntry e = _namespacePool;
_namespacePool = e.next;
final NamespaceEntry current = _inScopeNamespaces[++prefixIndex];
if (current == null) {
e.declarationId = _declarationId;
e.namespaceIndex = _currentInScope[prefixIndex] = ++namespaceIndex;
e.next = null;
_inScopeNamespaces[prefixIndex] = e;
} else if (current.declarationId < _declarationId) {
e.declarationId = _declarationId;
e.namespaceIndex = _currentInScope[prefixIndex] = ++namespaceIndex;
e.next = current;
current.declarationId = 0;
_inScopeNamespaces[prefixIndex] = e;
} else {
throw new FastInfosetException(CommonResourceBundle.getInstance().getString("message.duplicateNamespaceAttribute"));
}
final PrefixEntry p = _prefixPool;
_prefixPool = _prefixPool.next;
p.prefixId = prefixIndex;
e.prefix = prefix;
e.namespaceName = namespaceName;
e.prefixEntryIndex = KeyIntMap.indexFor(KeyIntMap.hashHash(prefix.hashCode()), _prefixMap.length);
final PrefixEntry pCurrent = _prefixMap[e.prefixEntryIndex];
p.next = pCurrent;
_prefixMap[e.prefixEntryIndex] = p;
}
public final void popScope(int prefixIndex) {
final NamespaceEntry e = _inScopeNamespaces[++prefixIndex];
_inScopeNamespaces[prefixIndex] = e.next;
_currentInScope[prefixIndex] = (e.next != null) ? e.next.namespaceIndex : 0;
e.next = _namespacePool;
_namespacePool = e;
}
public final void popScopeWithPrefixEntry(int prefixIndex) {
final NamespaceEntry e = _inScopeNamespaces[++prefixIndex];
_inScopeNamespaces[prefixIndex] = e.next;
_currentInScope[prefixIndex] = (e.next != null) ? e.next.namespaceIndex : 0;
e.prefix = e.namespaceName = null;
e.next = _namespacePool;
_namespacePool = e;
PrefixEntry current = _prefixMap[e.prefixEntryIndex];
if (current.prefixId == prefixIndex) {
_prefixMap[e.prefixEntryIndex] = current.next;
current.next = _prefixPool;
_prefixPool = current;
} else {
PrefixEntry prev = current;
current = current.next;
while (current != null) {
if (current.prefixId == prefixIndex) {
prev.next = current.next;
current.next = _prefixPool;
_prefixPool = current;
break;
}
prev = current;
current = current.next;
}
}
}
public final String getNamespaceFromPrefix(String prefix) {
final int index = KeyIntMap.indexFor(KeyIntMap.hashHash(prefix.hashCode()), _prefixMap.length);
PrefixEntry pe = _prefixMap[index];
while (pe != null) {
final NamespaceEntry ne = _inScopeNamespaces[pe.prefixId];
if (prefix == ne.prefix || prefix.equals(ne.prefix)) {
return ne.namespaceName;
}
pe = pe.next;
}
return null;
}
public final String getPrefixFromNamespace(String namespaceName) {
int position = 0;
while (++position < _size + 2) {
final NamespaceEntry ne = _inScopeNamespaces[position];
if (ne != null && namespaceName.equals(ne.namespaceName)) {
return ne.prefix;
}
}
return null;
}
public final Iterator getPrefixes() {
return new Iterator() {
int _position = 1;
NamespaceEntry _ne = _inScopeNamespaces[_position];
public boolean hasNext() {
return _ne != null;
}
public Object next() {
if (_position == _size + 2) {
throw new NoSuchElementException();
}
final String prefix = _ne.prefix;
moveToNext();
return prefix;
}
public void remove() {
throw new UnsupportedOperationException();
}
private final void moveToNext() {
while (++_position < _size + 2) {
_ne = _inScopeNamespaces[_position];
if (_ne != null) {
return;
}
}
_ne = null;
}
};
}
public final Iterator getPrefixesFromNamespace(final String namespaceName) {
return new Iterator() {
String _namespaceName = namespaceName;
int _position = 0;
NamespaceEntry _ne;
{
moveToNext();
}
public boolean hasNext() {
return _ne != null;
}
public Object next() {
if (_position == _size + 2) {
throw new NoSuchElementException();
}
final String prefix = _ne.prefix;
moveToNext();
return prefix;
}
public void remove() {
throw new UnsupportedOperationException();
}
private final void moveToNext() {
while (++_position < _size + 2) {
_ne = _inScopeNamespaces[_position];
if (_ne != null && _namespaceName.equals(_ne.namespaceName)) {
return;
}
}
_ne = null;
}
};
}
}

View File

@@ -0,0 +1,127 @@
/*
* Copyright (c) 2004, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*
* THIS FILE WAS MODIFIED BY SUN MICROSYSTEMS, INC.
*/
package com.sun.xml.internal.fastinfoset.util;
import com.sun.xml.internal.fastinfoset.QualifiedName;
import com.sun.xml.internal.fastinfoset.CommonResourceBundle;
public class QualifiedNameArray extends ValueArray {
public QualifiedName[] _array;
private QualifiedNameArray _readOnlyArray;
public QualifiedNameArray(int initialCapacity, int maximumCapacity) {
_array = new QualifiedName[initialCapacity];
_maximumCapacity = maximumCapacity;
}
public QualifiedNameArray() {
this(DEFAULT_CAPACITY, MAXIMUM_CAPACITY);
}
public final void clear() {
_size = _readOnlyArraySize;
}
/**
* Returns cloned version of internal QualifiedName[].
* @return cloned version of internal QualifiedName[].
*/
public final QualifiedName[] getArray() {
if (_array == null) return null;
final QualifiedName[] clonedArray = new QualifiedName[_array.length];
System.arraycopy(_array, 0, clonedArray, 0, _array.length);
return clonedArray;
}
public final void setReadOnlyArray(ValueArray readOnlyArray, boolean clear) {
if (!(readOnlyArray instanceof QualifiedNameArray)) {
throw new IllegalArgumentException(CommonResourceBundle.getInstance().
getString("message.illegalClass", new Object[]{readOnlyArray}));
}
setReadOnlyArray((QualifiedNameArray)readOnlyArray, clear);
}
public final void setReadOnlyArray(QualifiedNameArray readOnlyArray, boolean clear) {
if (readOnlyArray != null) {
_readOnlyArray = readOnlyArray;
_readOnlyArraySize = readOnlyArray.getSize();
if (clear) {
clear();
}
_array = getCompleteArray();
_size = _readOnlyArraySize;
}
}
public final QualifiedName[] getCompleteArray() {
if (_readOnlyArray == null) {
// Return cloned version of internal _array
return getArray();
// return _array;
} else {
final QualifiedName[] ra = _readOnlyArray.getCompleteArray();
final QualifiedName[] a = new QualifiedName[_readOnlyArraySize + _array.length];
System.arraycopy(ra, 0, a, 0, _readOnlyArraySize);
return a;
}
}
public final QualifiedName getNext() {
return (_size == _array.length) ? null : _array[_size];
}
public final void add(QualifiedName s) {
if (_size == _array.length) {
resize();
}
_array[_size++] = s;
}
protected final void resize() {
if (_size == _maximumCapacity) {
throw new ValueArrayResourceException(CommonResourceBundle.getInstance().getString("message.arrayMaxCapacity"));
}
int newSize = _size * 3 / 2 + 1;
if (newSize > _maximumCapacity) {
newSize = _maximumCapacity;
}
final QualifiedName[] newArray = new QualifiedName[newSize];
System.arraycopy(_array, 0, newArray, 0, _size);
_array = newArray;
}
}

View File

@@ -0,0 +1,131 @@
/*
* Copyright (c) 2004, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*
* THIS FILE WAS MODIFIED BY SUN MICROSYSTEMS, INC.
*/
package com.sun.xml.internal.fastinfoset.util;
import com.sun.xml.internal.fastinfoset.CommonResourceBundle;
public class StringArray extends ValueArray {
public String[] _array;
private StringArray _readOnlyArray;
private boolean _clear;
public StringArray(int initialCapacity, int maximumCapacity, boolean clear) {
_array = new String[initialCapacity];
_maximumCapacity = maximumCapacity;
_clear = clear;
}
public StringArray() {
this(DEFAULT_CAPACITY, MAXIMUM_CAPACITY, false);
}
public final void clear() {
if (_clear) for (int i = _readOnlyArraySize; i < _size; i++) {
_array[i] = null;
}
_size = _readOnlyArraySize;
}
/**
* Returns cloned version of internal String[].
* @return cloned version of internal String[].
*/
public final String[] getArray() {
if (_array == null) return null;
final String[] clonedArray = new String[_array.length];
System.arraycopy(_array, 0, clonedArray, 0, _array.length);
return clonedArray;
}
public final void setReadOnlyArray(ValueArray readOnlyArray, boolean clear) {
if (!(readOnlyArray instanceof StringArray)) {
throw new IllegalArgumentException(CommonResourceBundle.getInstance().
getString("message.illegalClass", new Object[]{readOnlyArray}));
}
setReadOnlyArray((StringArray)readOnlyArray, clear);
}
public final void setReadOnlyArray(StringArray readOnlyArray, boolean clear) {
if (readOnlyArray != null) {
_readOnlyArray = readOnlyArray;
_readOnlyArraySize = readOnlyArray.getSize();
if (clear) {
clear();
}
_array = getCompleteArray();
_size = _readOnlyArraySize;
}
}
public final String[] getCompleteArray() {
if (_readOnlyArray == null) {
// Return cloned version of internal _array
return getArray();
// return _array;
} else {
final String[] ra = _readOnlyArray.getCompleteArray();
final String[] a = new String[_readOnlyArraySize + _array.length];
System.arraycopy(ra, 0, a, 0, _readOnlyArraySize);
return a;
}
}
public final String get(int i) {
return _array[i];
}
public final int add(String s) {
if (_size == _array.length) {
resize();
}
_array[_size++] = s;
return _size;
}
protected final void resize() {
if (_size == _maximumCapacity) {
throw new ValueArrayResourceException(CommonResourceBundle.getInstance().getString("message.arrayMaxCapacity"));
}
int newSize = _size * 3 / 2 + 1;
if (newSize > _maximumCapacity) {
newSize = _maximumCapacity;
}
final String[] newArray = new String[newSize];
System.arraycopy(_array, 0, newArray, 0, _size);
_array = newArray;
}
}

View File

@@ -0,0 +1,216 @@
/*
* Copyright (c) 2004, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*
* THIS FILE WAS MODIFIED BY SUN MICROSYSTEMS, INC.
*/
package com.sun.xml.internal.fastinfoset.util;
import com.sun.xml.internal.fastinfoset.CommonResourceBundle;
public class StringIntMap extends KeyIntMap {
protected static final Entry NULL_ENTRY = new Entry(null, 0, -1, null);
protected StringIntMap _readOnlyMap;
protected static class Entry extends BaseEntry {
final String _key;
Entry _next;
public Entry(String key, int hash, int value, Entry next) {
super(hash, value);
_key = key;
_next = next;
}
}
protected Entry _lastEntry = NULL_ENTRY;
protected Entry[] _table;
protected int _index;
// Total character count of Map
protected int _totalCharacterCount;
public StringIntMap(int initialCapacity, float loadFactor) {
super(initialCapacity, loadFactor);
_table = new Entry[_capacity];
}
public StringIntMap(int initialCapacity) {
this(initialCapacity, DEFAULT_LOAD_FACTOR);
}
public StringIntMap() {
this(DEFAULT_INITIAL_CAPACITY, DEFAULT_LOAD_FACTOR);
}
public void clear() {
for (int i = 0; i < _table.length; i++) {
_table[i] = null;
}
_lastEntry = NULL_ENTRY;
_size = 0;
_index = _readOnlyMapSize;
_totalCharacterCount = 0;
}
public void setReadOnlyMap(KeyIntMap readOnlyMap, boolean clear) {
if (!(readOnlyMap instanceof StringIntMap)) {
throw new IllegalArgumentException(CommonResourceBundle.getInstance().
getString("message.illegalClass", new Object[]{readOnlyMap}));
}
setReadOnlyMap((StringIntMap)readOnlyMap, clear);
}
public final void setReadOnlyMap(StringIntMap readOnlyMap, boolean clear) {
_readOnlyMap = readOnlyMap;
if (_readOnlyMap != null) {
_readOnlyMapSize = _readOnlyMap.size();
_index = _size + _readOnlyMapSize;
if (clear) {
clear();
}
} else {
_readOnlyMapSize = 0;
_index = _size;
}
}
public final int getNextIndex() {
return _index++;
}
public final int getIndex() {
return _index;
}
public final int obtainIndex(String key) {
final int hash = hashHash(key.hashCode());
if (_readOnlyMap != null) {
final int index = _readOnlyMap.get(key, hash);
if (index != -1) {
return index;
}
}
final int tableIndex = indexFor(hash, _table.length);
for (Entry e = _table[tableIndex]; e != null; e = e._next) {
if (e._hash == hash && eq(key, e._key)) {
return e._value;
}
}
addEntry(key, hash, tableIndex);
return NOT_PRESENT;
}
public final void add(String key) {
final int hash = hashHash(key.hashCode());
final int tableIndex = indexFor(hash, _table.length);
addEntry(key, hash, tableIndex);
}
public final int get(String key) {
if (key == _lastEntry._key)
return _lastEntry._value;
return get(key, hashHash(key.hashCode()));
}
public final int getTotalCharacterCount() {
return _totalCharacterCount;
}
private final int get(String key, int hash) {
if (_readOnlyMap != null) {
final int i = _readOnlyMap.get(key, hash);
if (i != -1) {
return i;
}
}
final int tableIndex = indexFor(hash, _table.length);
for (Entry e = _table[tableIndex]; e != null; e = e._next) {
if (e._hash == hash && eq(key, e._key)) {
_lastEntry = e;
return e._value;
}
}
return NOT_PRESENT;
}
private final void addEntry(String key, int hash, int bucketIndex) {
Entry e = _table[bucketIndex];
_table[bucketIndex] = new Entry(key, hash, _index++, e);
_totalCharacterCount += key.length();
if (_size++ >= _threshold) {
resize(2 * _table.length);
}
}
protected final void resize(int newCapacity) {
_capacity = newCapacity;
Entry[] oldTable = _table;
int oldCapacity = oldTable.length;
if (oldCapacity == MAXIMUM_CAPACITY) {
_threshold = Integer.MAX_VALUE;
return;
}
Entry[] newTable = new Entry[_capacity];
transfer(newTable);
_table = newTable;
_threshold = (int)(_capacity * _loadFactor);
}
private final void transfer(Entry[] newTable) {
Entry[] src = _table;
int newCapacity = newTable.length;
for (int j = 0; j < src.length; j++) {
Entry e = src[j];
if (e != null) {
src[j] = null;
do {
Entry next = e._next;
int i = indexFor(e._hash, newCapacity);
e._next = newTable[i];
newTable[i] = e;
e = next;
} while (e != null);
}
}
}
private final boolean eq(String x, String y) {
return x == y || x.equals(y);
}
}

View File

@@ -0,0 +1,55 @@
/*
* Copyright (c) 2004, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*
* THIS FILE WAS MODIFIED BY SUN MICROSYSTEMS, INC.
*/
package com.sun.xml.internal.fastinfoset.util;
public abstract class ValueArray {
public static final int DEFAULT_CAPACITY = 10;
public static final int MAXIMUM_CAPACITY = Integer.MAX_VALUE;
protected int _size;
protected int _readOnlyArraySize;
protected int _maximumCapacity;
public int getSize() {
return _size;
}
public int getMaximumCapacity() {
return _maximumCapacity;
}
public void setMaximumCapacity(int maximumCapacity) {
_maximumCapacity = maximumCapacity;
}
public abstract void setReadOnlyArray(ValueArray array, boolean clear);
public abstract void clear();
}

View File

@@ -0,0 +1,38 @@
/*
* Copyright (c) 2004, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*
* THIS FILE WAS MODIFIED BY SUN MICROSYSTEMS, INC.
*/
package com.sun.xml.internal.fastinfoset.util;
public class ValueArrayResourceException extends RuntimeException {
public ValueArrayResourceException() {
}
public ValueArrayResourceException(String message) {
super(message);
}
}