author | mkos |
Sun, 30 Dec 2012 00:00:00 +0100 | |
changeset 22678 | ac1ea46be942 |
parent 12009 | 4abb694f273a |
permissions | -rw-r--r-- |
12009 | 1 |
/* |
22678
ac1ea46be942
8029237: Update copyright year to match last edit in jaxws repository for 2012
mkos
parents:
12009
diff
changeset
|
2 |
* Copyright (c) 2004, 2012, Oracle and/or its affiliates. All rights reserved. |
12009 | 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.vocab; |
|
29 |
||
30 |
import com.sun.xml.internal.fastinfoset.EncodingConstants; |
|
31 |
import com.sun.xml.internal.fastinfoset.QualifiedName; |
|
32 |
import com.sun.xml.internal.fastinfoset.util.CharArray; |
|
33 |
import com.sun.xml.internal.fastinfoset.util.CharArrayArray; |
|
34 |
import com.sun.xml.internal.fastinfoset.util.ContiguousCharArrayArray; |
|
35 |
import com.sun.xml.internal.fastinfoset.util.DuplicateAttributeVerifier; |
|
36 |
import com.sun.xml.internal.fastinfoset.util.FixedEntryStringIntMap; |
|
37 |
import com.sun.xml.internal.fastinfoset.util.KeyIntMap; |
|
38 |
import com.sun.xml.internal.fastinfoset.util.PrefixArray; |
|
39 |
import com.sun.xml.internal.fastinfoset.util.QualifiedNameArray; |
|
40 |
import com.sun.xml.internal.fastinfoset.util.StringArray; |
|
41 |
import com.sun.xml.internal.fastinfoset.util.StringIntMap; |
|
42 |
import com.sun.xml.internal.fastinfoset.util.ValueArray; |
|
43 |
import java.util.Iterator; |
|
44 |
import javax.xml.namespace.QName; |
|
45 |
||
46 |
public class ParserVocabulary extends Vocabulary { |
|
47 |
public static final String IDENTIFYING_STRING_TABLE_MAXIMUM_ITEMS_PEOPERTY = |
|
48 |
"com.sun.xml.internal.fastinfoset.vocab.ParserVocabulary.IdentifyingStringTable.maximumItems"; |
|
49 |
public static final String NON_IDENTIFYING_STRING_TABLE_MAXIMUM_ITEMS_PEOPERTY = |
|
50 |
"com.sun.xml.internal.fastinfoset.vocab.ParserVocabulary.NonIdentifyingStringTable.maximumItems"; |
|
51 |
public static final String NON_IDENTIFYING_STRING_TABLE_MAXIMUM_CHARACTERS_PEOPERTY = |
|
52 |
"com.sun.xml.internal.fastinfoset.vocab.ParserVocabulary.NonIdentifyingStringTable.maximumCharacters"; |
|
53 |
||
54 |
protected static final int IDENTIFYING_STRING_TABLE_MAXIMUM_ITEMS = |
|
55 |
getIntegerValueFromProperty(IDENTIFYING_STRING_TABLE_MAXIMUM_ITEMS_PEOPERTY); |
|
56 |
protected static final int NON_IDENTIFYING_STRING_TABLE_MAXIMUM_ITEMS = |
|
57 |
getIntegerValueFromProperty(NON_IDENTIFYING_STRING_TABLE_MAXIMUM_ITEMS_PEOPERTY); |
|
58 |
protected static final int NON_IDENTIFYING_STRING_TABLE_MAXIMUM_CHARACTERS = |
|
59 |
getIntegerValueFromProperty(NON_IDENTIFYING_STRING_TABLE_MAXIMUM_CHARACTERS_PEOPERTY); |
|
60 |
||
61 |
private static int getIntegerValueFromProperty(String property) { |
|
62 |
String value = System.getProperty(property); |
|
63 |
if (value == null) { |
|
64 |
return Integer.MAX_VALUE; |
|
65 |
} |
|
66 |
||
67 |
try { |
|
68 |
return Math.max(Integer.parseInt(value), ValueArray.DEFAULT_CAPACITY); |
|
69 |
} catch (NumberFormatException e) { |
|
70 |
return Integer.MAX_VALUE; |
|
71 |
} |
|
72 |
} |
|
73 |
||
74 |
public final CharArrayArray restrictedAlphabet = new CharArrayArray(ValueArray.DEFAULT_CAPACITY, 256); |
|
75 |
public final StringArray encodingAlgorithm = new StringArray(ValueArray.DEFAULT_CAPACITY, 256, true); |
|
76 |
||
77 |
public final StringArray namespaceName; |
|
78 |
public final PrefixArray prefix; |
|
79 |
public final StringArray localName; |
|
80 |
public final StringArray otherNCName ; |
|
81 |
public final StringArray otherURI; |
|
82 |
public final StringArray attributeValue; |
|
83 |
public final CharArrayArray otherString; |
|
84 |
||
85 |
public final ContiguousCharArrayArray characterContentChunk; |
|
86 |
||
87 |
public final QualifiedNameArray elementName; |
|
88 |
public final QualifiedNameArray attributeName; |
|
89 |
||
90 |
public final ValueArray[] tables = new ValueArray[12]; |
|
91 |
||
92 |
protected SerializerVocabulary _readOnlyVocabulary; |
|
93 |
||
94 |
/** Creates a new instance of ParserVocabulary */ |
|
95 |
public ParserVocabulary() { |
|
96 |
namespaceName = new StringArray(ValueArray.DEFAULT_CAPACITY, IDENTIFYING_STRING_TABLE_MAXIMUM_ITEMS, false); |
|
97 |
prefix = new PrefixArray(ValueArray.DEFAULT_CAPACITY, IDENTIFYING_STRING_TABLE_MAXIMUM_ITEMS); |
|
98 |
localName = new StringArray(ValueArray.DEFAULT_CAPACITY, IDENTIFYING_STRING_TABLE_MAXIMUM_ITEMS, false); |
|
99 |
otherNCName = new StringArray(ValueArray.DEFAULT_CAPACITY, IDENTIFYING_STRING_TABLE_MAXIMUM_ITEMS, false); |
|
100 |
otherURI = new StringArray(ValueArray.DEFAULT_CAPACITY, IDENTIFYING_STRING_TABLE_MAXIMUM_ITEMS, true); |
|
101 |
attributeValue = new StringArray(ValueArray.DEFAULT_CAPACITY, NON_IDENTIFYING_STRING_TABLE_MAXIMUM_ITEMS, true); |
|
102 |
otherString = new CharArrayArray(ValueArray.DEFAULT_CAPACITY, NON_IDENTIFYING_STRING_TABLE_MAXIMUM_ITEMS); |
|
103 |
||
104 |
characterContentChunk = new ContiguousCharArrayArray(ValueArray.DEFAULT_CAPACITY, |
|
105 |
NON_IDENTIFYING_STRING_TABLE_MAXIMUM_ITEMS, |
|
106 |
ContiguousCharArrayArray.INITIAL_CHARACTER_SIZE, |
|
107 |
NON_IDENTIFYING_STRING_TABLE_MAXIMUM_CHARACTERS); |
|
108 |
||
109 |
elementName = new QualifiedNameArray(ValueArray.DEFAULT_CAPACITY, IDENTIFYING_STRING_TABLE_MAXIMUM_ITEMS); |
|
110 |
attributeName = new QualifiedNameArray(ValueArray.DEFAULT_CAPACITY, IDENTIFYING_STRING_TABLE_MAXIMUM_ITEMS); |
|
111 |
||
112 |
tables[RESTRICTED_ALPHABET] = restrictedAlphabet; |
|
113 |
tables[ENCODING_ALGORITHM] = encodingAlgorithm; |
|
114 |
tables[PREFIX] = prefix; |
|
115 |
tables[NAMESPACE_NAME] = namespaceName; |
|
116 |
tables[LOCAL_NAME] = localName; |
|
117 |
tables[OTHER_NCNAME] = otherNCName; |
|
118 |
tables[OTHER_URI] = otherURI; |
|
119 |
tables[ATTRIBUTE_VALUE] = attributeValue; |
|
120 |
tables[OTHER_STRING] = otherString; |
|
121 |
tables[CHARACTER_CONTENT_CHUNK] = characterContentChunk; |
|
122 |
tables[ELEMENT_NAME] = elementName; |
|
123 |
tables[ATTRIBUTE_NAME] = attributeName; |
|
124 |
} |
|
125 |
||
126 |
||
127 |
public ParserVocabulary(com.sun.xml.internal.org.jvnet.fastinfoset.Vocabulary v) { |
|
128 |
this(); |
|
129 |
||
130 |
convertVocabulary(v); |
|
131 |
} |
|
132 |
||
133 |
void setReadOnlyVocabulary(ParserVocabulary readOnlyVocabulary, boolean clear) { |
|
134 |
for (int i = 0; i < tables.length; i++) { |
|
135 |
tables[i].setReadOnlyArray(readOnlyVocabulary.tables[i], clear); |
|
136 |
} |
|
137 |
} |
|
138 |
||
139 |
public void setInitialVocabulary(ParserVocabulary initialVocabulary, boolean clear) { |
|
140 |
setExternalVocabularyURI(null); |
|
141 |
setInitialReadOnlyVocabulary(true); |
|
142 |
setReadOnlyVocabulary(initialVocabulary, clear); |
|
143 |
} |
|
144 |
||
145 |
public void setReferencedVocabulary(String referencedVocabularyURI, ParserVocabulary referencedVocabulary, boolean clear) { |
|
146 |
if (!referencedVocabularyURI.equals(getExternalVocabularyURI())) { |
|
147 |
setInitialReadOnlyVocabulary(false); |
|
148 |
setExternalVocabularyURI(referencedVocabularyURI); |
|
149 |
setReadOnlyVocabulary(referencedVocabulary, clear); |
|
150 |
} |
|
151 |
} |
|
152 |
||
153 |
public void clear() { |
|
154 |
for (int i = 0; i < tables.length; i++) { |
|
155 |
tables[i].clear(); |
|
156 |
} |
|
157 |
} |
|
158 |
||
159 |
private void convertVocabulary(com.sun.xml.internal.org.jvnet.fastinfoset.Vocabulary v) { |
|
160 |
final StringIntMap prefixMap = new FixedEntryStringIntMap( |
|
161 |
EncodingConstants.XML_NAMESPACE_PREFIX, 8); |
|
162 |
final StringIntMap namespaceNameMap = new FixedEntryStringIntMap( |
|
163 |
EncodingConstants.XML_NAMESPACE_NAME, 8); |
|
164 |
final StringIntMap localNameMap = new StringIntMap(); |
|
165 |
||
166 |
addToTable(v.restrictedAlphabets.iterator(), restrictedAlphabet); |
|
167 |
addToTable(v.encodingAlgorithms.iterator(), encodingAlgorithm); |
|
168 |
addToTable(v.prefixes.iterator(), prefix, prefixMap); |
|
169 |
addToTable(v.namespaceNames.iterator(), namespaceName, namespaceNameMap); |
|
170 |
addToTable(v.localNames.iterator(), localName, localNameMap); |
|
171 |
addToTable(v.otherNCNames.iterator(), otherNCName); |
|
172 |
addToTable(v.otherURIs.iterator(), otherURI); |
|
173 |
addToTable(v.attributeValues.iterator(), attributeValue); |
|
174 |
addToTable(v.otherStrings.iterator(), otherString); |
|
175 |
addToTable(v.characterContentChunks.iterator(), characterContentChunk); |
|
176 |
addToTable(v.elements.iterator(), elementName, false, |
|
177 |
prefixMap, namespaceNameMap, localNameMap); |
|
178 |
addToTable(v.attributes.iterator(), attributeName, true, |
|
179 |
prefixMap, namespaceNameMap, localNameMap); |
|
180 |
} |
|
181 |
||
182 |
private void addToTable(Iterator i, StringArray a) { |
|
183 |
while (i.hasNext()) { |
|
184 |
addToTable((String)i.next(), a, null); |
|
185 |
} |
|
186 |
} |
|
187 |
||
188 |
private void addToTable(Iterator i, StringArray a, StringIntMap m) { |
|
189 |
while (i.hasNext()) { |
|
190 |
addToTable((String)i.next(), a, m); |
|
191 |
} |
|
192 |
} |
|
193 |
||
194 |
private void addToTable(String s, StringArray a, StringIntMap m) { |
|
195 |
if (s.length() == 0) { |
|
196 |
return; |
|
197 |
} |
|
198 |
||
199 |
if (m != null) m.obtainIndex(s); |
|
200 |
a.add(s); |
|
201 |
} |
|
202 |
||
203 |
private void addToTable(Iterator i, PrefixArray a, StringIntMap m) { |
|
204 |
while (i.hasNext()) { |
|
205 |
addToTable((String)i.next(), a, m); |
|
206 |
} |
|
207 |
} |
|
208 |
||
209 |
private void addToTable(String s, PrefixArray a, StringIntMap m) { |
|
210 |
if (s.length() == 0) { |
|
211 |
return; |
|
212 |
} |
|
213 |
||
214 |
if (m != null) m.obtainIndex(s); |
|
215 |
a.add(s); |
|
216 |
} |
|
217 |
||
218 |
private void addToTable(Iterator i, ContiguousCharArrayArray a) { |
|
219 |
while (i.hasNext()) { |
|
220 |
addToTable((String)i.next(), a); |
|
221 |
} |
|
222 |
} |
|
223 |
||
224 |
private void addToTable(String s, ContiguousCharArrayArray a) { |
|
225 |
if (s.length() == 0) { |
|
226 |
return; |
|
227 |
} |
|
228 |
||
229 |
char[] c = s.toCharArray(); |
|
230 |
a.add(c, c.length); |
|
231 |
} |
|
232 |
||
233 |
private void addToTable(Iterator i, CharArrayArray a) { |
|
234 |
while (i.hasNext()) { |
|
235 |
addToTable((String)i.next(), a); |
|
236 |
} |
|
237 |
} |
|
238 |
||
239 |
private void addToTable(String s, CharArrayArray a) { |
|
240 |
if (s.length() == 0) { |
|
241 |
return; |
|
242 |
} |
|
243 |
||
244 |
char[] c = s.toCharArray(); |
|
245 |
a.add(new CharArray(c, 0, c.length, false)); |
|
246 |
} |
|
247 |
||
248 |
private void addToTable(Iterator i, QualifiedNameArray a, |
|
249 |
boolean isAttribute, |
|
250 |
StringIntMap prefixMap, StringIntMap namespaceNameMap, |
|
251 |
StringIntMap localNameMap) { |
|
252 |
while (i.hasNext()) { |
|
253 |
addToNameTable((QName)i.next(), a, isAttribute, |
|
254 |
prefixMap, namespaceNameMap, localNameMap); |
|
255 |
} |
|
256 |
} |
|
257 |
||
258 |
private void addToNameTable(QName n, QualifiedNameArray a, |
|
259 |
boolean isAttribute, |
|
260 |
StringIntMap prefixMap, StringIntMap namespaceNameMap, |
|
261 |
StringIntMap localNameMap) { |
|
262 |
int namespaceURIIndex = -1; |
|
263 |
int prefixIndex = -1; |
|
264 |
if (n.getNamespaceURI().length() > 0) { |
|
265 |
namespaceURIIndex = namespaceNameMap.obtainIndex(n.getNamespaceURI()); |
|
266 |
if (namespaceURIIndex == KeyIntMap.NOT_PRESENT) { |
|
267 |
namespaceURIIndex = namespaceName.getSize(); |
|
268 |
namespaceName.add(n.getNamespaceURI()); |
|
269 |
} |
|
270 |
||
271 |
if (n.getPrefix().length() > 0) { |
|
272 |
prefixIndex = prefixMap.obtainIndex(n.getPrefix()); |
|
273 |
if (prefixIndex == KeyIntMap.NOT_PRESENT) { |
|
274 |
prefixIndex = prefix.getSize(); |
|
275 |
prefix.add(n.getPrefix()); |
|
276 |
} |
|
277 |
} |
|
278 |
} |
|
279 |
||
280 |
int localNameIndex = localNameMap.obtainIndex(n.getLocalPart()); |
|
281 |
if (localNameIndex == KeyIntMap.NOT_PRESENT) { |
|
282 |
localNameIndex = localName.getSize(); |
|
283 |
localName.add(n.getLocalPart()); |
|
284 |
} |
|
285 |
||
286 |
QualifiedName name = new QualifiedName(n.getPrefix(), n.getNamespaceURI(), n.getLocalPart(), |
|
287 |
a.getSize(), |
|
288 |
prefixIndex, namespaceURIIndex, localNameIndex); |
|
289 |
if (isAttribute) { |
|
290 |
name.createAttributeValues(DuplicateAttributeVerifier.MAP_SIZE); |
|
291 |
} |
|
292 |
a.add(name); |
|
293 |
} |
|
294 |
} |