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 | import com.sun.xml.internal.fastinfoset.CommonResourceBundle; |
aoqi@0 | 30 | |
aoqi@0 | 31 | public class ContiguousCharArrayArray extends ValueArray { |
aoqi@0 | 32 | public static final int INITIAL_CHARACTER_SIZE = 512; |
aoqi@0 | 33 | public static final int MAXIMUM_CHARACTER_SIZE = Integer.MAX_VALUE; |
aoqi@0 | 34 | |
aoqi@0 | 35 | protected int _maximumCharacterSize; |
aoqi@0 | 36 | |
aoqi@0 | 37 | public int[] _offset; |
aoqi@0 | 38 | public int[] _length; |
aoqi@0 | 39 | |
aoqi@0 | 40 | public char[] _array; |
aoqi@0 | 41 | public int _arrayIndex; |
aoqi@0 | 42 | public int _readOnlyArrayIndex; |
aoqi@0 | 43 | |
aoqi@0 | 44 | private String[] _cachedStrings; |
aoqi@0 | 45 | |
aoqi@0 | 46 | public int _cachedIndex; |
aoqi@0 | 47 | |
aoqi@0 | 48 | private ContiguousCharArrayArray _readOnlyArray; |
aoqi@0 | 49 | |
aoqi@0 | 50 | public ContiguousCharArrayArray(int initialCapacity, int maximumCapacity, |
aoqi@0 | 51 | int initialCharacterSize, int maximumCharacterSize) { |
aoqi@0 | 52 | _offset = new int[initialCapacity]; |
aoqi@0 | 53 | _length = new int[initialCapacity]; |
aoqi@0 | 54 | _array = new char[initialCharacterSize]; |
aoqi@0 | 55 | _maximumCapacity = maximumCapacity; |
aoqi@0 | 56 | _maximumCharacterSize = maximumCharacterSize; |
aoqi@0 | 57 | } |
aoqi@0 | 58 | |
aoqi@0 | 59 | public ContiguousCharArrayArray() { |
aoqi@0 | 60 | this(DEFAULT_CAPACITY, MAXIMUM_CAPACITY, |
aoqi@0 | 61 | INITIAL_CHARACTER_SIZE, MAXIMUM_CHARACTER_SIZE); |
aoqi@0 | 62 | } |
aoqi@0 | 63 | |
aoqi@0 | 64 | public final void clear() { |
aoqi@0 | 65 | _arrayIndex = _readOnlyArrayIndex; |
aoqi@0 | 66 | _size = _readOnlyArraySize; |
aoqi@0 | 67 | |
aoqi@0 | 68 | if (_cachedStrings != null) { |
aoqi@0 | 69 | for (int i = _readOnlyArraySize; i < _cachedStrings.length; i++) { |
aoqi@0 | 70 | _cachedStrings[i] = null; |
aoqi@0 | 71 | } |
aoqi@0 | 72 | } |
aoqi@0 | 73 | } |
aoqi@0 | 74 | |
aoqi@0 | 75 | public final int getArrayIndex() { |
aoqi@0 | 76 | return _arrayIndex; |
aoqi@0 | 77 | } |
aoqi@0 | 78 | |
aoqi@0 | 79 | public final void setReadOnlyArray(ValueArray readOnlyArray, boolean clear) { |
aoqi@0 | 80 | if (!(readOnlyArray instanceof ContiguousCharArrayArray)) { |
aoqi@0 | 81 | throw new IllegalArgumentException(CommonResourceBundle.getInstance().getString("message.illegalClass", new Object[]{readOnlyArray})); |
aoqi@0 | 82 | } |
aoqi@0 | 83 | |
aoqi@0 | 84 | setReadOnlyArray((ContiguousCharArrayArray)readOnlyArray, clear); |
aoqi@0 | 85 | } |
aoqi@0 | 86 | |
aoqi@0 | 87 | public final void setReadOnlyArray(ContiguousCharArrayArray readOnlyArray, boolean clear) { |
aoqi@0 | 88 | if (readOnlyArray != null) { |
aoqi@0 | 89 | _readOnlyArray = readOnlyArray; |
aoqi@0 | 90 | _readOnlyArraySize = readOnlyArray.getSize(); |
aoqi@0 | 91 | _readOnlyArrayIndex = readOnlyArray.getArrayIndex(); |
aoqi@0 | 92 | |
aoqi@0 | 93 | if (clear) { |
aoqi@0 | 94 | clear(); |
aoqi@0 | 95 | } |
aoqi@0 | 96 | |
aoqi@0 | 97 | _array = getCompleteCharArray(); |
aoqi@0 | 98 | _offset = getCompleteOffsetArray(); |
aoqi@0 | 99 | _length = getCompleteLengthArray(); |
aoqi@0 | 100 | _size = _readOnlyArraySize; |
aoqi@0 | 101 | _arrayIndex = _readOnlyArrayIndex; |
aoqi@0 | 102 | } |
aoqi@0 | 103 | } |
aoqi@0 | 104 | |
aoqi@0 | 105 | public final char[] getCompleteCharArray() { |
aoqi@0 | 106 | if (_readOnlyArray == null) { |
aoqi@0 | 107 | if (_array == null) return null; |
aoqi@0 | 108 | |
aoqi@0 | 109 | // Return cloned version of internal _array |
aoqi@0 | 110 | final char[] clonedArray = new char[_array.length]; |
aoqi@0 | 111 | System.arraycopy(_array, 0, clonedArray, 0, _array.length); |
aoqi@0 | 112 | return clonedArray; |
aoqi@0 | 113 | // return _array; |
aoqi@0 | 114 | } else { |
aoqi@0 | 115 | final char[] ra = _readOnlyArray.getCompleteCharArray(); |
aoqi@0 | 116 | final char[] a = new char[_readOnlyArrayIndex + _array.length]; |
aoqi@0 | 117 | System.arraycopy(ra, 0, a, 0, _readOnlyArrayIndex); |
aoqi@0 | 118 | return a; |
aoqi@0 | 119 | } |
aoqi@0 | 120 | } |
aoqi@0 | 121 | |
aoqi@0 | 122 | public final int[] getCompleteOffsetArray() { |
aoqi@0 | 123 | if (_readOnlyArray == null) { |
aoqi@0 | 124 | if (_offset == null) return null; |
aoqi@0 | 125 | |
aoqi@0 | 126 | // Return cloned version of internal _offset |
aoqi@0 | 127 | final int[] clonedArray = new int[_offset.length]; |
aoqi@0 | 128 | System.arraycopy(_offset, 0, clonedArray, 0, _offset.length); |
aoqi@0 | 129 | return clonedArray; |
aoqi@0 | 130 | // return _offset; |
aoqi@0 | 131 | } else { |
aoqi@0 | 132 | final int[] ra = _readOnlyArray.getCompleteOffsetArray(); |
aoqi@0 | 133 | final int[] a = new int[_readOnlyArraySize + _offset.length]; |
aoqi@0 | 134 | System.arraycopy(ra, 0, a, 0, _readOnlyArraySize); |
aoqi@0 | 135 | return a; |
aoqi@0 | 136 | } |
aoqi@0 | 137 | } |
aoqi@0 | 138 | |
aoqi@0 | 139 | public final int[] getCompleteLengthArray() { |
aoqi@0 | 140 | if (_readOnlyArray == null) { |
aoqi@0 | 141 | if (_length == null) return null; |
aoqi@0 | 142 | |
aoqi@0 | 143 | // Return cloned version of internal _length |
aoqi@0 | 144 | final int[] clonedArray = new int[_length.length]; |
aoqi@0 | 145 | System.arraycopy(_length, 0, clonedArray, 0, _length.length); |
aoqi@0 | 146 | return clonedArray; |
aoqi@0 | 147 | // return _length; |
aoqi@0 | 148 | } else { |
aoqi@0 | 149 | final int[] ra = _readOnlyArray.getCompleteLengthArray(); |
aoqi@0 | 150 | final int[] a = new int[_readOnlyArraySize + _length.length]; |
aoqi@0 | 151 | System.arraycopy(ra, 0, a, 0, _readOnlyArraySize); |
aoqi@0 | 152 | return a; |
aoqi@0 | 153 | } |
aoqi@0 | 154 | } |
aoqi@0 | 155 | |
aoqi@0 | 156 | public final String getString(int i) { |
aoqi@0 | 157 | if (_cachedStrings != null && i < _cachedStrings.length) { |
aoqi@0 | 158 | final String s = _cachedStrings[i]; |
aoqi@0 | 159 | return (s != null) ? s : (_cachedStrings[i] = new String(_array, _offset[i], _length[i])); |
aoqi@0 | 160 | } |
aoqi@0 | 161 | |
aoqi@0 | 162 | final String[] newCachedStrings = new String[_offset.length]; |
aoqi@0 | 163 | if (_cachedStrings != null && i >= _cachedStrings.length) { |
aoqi@0 | 164 | System.arraycopy(_cachedStrings, 0, newCachedStrings, 0, _cachedStrings.length); |
aoqi@0 | 165 | } |
aoqi@0 | 166 | _cachedStrings = newCachedStrings; |
aoqi@0 | 167 | |
aoqi@0 | 168 | return _cachedStrings[i] = new String(_array, _offset[i], _length[i]); |
aoqi@0 | 169 | } |
aoqi@0 | 170 | |
aoqi@0 | 171 | public final void ensureSize(int l) { |
aoqi@0 | 172 | if (_arrayIndex + l >= _array.length) { |
aoqi@0 | 173 | resizeArray(_arrayIndex + l); |
aoqi@0 | 174 | } |
aoqi@0 | 175 | } |
aoqi@0 | 176 | |
aoqi@0 | 177 | public final void add(int l) { |
aoqi@0 | 178 | if (_size == _offset.length) { |
aoqi@0 | 179 | resize(); |
aoqi@0 | 180 | } |
aoqi@0 | 181 | |
aoqi@0 | 182 | _cachedIndex = _size; |
aoqi@0 | 183 | _offset[_size] = _arrayIndex; |
aoqi@0 | 184 | _length[_size++] = l; |
aoqi@0 | 185 | |
aoqi@0 | 186 | _arrayIndex += l; |
aoqi@0 | 187 | } |
aoqi@0 | 188 | |
aoqi@0 | 189 | public final int add(char[] c, int l) { |
aoqi@0 | 190 | if (_size == _offset.length) { |
aoqi@0 | 191 | resize(); |
aoqi@0 | 192 | } |
aoqi@0 | 193 | |
aoqi@0 | 194 | final int oldArrayIndex = _arrayIndex; |
aoqi@0 | 195 | final int arrayIndex = oldArrayIndex + l; |
aoqi@0 | 196 | |
aoqi@0 | 197 | _cachedIndex = _size; |
aoqi@0 | 198 | _offset[_size] = oldArrayIndex; |
aoqi@0 | 199 | _length[_size++] = l; |
aoqi@0 | 200 | |
aoqi@0 | 201 | if (arrayIndex >= _array.length) { |
aoqi@0 | 202 | resizeArray(arrayIndex); |
aoqi@0 | 203 | } |
aoqi@0 | 204 | |
aoqi@0 | 205 | System.arraycopy(c, 0, _array, oldArrayIndex, l); |
aoqi@0 | 206 | |
aoqi@0 | 207 | _arrayIndex = arrayIndex; |
aoqi@0 | 208 | return oldArrayIndex; |
aoqi@0 | 209 | } |
aoqi@0 | 210 | |
aoqi@0 | 211 | protected final void resize() { |
aoqi@0 | 212 | if (_size == _maximumCapacity) { |
aoqi@0 | 213 | throw new ValueArrayResourceException(CommonResourceBundle.getInstance().getString("message.arrayMaxCapacity")); |
aoqi@0 | 214 | } |
aoqi@0 | 215 | |
aoqi@0 | 216 | int newSize = _size * 3 / 2 + 1; |
aoqi@0 | 217 | if (newSize > _maximumCapacity) { |
aoqi@0 | 218 | newSize = _maximumCapacity; |
aoqi@0 | 219 | } |
aoqi@0 | 220 | |
aoqi@0 | 221 | final int[] offset = new int[newSize]; |
aoqi@0 | 222 | System.arraycopy(_offset, 0, offset, 0, _size); |
aoqi@0 | 223 | _offset = offset; |
aoqi@0 | 224 | |
aoqi@0 | 225 | final int[] length = new int[newSize]; |
aoqi@0 | 226 | System.arraycopy(_length, 0, length, 0, _size); |
aoqi@0 | 227 | _length = length; |
aoqi@0 | 228 | } |
aoqi@0 | 229 | |
aoqi@0 | 230 | protected final void resizeArray(int requestedSize) { |
aoqi@0 | 231 | if (_arrayIndex == _maximumCharacterSize) { |
aoqi@0 | 232 | throw new ValueArrayResourceException(CommonResourceBundle.getInstance().getString("message.maxNumberOfCharacters")); |
aoqi@0 | 233 | } |
aoqi@0 | 234 | |
aoqi@0 | 235 | int newSize = requestedSize * 3 / 2 + 1; |
aoqi@0 | 236 | if (newSize > _maximumCharacterSize) { |
aoqi@0 | 237 | newSize = _maximumCharacterSize; |
aoqi@0 | 238 | } |
aoqi@0 | 239 | |
aoqi@0 | 240 | final char[] array = new char[newSize]; |
aoqi@0 | 241 | System.arraycopy(_array, 0, array, 0, _arrayIndex); |
aoqi@0 | 242 | _array = array; |
aoqi@0 | 243 | } |
aoqi@0 | 244 | } |