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