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/SerializerVocabulary.java Tue Mar 06 16:09:35 2012 -0800 1.3 @@ -0,0 +1,205 @@ 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.CharArrayIntMap; 1.36 +import com.sun.xml.internal.fastinfoset.util.FixedEntryStringIntMap; 1.37 +import com.sun.xml.internal.fastinfoset.util.KeyIntMap; 1.38 +import com.sun.xml.internal.fastinfoset.util.LocalNameQualifiedNamesMap; 1.39 +import com.sun.xml.internal.fastinfoset.util.StringIntMap; 1.40 +import java.util.Iterator; 1.41 +import javax.xml.namespace.QName; 1.42 + 1.43 +public class SerializerVocabulary extends Vocabulary { 1.44 + public final StringIntMap restrictedAlphabet; 1.45 + public final StringIntMap encodingAlgorithm; 1.46 + 1.47 + public final StringIntMap namespaceName; 1.48 + public final StringIntMap prefix; 1.49 + public final StringIntMap localName; 1.50 + public final StringIntMap otherNCName; 1.51 + public final StringIntMap otherURI; 1.52 + public final StringIntMap attributeValue; 1.53 + public final CharArrayIntMap otherString; 1.54 + 1.55 + public final CharArrayIntMap characterContentChunk; 1.56 + 1.57 + public final LocalNameQualifiedNamesMap elementName; 1.58 + public final LocalNameQualifiedNamesMap attributeName; 1.59 + 1.60 + public final KeyIntMap[] tables = new KeyIntMap[12]; 1.61 + 1.62 + protected boolean _useLocalNameAsKey; 1.63 + 1.64 + protected SerializerVocabulary _readOnlyVocabulary; 1.65 + 1.66 + public SerializerVocabulary() { 1.67 + tables[RESTRICTED_ALPHABET] = restrictedAlphabet = new StringIntMap(4); 1.68 + tables[ENCODING_ALGORITHM] = encodingAlgorithm = new StringIntMap(4); 1.69 + tables[PREFIX] = prefix = new FixedEntryStringIntMap(EncodingConstants.XML_NAMESPACE_PREFIX, 8); 1.70 + tables[NAMESPACE_NAME] = namespaceName = new FixedEntryStringIntMap(EncodingConstants.XML_NAMESPACE_NAME, 8); 1.71 + tables[LOCAL_NAME] = localName = new StringIntMap(); 1.72 + tables[OTHER_NCNAME] = otherNCName = new StringIntMap(4); 1.73 + tables[OTHER_URI] = otherURI = new StringIntMap(4); 1.74 + tables[ATTRIBUTE_VALUE] = attributeValue = new StringIntMap(); 1.75 + tables[OTHER_STRING] = otherString = new CharArrayIntMap(4); 1.76 + tables[CHARACTER_CONTENT_CHUNK] = characterContentChunk = new CharArrayIntMap(); 1.77 + tables[ELEMENT_NAME] = elementName = new LocalNameQualifiedNamesMap(); 1.78 + tables[ATTRIBUTE_NAME] = attributeName = new LocalNameQualifiedNamesMap(); 1.79 + } 1.80 + 1.81 + public SerializerVocabulary(com.sun.xml.internal.org.jvnet.fastinfoset.Vocabulary v, 1.82 + boolean useLocalNameAsKey) { 1.83 + this(); 1.84 + 1.85 + _useLocalNameAsKey = useLocalNameAsKey; 1.86 + convertVocabulary(v); 1.87 + } 1.88 + 1.89 + public SerializerVocabulary getReadOnlyVocabulary() { 1.90 + return _readOnlyVocabulary; 1.91 + } 1.92 + 1.93 + protected void setReadOnlyVocabulary(SerializerVocabulary readOnlyVocabulary, 1.94 + boolean clear) { 1.95 + for (int i = 0; i < tables.length; i++) { 1.96 + tables[i].setReadOnlyMap(readOnlyVocabulary.tables[i], clear); 1.97 + } 1.98 + } 1.99 + 1.100 + public void setInitialVocabulary(SerializerVocabulary initialVocabulary, 1.101 + boolean clear) { 1.102 + setExternalVocabularyURI(null); 1.103 + setInitialReadOnlyVocabulary(true); 1.104 + setReadOnlyVocabulary(initialVocabulary, clear); 1.105 + } 1.106 + 1.107 + public void setExternalVocabulary(String externalVocabularyURI, 1.108 + SerializerVocabulary externalVocabulary, boolean clear) { 1.109 + setInitialReadOnlyVocabulary(false); 1.110 + setExternalVocabularyURI(externalVocabularyURI); 1.111 + setReadOnlyVocabulary(externalVocabulary, clear); 1.112 + } 1.113 + 1.114 + public void clear() { 1.115 + for (int i = 0; i < tables.length; i++) { 1.116 + tables[i].clear(); 1.117 + } 1.118 + } 1.119 + 1.120 + private void convertVocabulary(com.sun.xml.internal.org.jvnet.fastinfoset.Vocabulary v) { 1.121 + addToTable(v.restrictedAlphabets.iterator(), restrictedAlphabet); 1.122 + addToTable(v.encodingAlgorithms.iterator(), encodingAlgorithm); 1.123 + addToTable(v.prefixes.iterator(), prefix); 1.124 + addToTable(v.namespaceNames.iterator(), namespaceName); 1.125 + addToTable(v.localNames.iterator(), localName); 1.126 + addToTable(v.otherNCNames.iterator(), otherNCName); 1.127 + addToTable(v.otherURIs.iterator(), otherURI); 1.128 + addToTable(v.attributeValues.iterator(), attributeValue); 1.129 + addToTable(v.otherStrings.iterator(), otherString); 1.130 + addToTable(v.characterContentChunks.iterator(), characterContentChunk); 1.131 + addToTable(v.elements.iterator(), elementName); 1.132 + addToTable(v.attributes.iterator(), attributeName); 1.133 + } 1.134 + 1.135 + private void addToTable(Iterator i, StringIntMap m) { 1.136 + while (i.hasNext()) { 1.137 + addToTable((String)i.next(), m); 1.138 + } 1.139 + } 1.140 + 1.141 + private void addToTable(String s, StringIntMap m) { 1.142 + if (s.length() == 0) { 1.143 + return; 1.144 + } 1.145 + 1.146 + m.obtainIndex(s); 1.147 + } 1.148 + 1.149 + private void addToTable(Iterator i, CharArrayIntMap m) { 1.150 + while (i.hasNext()) { 1.151 + addToTable((String)i.next(), m); 1.152 + } 1.153 + } 1.154 + 1.155 + private void addToTable(String s, CharArrayIntMap m) { 1.156 + if (s.length() == 0) { 1.157 + return; 1.158 + } 1.159 + 1.160 + char[] c = s.toCharArray(); 1.161 + m.obtainIndex(c, 0, c.length, false); 1.162 + } 1.163 + 1.164 + private void addToTable(Iterator i, LocalNameQualifiedNamesMap m) { 1.165 + while (i.hasNext()) { 1.166 + addToNameTable((QName)i.next(), m); 1.167 + } 1.168 + } 1.169 + 1.170 + private void addToNameTable(QName n, LocalNameQualifiedNamesMap m) { 1.171 + int namespaceURIIndex = -1; 1.172 + int prefixIndex = -1; 1.173 + if (n.getNamespaceURI().length() > 0) { 1.174 + namespaceURIIndex = namespaceName.obtainIndex(n.getNamespaceURI()); 1.175 + if (namespaceURIIndex == KeyIntMap.NOT_PRESENT) { 1.176 + namespaceURIIndex = namespaceName.get(n.getNamespaceURI()); 1.177 + } 1.178 + 1.179 + if (n.getPrefix().length() > 0) { 1.180 + prefixIndex = prefix.obtainIndex(n.getPrefix()); 1.181 + if (prefixIndex == KeyIntMap.NOT_PRESENT) { 1.182 + prefixIndex = prefix.get(n.getPrefix()); 1.183 + } 1.184 + } 1.185 + } 1.186 + 1.187 + int localNameIndex = localName.obtainIndex(n.getLocalPart()); 1.188 + if (localNameIndex == KeyIntMap.NOT_PRESENT) { 1.189 + localNameIndex = localName.get(n.getLocalPart()); 1.190 + } 1.191 + 1.192 + QualifiedName name = new QualifiedName(n.getPrefix(), n.getNamespaceURI(), n.getLocalPart(), 1.193 + m.getNextIndex(), 1.194 + prefixIndex, namespaceURIIndex, localNameIndex); 1.195 + 1.196 + LocalNameQualifiedNamesMap.Entry entry = null; 1.197 + if (_useLocalNameAsKey) { 1.198 + entry = m.obtainEntry(n.getLocalPart()); 1.199 + } else { 1.200 + String qName = (prefixIndex == -1) 1.201 + ? n.getLocalPart() 1.202 + : n.getPrefix() + ":" + n.getLocalPart(); 1.203 + entry = m.obtainEntry(qName); 1.204 + } 1.205 + 1.206 + entry.addQualifiedName(name); 1.207 + } 1.208 +}