1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/src/share/jaxws_classes/com/sun/xml/internal/fastinfoset/util/QualifiedNameArray.java Tue Mar 06 16:09:35 2012 -0800 1.3 @@ -0,0 +1,127 @@ 1.4 +/* 1.5 + * Copyright (c) 2004, 2011, Oracle and/or its affiliates. All rights reserved. 1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 1.7 + * 1.8 + * This code is free software; you can redistribute it and/or modify it 1.9 + * under the terms of the GNU General Public License version 2 only, as 1.10 + * published by the Free Software Foundation. Oracle designates this 1.11 + * particular file as subject to the "Classpath" exception as provided 1.12 + * by Oracle in the LICENSE file that accompanied this code. 1.13 + * 1.14 + * This code is distributed in the hope that it will be useful, but WITHOUT 1.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 1.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 1.17 + * version 2 for more details (a copy is included in the LICENSE file that 1.18 + * accompanied this code). 1.19 + * 1.20 + * You should have received a copy of the GNU General Public License version 1.21 + * 2 along with this work; if not, write to the Free Software Foundation, 1.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 1.23 + * 1.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 1.25 + * or visit www.oracle.com if you need additional information or have any 1.26 + * questions. 1.27 + * 1.28 + * THIS FILE WAS MODIFIED BY SUN MICROSYSTEMS, INC. 1.29 + */ 1.30 + 1.31 +package com.sun.xml.internal.fastinfoset.util; 1.32 + 1.33 +import com.sun.xml.internal.fastinfoset.QualifiedName; 1.34 +import com.sun.xml.internal.fastinfoset.CommonResourceBundle; 1.35 + 1.36 +public class QualifiedNameArray extends ValueArray { 1.37 + 1.38 + public QualifiedName[] _array; 1.39 + 1.40 + private QualifiedNameArray _readOnlyArray; 1.41 + 1.42 + public QualifiedNameArray(int initialCapacity, int maximumCapacity) { 1.43 + _array = new QualifiedName[initialCapacity]; 1.44 + _maximumCapacity = maximumCapacity; 1.45 + } 1.46 + 1.47 + public QualifiedNameArray() { 1.48 + this(DEFAULT_CAPACITY, MAXIMUM_CAPACITY); 1.49 + } 1.50 + 1.51 + public final void clear() { 1.52 + _size = _readOnlyArraySize; 1.53 + } 1.54 + 1.55 + /** 1.56 + * Returns cloned version of internal QualifiedName[]. 1.57 + * @return cloned version of internal QualifiedName[]. 1.58 + */ 1.59 + public final QualifiedName[] getArray() { 1.60 + if (_array == null) return null; 1.61 + 1.62 + final QualifiedName[] clonedArray = new QualifiedName[_array.length]; 1.63 + System.arraycopy(_array, 0, clonedArray, 0, _array.length); 1.64 + return clonedArray; 1.65 + } 1.66 + 1.67 + public final void setReadOnlyArray(ValueArray readOnlyArray, boolean clear) { 1.68 + if (!(readOnlyArray instanceof QualifiedNameArray)) { 1.69 + throw new IllegalArgumentException(CommonResourceBundle.getInstance(). 1.70 + getString("message.illegalClass", new Object[]{readOnlyArray})); 1.71 + } 1.72 + 1.73 + setReadOnlyArray((QualifiedNameArray)readOnlyArray, clear); 1.74 + } 1.75 + 1.76 + public final void setReadOnlyArray(QualifiedNameArray readOnlyArray, boolean clear) { 1.77 + if (readOnlyArray != null) { 1.78 + _readOnlyArray = readOnlyArray; 1.79 + _readOnlyArraySize = readOnlyArray.getSize(); 1.80 + 1.81 + if (clear) { 1.82 + clear(); 1.83 + } 1.84 + 1.85 + _array = getCompleteArray(); 1.86 + _size = _readOnlyArraySize; 1.87 + } 1.88 + } 1.89 + 1.90 + public final QualifiedName[] getCompleteArray() { 1.91 + if (_readOnlyArray == null) { 1.92 + // Return cloned version of internal _array 1.93 + return getArray(); 1.94 +// return _array; 1.95 + } else { 1.96 + final QualifiedName[] ra = _readOnlyArray.getCompleteArray(); 1.97 + final QualifiedName[] a = new QualifiedName[_readOnlyArraySize + _array.length]; 1.98 + System.arraycopy(ra, 0, a, 0, _readOnlyArraySize); 1.99 + return a; 1.100 + } 1.101 + } 1.102 + 1.103 + public final QualifiedName getNext() { 1.104 + return (_size == _array.length) ? null : _array[_size]; 1.105 + } 1.106 + 1.107 + public final void add(QualifiedName s) { 1.108 + if (_size == _array.length) { 1.109 + resize(); 1.110 + } 1.111 + 1.112 + _array[_size++] = s; 1.113 + } 1.114 + 1.115 + protected final void resize() { 1.116 + if (_size == _maximumCapacity) { 1.117 + throw new ValueArrayResourceException(CommonResourceBundle.getInstance().getString("message.arrayMaxCapacity")); 1.118 + } 1.119 + 1.120 + int newSize = _size * 3 / 2 + 1; 1.121 + if (newSize > _maximumCapacity) { 1.122 + newSize = _maximumCapacity; 1.123 + } 1.124 + 1.125 + final QualifiedName[] newArray = new QualifiedName[newSize]; 1.126 + System.arraycopy(_array, 0, newArray, 0, _size); 1.127 + _array = newArray; 1.128 + } 1.129 + 1.130 +}