|
1 /* |
|
2 * Copyright (c) 2004, 2011, Oracle and/or its affiliates. All rights reserved. |
|
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
|
4 * |
|
5 * This code is free software; you can redistribute it and/or modify it |
|
6 * under the terms of the GNU General Public License version 2 only, as |
|
7 * published by the Free Software Foundation. Oracle designates this |
|
8 * particular file as subject to the "Classpath" exception as provided |
|
9 * by Oracle in the LICENSE file that accompanied this code. |
|
10 * |
|
11 * This code is distributed in the hope that it will be useful, but WITHOUT |
|
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
14 * version 2 for more details (a copy is included in the LICENSE file that |
|
15 * accompanied this code). |
|
16 * |
|
17 * You should have received a copy of the GNU General Public License version |
|
18 * 2 along with this work; if not, write to the Free Software Foundation, |
|
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
20 * |
|
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
|
22 * or visit www.oracle.com if you need additional information or have any |
|
23 * questions. |
|
24 * |
|
25 * THIS FILE WAS MODIFIED BY SUN MICROSYSTEMS, INC. |
|
26 */ |
|
27 |
|
28 package com.sun.xml.internal.fastinfoset.util; |
|
29 |
|
30 import com.sun.xml.internal.fastinfoset.QualifiedName; |
|
31 import com.sun.xml.internal.fastinfoset.CommonResourceBundle; |
|
32 |
|
33 public class QualifiedNameArray extends ValueArray { |
|
34 |
|
35 public QualifiedName[] _array; |
|
36 |
|
37 private QualifiedNameArray _readOnlyArray; |
|
38 |
|
39 public QualifiedNameArray(int initialCapacity, int maximumCapacity) { |
|
40 _array = new QualifiedName[initialCapacity]; |
|
41 _maximumCapacity = maximumCapacity; |
|
42 } |
|
43 |
|
44 public QualifiedNameArray() { |
|
45 this(DEFAULT_CAPACITY, MAXIMUM_CAPACITY); |
|
46 } |
|
47 |
|
48 public final void clear() { |
|
49 _size = _readOnlyArraySize; |
|
50 } |
|
51 |
|
52 /** |
|
53 * Returns cloned version of internal QualifiedName[]. |
|
54 * @return cloned version of internal QualifiedName[]. |
|
55 */ |
|
56 public final QualifiedName[] getArray() { |
|
57 if (_array == null) return null; |
|
58 |
|
59 final QualifiedName[] clonedArray = new QualifiedName[_array.length]; |
|
60 System.arraycopy(_array, 0, clonedArray, 0, _array.length); |
|
61 return clonedArray; |
|
62 } |
|
63 |
|
64 public final void setReadOnlyArray(ValueArray readOnlyArray, boolean clear) { |
|
65 if (!(readOnlyArray instanceof QualifiedNameArray)) { |
|
66 throw new IllegalArgumentException(CommonResourceBundle.getInstance(). |
|
67 getString("message.illegalClass", new Object[]{readOnlyArray})); |
|
68 } |
|
69 |
|
70 setReadOnlyArray((QualifiedNameArray)readOnlyArray, clear); |
|
71 } |
|
72 |
|
73 public final void setReadOnlyArray(QualifiedNameArray readOnlyArray, boolean clear) { |
|
74 if (readOnlyArray != null) { |
|
75 _readOnlyArray = readOnlyArray; |
|
76 _readOnlyArraySize = readOnlyArray.getSize(); |
|
77 |
|
78 if (clear) { |
|
79 clear(); |
|
80 } |
|
81 |
|
82 _array = getCompleteArray(); |
|
83 _size = _readOnlyArraySize; |
|
84 } |
|
85 } |
|
86 |
|
87 public final QualifiedName[] getCompleteArray() { |
|
88 if (_readOnlyArray == null) { |
|
89 // Return cloned version of internal _array |
|
90 return getArray(); |
|
91 // return _array; |
|
92 } else { |
|
93 final QualifiedName[] ra = _readOnlyArray.getCompleteArray(); |
|
94 final QualifiedName[] a = new QualifiedName[_readOnlyArraySize + _array.length]; |
|
95 System.arraycopy(ra, 0, a, 0, _readOnlyArraySize); |
|
96 return a; |
|
97 } |
|
98 } |
|
99 |
|
100 public final QualifiedName getNext() { |
|
101 return (_size == _array.length) ? null : _array[_size]; |
|
102 } |
|
103 |
|
104 public final void add(QualifiedName s) { |
|
105 if (_size == _array.length) { |
|
106 resize(); |
|
107 } |
|
108 |
|
109 _array[_size++] = s; |
|
110 } |
|
111 |
|
112 protected final void resize() { |
|
113 if (_size == _maximumCapacity) { |
|
114 throw new ValueArrayResourceException(CommonResourceBundle.getInstance().getString("message.arrayMaxCapacity")); |
|
115 } |
|
116 |
|
117 int newSize = _size * 3 / 2 + 1; |
|
118 if (newSize > _maximumCapacity) { |
|
119 newSize = _maximumCapacity; |
|
120 } |
|
121 |
|
122 final QualifiedName[] newArray = new QualifiedName[newSize]; |
|
123 System.arraycopy(_array, 0, newArray, 0, _size); |
|
124 _array = newArray; |
|
125 } |
|
126 |
|
127 } |