src/share/jaxws_classes/com/sun/xml/internal/fastinfoset/vocab/ParserVocabulary.java

changeset 0
373ffda63c9a
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/share/jaxws_classes/com/sun/xml/internal/fastinfoset/vocab/ParserVocabulary.java	Wed Apr 27 01:27:09 2016 +0800
     1.3 @@ -0,0 +1,294 @@
     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.vocab;
    1.32 +
    1.33 +import com.sun.xml.internal.fastinfoset.EncodingConstants;
    1.34 +import com.sun.xml.internal.fastinfoset.QualifiedName;
    1.35 +import com.sun.xml.internal.fastinfoset.util.CharArray;
    1.36 +import com.sun.xml.internal.fastinfoset.util.CharArrayArray;
    1.37 +import com.sun.xml.internal.fastinfoset.util.ContiguousCharArrayArray;
    1.38 +import com.sun.xml.internal.fastinfoset.util.DuplicateAttributeVerifier;
    1.39 +import com.sun.xml.internal.fastinfoset.util.FixedEntryStringIntMap;
    1.40 +import com.sun.xml.internal.fastinfoset.util.KeyIntMap;
    1.41 +import com.sun.xml.internal.fastinfoset.util.PrefixArray;
    1.42 +import com.sun.xml.internal.fastinfoset.util.QualifiedNameArray;
    1.43 +import com.sun.xml.internal.fastinfoset.util.StringArray;
    1.44 +import com.sun.xml.internal.fastinfoset.util.StringIntMap;
    1.45 +import com.sun.xml.internal.fastinfoset.util.ValueArray;
    1.46 +import java.util.Iterator;
    1.47 +import javax.xml.namespace.QName;
    1.48 +
    1.49 +public class ParserVocabulary extends Vocabulary {
    1.50 +    public static final String IDENTIFYING_STRING_TABLE_MAXIMUM_ITEMS_PEOPERTY =
    1.51 +        "com.sun.xml.internal.fastinfoset.vocab.ParserVocabulary.IdentifyingStringTable.maximumItems";
    1.52 +    public static final String NON_IDENTIFYING_STRING_TABLE_MAXIMUM_ITEMS_PEOPERTY =
    1.53 +        "com.sun.xml.internal.fastinfoset.vocab.ParserVocabulary.NonIdentifyingStringTable.maximumItems";
    1.54 +    public static final String NON_IDENTIFYING_STRING_TABLE_MAXIMUM_CHARACTERS_PEOPERTY =
    1.55 +        "com.sun.xml.internal.fastinfoset.vocab.ParserVocabulary.NonIdentifyingStringTable.maximumCharacters";
    1.56 +
    1.57 +    protected static final int IDENTIFYING_STRING_TABLE_MAXIMUM_ITEMS =
    1.58 +            getIntegerValueFromProperty(IDENTIFYING_STRING_TABLE_MAXIMUM_ITEMS_PEOPERTY);
    1.59 +    protected static final int NON_IDENTIFYING_STRING_TABLE_MAXIMUM_ITEMS =
    1.60 +            getIntegerValueFromProperty(NON_IDENTIFYING_STRING_TABLE_MAXIMUM_ITEMS_PEOPERTY);
    1.61 +    protected static final int NON_IDENTIFYING_STRING_TABLE_MAXIMUM_CHARACTERS =
    1.62 +            getIntegerValueFromProperty(NON_IDENTIFYING_STRING_TABLE_MAXIMUM_CHARACTERS_PEOPERTY);
    1.63 +
    1.64 +    private static int getIntegerValueFromProperty(String property) {
    1.65 +        String value = System.getProperty(property);
    1.66 +        if (value == null) {
    1.67 +            return Integer.MAX_VALUE;
    1.68 +        }
    1.69 +
    1.70 +        try {
    1.71 +            return Math.max(Integer.parseInt(value), ValueArray.DEFAULT_CAPACITY);
    1.72 +        } catch (NumberFormatException e) {
    1.73 +            return Integer.MAX_VALUE;
    1.74 +        }
    1.75 +    }
    1.76 +
    1.77 +    public final CharArrayArray restrictedAlphabet = new CharArrayArray(ValueArray.DEFAULT_CAPACITY, 256);
    1.78 +    public final StringArray encodingAlgorithm = new StringArray(ValueArray.DEFAULT_CAPACITY, 256, true);
    1.79 +
    1.80 +    public final StringArray namespaceName;
    1.81 +    public final PrefixArray prefix;
    1.82 +    public final StringArray localName;
    1.83 +    public final StringArray otherNCName ;
    1.84 +    public final StringArray otherURI;
    1.85 +    public final StringArray attributeValue;
    1.86 +    public final CharArrayArray otherString;
    1.87 +
    1.88 +    public final ContiguousCharArrayArray characterContentChunk;
    1.89 +
    1.90 +    public final QualifiedNameArray elementName;
    1.91 +    public final QualifiedNameArray attributeName;
    1.92 +
    1.93 +    public final ValueArray[] tables = new ValueArray[12];
    1.94 +
    1.95 +    protected SerializerVocabulary _readOnlyVocabulary;
    1.96 +
    1.97 +    /** Creates a new instance of ParserVocabulary */
    1.98 +    public ParserVocabulary() {
    1.99 +        namespaceName = new StringArray(ValueArray.DEFAULT_CAPACITY, IDENTIFYING_STRING_TABLE_MAXIMUM_ITEMS, false);
   1.100 +        prefix = new PrefixArray(ValueArray.DEFAULT_CAPACITY, IDENTIFYING_STRING_TABLE_MAXIMUM_ITEMS);
   1.101 +        localName = new StringArray(ValueArray.DEFAULT_CAPACITY, IDENTIFYING_STRING_TABLE_MAXIMUM_ITEMS, false);
   1.102 +        otherNCName = new StringArray(ValueArray.DEFAULT_CAPACITY, IDENTIFYING_STRING_TABLE_MAXIMUM_ITEMS, false);
   1.103 +        otherURI = new StringArray(ValueArray.DEFAULT_CAPACITY, IDENTIFYING_STRING_TABLE_MAXIMUM_ITEMS, true);
   1.104 +        attributeValue = new StringArray(ValueArray.DEFAULT_CAPACITY, NON_IDENTIFYING_STRING_TABLE_MAXIMUM_ITEMS, true);
   1.105 +        otherString = new CharArrayArray(ValueArray.DEFAULT_CAPACITY, NON_IDENTIFYING_STRING_TABLE_MAXIMUM_ITEMS);
   1.106 +
   1.107 +        characterContentChunk = new ContiguousCharArrayArray(ValueArray.DEFAULT_CAPACITY,
   1.108 +                NON_IDENTIFYING_STRING_TABLE_MAXIMUM_ITEMS,
   1.109 +                ContiguousCharArrayArray.INITIAL_CHARACTER_SIZE,
   1.110 +                NON_IDENTIFYING_STRING_TABLE_MAXIMUM_CHARACTERS);
   1.111 +
   1.112 +        elementName = new QualifiedNameArray(ValueArray.DEFAULT_CAPACITY, IDENTIFYING_STRING_TABLE_MAXIMUM_ITEMS);
   1.113 +        attributeName = new QualifiedNameArray(ValueArray.DEFAULT_CAPACITY, IDENTIFYING_STRING_TABLE_MAXIMUM_ITEMS);
   1.114 +
   1.115 +        tables[RESTRICTED_ALPHABET] = restrictedAlphabet;
   1.116 +        tables[ENCODING_ALGORITHM] = encodingAlgorithm;
   1.117 +        tables[PREFIX] = prefix;
   1.118 +        tables[NAMESPACE_NAME] = namespaceName;
   1.119 +        tables[LOCAL_NAME] = localName;
   1.120 +        tables[OTHER_NCNAME] = otherNCName;
   1.121 +        tables[OTHER_URI] = otherURI;
   1.122 +        tables[ATTRIBUTE_VALUE] = attributeValue;
   1.123 +        tables[OTHER_STRING] = otherString;
   1.124 +        tables[CHARACTER_CONTENT_CHUNK] = characterContentChunk;
   1.125 +        tables[ELEMENT_NAME] = elementName;
   1.126 +        tables[ATTRIBUTE_NAME] = attributeName;
   1.127 +    }
   1.128 +
   1.129 +
   1.130 +    public ParserVocabulary(com.sun.xml.internal.org.jvnet.fastinfoset.Vocabulary v) {
   1.131 +        this();
   1.132 +
   1.133 +        convertVocabulary(v);
   1.134 +    }
   1.135 +
   1.136 +    void setReadOnlyVocabulary(ParserVocabulary readOnlyVocabulary, boolean clear) {
   1.137 +        for (int i = 0; i < tables.length; i++) {
   1.138 +            tables[i].setReadOnlyArray(readOnlyVocabulary.tables[i], clear);
   1.139 +        }
   1.140 +    }
   1.141 +
   1.142 +    public void setInitialVocabulary(ParserVocabulary initialVocabulary, boolean clear) {
   1.143 +        setExternalVocabularyURI(null);
   1.144 +        setInitialReadOnlyVocabulary(true);
   1.145 +        setReadOnlyVocabulary(initialVocabulary, clear);
   1.146 +    }
   1.147 +
   1.148 +    public void setReferencedVocabulary(String referencedVocabularyURI, ParserVocabulary referencedVocabulary, boolean clear) {
   1.149 +        if (!referencedVocabularyURI.equals(getExternalVocabularyURI())) {
   1.150 +            setInitialReadOnlyVocabulary(false);
   1.151 +            setExternalVocabularyURI(referencedVocabularyURI);
   1.152 +            setReadOnlyVocabulary(referencedVocabulary, clear);
   1.153 +        }
   1.154 +    }
   1.155 +
   1.156 +    public void clear() {
   1.157 +        for (int i = 0; i < tables.length; i++) {
   1.158 +            tables[i].clear();
   1.159 +        }
   1.160 +    }
   1.161 +
   1.162 +    private void convertVocabulary(com.sun.xml.internal.org.jvnet.fastinfoset.Vocabulary v) {
   1.163 +        final StringIntMap prefixMap = new FixedEntryStringIntMap(
   1.164 +                EncodingConstants.XML_NAMESPACE_PREFIX, 8);
   1.165 +        final StringIntMap namespaceNameMap = new FixedEntryStringIntMap(
   1.166 +                EncodingConstants.XML_NAMESPACE_NAME, 8);
   1.167 +        final StringIntMap localNameMap = new StringIntMap();
   1.168 +
   1.169 +        addToTable(v.restrictedAlphabets.iterator(), restrictedAlphabet);
   1.170 +        addToTable(v.encodingAlgorithms.iterator(), encodingAlgorithm);
   1.171 +        addToTable(v.prefixes.iterator(), prefix, prefixMap);
   1.172 +        addToTable(v.namespaceNames.iterator(), namespaceName, namespaceNameMap);
   1.173 +        addToTable(v.localNames.iterator(), localName, localNameMap);
   1.174 +        addToTable(v.otherNCNames.iterator(), otherNCName);
   1.175 +        addToTable(v.otherURIs.iterator(), otherURI);
   1.176 +        addToTable(v.attributeValues.iterator(), attributeValue);
   1.177 +        addToTable(v.otherStrings.iterator(), otherString);
   1.178 +        addToTable(v.characterContentChunks.iterator(), characterContentChunk);
   1.179 +        addToTable(v.elements.iterator(), elementName, false,
   1.180 +                prefixMap, namespaceNameMap, localNameMap);
   1.181 +        addToTable(v.attributes.iterator(), attributeName, true,
   1.182 +                prefixMap, namespaceNameMap, localNameMap);
   1.183 +    }
   1.184 +
   1.185 +    private void addToTable(Iterator i, StringArray a) {
   1.186 +        while (i.hasNext()) {
   1.187 +            addToTable((String)i.next(), a, null);
   1.188 +        }
   1.189 +    }
   1.190 +
   1.191 +    private void addToTable(Iterator i, StringArray a, StringIntMap m) {
   1.192 +        while (i.hasNext()) {
   1.193 +            addToTable((String)i.next(), a, m);
   1.194 +        }
   1.195 +    }
   1.196 +
   1.197 +    private void addToTable(String s, StringArray a, StringIntMap m) {
   1.198 +        if (s.length() == 0) {
   1.199 +            return;
   1.200 +        }
   1.201 +
   1.202 +        if (m != null) m.obtainIndex(s);
   1.203 +        a.add(s);
   1.204 +    }
   1.205 +
   1.206 +    private void addToTable(Iterator i, PrefixArray a, StringIntMap m) {
   1.207 +        while (i.hasNext()) {
   1.208 +            addToTable((String)i.next(), a, m);
   1.209 +        }
   1.210 +    }
   1.211 +
   1.212 +    private void addToTable(String s, PrefixArray a, StringIntMap m) {
   1.213 +        if (s.length() == 0) {
   1.214 +            return;
   1.215 +        }
   1.216 +
   1.217 +        if (m != null) m.obtainIndex(s);
   1.218 +        a.add(s);
   1.219 +    }
   1.220 +
   1.221 +    private void addToTable(Iterator i, ContiguousCharArrayArray a) {
   1.222 +        while (i.hasNext()) {
   1.223 +            addToTable((String)i.next(), a);
   1.224 +        }
   1.225 +    }
   1.226 +
   1.227 +    private void addToTable(String s, ContiguousCharArrayArray a) {
   1.228 +        if (s.length() == 0) {
   1.229 +            return;
   1.230 +        }
   1.231 +
   1.232 +        char[] c = s.toCharArray();
   1.233 +        a.add(c, c.length);
   1.234 +    }
   1.235 +
   1.236 +    private void addToTable(Iterator i, CharArrayArray a) {
   1.237 +        while (i.hasNext()) {
   1.238 +            addToTable((String)i.next(), a);
   1.239 +        }
   1.240 +    }
   1.241 +
   1.242 +    private void addToTable(String s, CharArrayArray a) {
   1.243 +        if (s.length() == 0) {
   1.244 +            return;
   1.245 +        }
   1.246 +
   1.247 +        char[] c = s.toCharArray();
   1.248 +        a.add(new CharArray(c, 0, c.length, false));
   1.249 +    }
   1.250 +
   1.251 +    private void addToTable(Iterator i, QualifiedNameArray a,
   1.252 +            boolean isAttribute,
   1.253 +            StringIntMap prefixMap, StringIntMap namespaceNameMap,
   1.254 +            StringIntMap localNameMap) {
   1.255 +        while (i.hasNext()) {
   1.256 +            addToNameTable((QName)i.next(), a, isAttribute,
   1.257 +                    prefixMap, namespaceNameMap, localNameMap);
   1.258 +        }
   1.259 +    }
   1.260 +
   1.261 +    private void addToNameTable(QName n, QualifiedNameArray a,
   1.262 +            boolean isAttribute,
   1.263 +            StringIntMap prefixMap, StringIntMap namespaceNameMap,
   1.264 +            StringIntMap localNameMap) {
   1.265 +        int namespaceURIIndex = -1;
   1.266 +        int prefixIndex = -1;
   1.267 +        if (n.getNamespaceURI().length() > 0) {
   1.268 +            namespaceURIIndex = namespaceNameMap.obtainIndex(n.getNamespaceURI());
   1.269 +            if (namespaceURIIndex == KeyIntMap.NOT_PRESENT) {
   1.270 +                namespaceURIIndex = namespaceName.getSize();
   1.271 +                namespaceName.add(n.getNamespaceURI());
   1.272 +            }
   1.273 +
   1.274 +            if (n.getPrefix().length() > 0) {
   1.275 +                prefixIndex = prefixMap.obtainIndex(n.getPrefix());
   1.276 +                if (prefixIndex == KeyIntMap.NOT_PRESENT) {
   1.277 +                    prefixIndex = prefix.getSize();
   1.278 +                    prefix.add(n.getPrefix());
   1.279 +                }
   1.280 +            }
   1.281 +        }
   1.282 +
   1.283 +        int localNameIndex = localNameMap.obtainIndex(n.getLocalPart());
   1.284 +        if (localNameIndex == KeyIntMap.NOT_PRESENT) {
   1.285 +            localNameIndex = localName.getSize();
   1.286 +            localName.add(n.getLocalPart());
   1.287 +        }
   1.288 +
   1.289 +        QualifiedName name = new QualifiedName(n.getPrefix(), n.getNamespaceURI(), n.getLocalPart(),
   1.290 +                a.getSize(),
   1.291 +                prefixIndex, namespaceURIIndex, localNameIndex);
   1.292 +        if (isAttribute) {
   1.293 +            name.createAttributeValues(DuplicateAttributeVerifier.MAP_SIZE);
   1.294 +        }
   1.295 +        a.add(name);
   1.296 +    }
   1.297 +}

mercurial