src/share/jaxws_classes/com/sun/xml/internal/fastinfoset/sax/AttributesHolder.java

Wed, 12 Jun 2013 14:47:09 +0100

author
mkos
date
Wed, 12 Jun 2013 14:47:09 +0100
changeset 384
8f2986ff0235
parent 286
f50545b5e2f1
child 637
9c07ef4934dd
permissions
-rw-r--r--

8013021: Rebase 8005432 & 8003542 against the latest jdk8/jaxws
8003542: Improve processing of MTOM attachments
8005432: Update access to JAX-WS
Reviewed-by: mullan

ohair@286 1 /*
mkos@384 2 * Copyright (c) 2004, 2013, Oracle and/or its affiliates. All rights reserved.
ohair@286 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
ohair@286 4 *
ohair@286 5 * This code is free software; you can redistribute it and/or modify it
ohair@286 6 * under the terms of the GNU General Public License version 2 only, as
ohair@286 7 * published by the Free Software Foundation. Oracle designates this
ohair@286 8 * particular file as subject to the "Classpath" exception as provided
ohair@286 9 * by Oracle in the LICENSE file that accompanied this code.
ohair@286 10 *
ohair@286 11 * This code is distributed in the hope that it will be useful, but WITHOUT
ohair@286 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
ohair@286 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
ohair@286 14 * version 2 for more details (a copy is included in the LICENSE file that
ohair@286 15 * accompanied this code).
ohair@286 16 *
ohair@286 17 * You should have received a copy of the GNU General Public License version
ohair@286 18 * 2 along with this work; if not, write to the Free Software Foundation,
ohair@286 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
ohair@286 20 *
ohair@286 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
ohair@286 22 * or visit www.oracle.com if you need additional information or have any
ohair@286 23 * questions.
ohair@286 24 *
ohair@286 25 * THIS FILE WAS MODIFIED BY SUN MICROSYSTEMS, INC.
ohair@286 26 */
ohair@286 27
ohair@286 28 package com.sun.xml.internal.fastinfoset.sax;
ohair@286 29
ohair@286 30 import com.sun.xml.internal.fastinfoset.EncodingConstants;
ohair@286 31 import com.sun.xml.internal.fastinfoset.QualifiedName;
ohair@286 32 import com.sun.xml.internal.fastinfoset.algorithm.BuiltInEncodingAlgorithmFactory;
ohair@286 33 import java.io.IOException;
ohair@286 34 import java.util.Map;
ohair@286 35 import com.sun.xml.internal.org.jvnet.fastinfoset.EncodingAlgorithm;
ohair@286 36 import com.sun.xml.internal.org.jvnet.fastinfoset.EncodingAlgorithmException;
ohair@286 37 import com.sun.xml.internal.org.jvnet.fastinfoset.EncodingAlgorithmIndexes;
ohair@286 38 import com.sun.xml.internal.org.jvnet.fastinfoset.FastInfosetException;
ohair@286 39
ohair@286 40 import com.sun.xml.internal.org.jvnet.fastinfoset.sax.EncodingAlgorithmAttributes;
ohair@286 41 import com.sun.xml.internal.fastinfoset.CommonResourceBundle;
ohair@286 42
ohair@286 43 public class AttributesHolder implements EncodingAlgorithmAttributes {
ohair@286 44 private static final int DEFAULT_CAPACITY = 8;
ohair@286 45
ohair@286 46 private Map _registeredEncodingAlgorithms;
ohair@286 47
ohair@286 48 private int _attributeCount;
ohair@286 49
ohair@286 50 private QualifiedName[] _names;
ohair@286 51 private String[] _values;
ohair@286 52
ohair@286 53 private String[] _algorithmURIs;
ohair@286 54 private int[] _algorithmIds;
ohair@286 55 private Object[] _algorithmData;
ohair@286 56
ohair@286 57 public AttributesHolder() {
ohair@286 58 _names = new QualifiedName[DEFAULT_CAPACITY];
ohair@286 59 _values = new String[DEFAULT_CAPACITY];
ohair@286 60
ohair@286 61 _algorithmURIs = new String[DEFAULT_CAPACITY];
ohair@286 62 _algorithmIds = new int[DEFAULT_CAPACITY];
ohair@286 63 _algorithmData = new Object[DEFAULT_CAPACITY];
ohair@286 64 }
ohair@286 65
ohair@286 66 public AttributesHolder(Map registeredEncodingAlgorithms) {
ohair@286 67 this();
ohair@286 68 _registeredEncodingAlgorithms = registeredEncodingAlgorithms;
ohair@286 69 }
ohair@286 70
ohair@286 71 // org.xml.sax.Attributes
ohair@286 72
ohair@286 73 public final int getLength() {
ohair@286 74 return _attributeCount;
ohair@286 75 }
ohair@286 76
ohair@286 77 public final String getLocalName(int index) {
ohair@286 78 return _names[index].localName;
ohair@286 79 }
ohair@286 80
ohair@286 81 public final String getQName(int index) {
ohair@286 82 return _names[index].getQNameString();
ohair@286 83 }
ohair@286 84
ohair@286 85 public final String getType(int index) {
ohair@286 86 return "CDATA";
ohair@286 87 }
ohair@286 88
ohair@286 89 public final String getURI(int index) {
ohair@286 90 return _names[index].namespaceName;
ohair@286 91 }
ohair@286 92
ohair@286 93 public final String getValue(int index) {
ohair@286 94 final String value = _values[index];
ohair@286 95 if (value != null) {
ohair@286 96 return value;
ohair@286 97 }
ohair@286 98
ohair@286 99 if (_algorithmData[index] == null ||
ohair@286 100 (_algorithmIds[index] >= EncodingConstants.ENCODING_ALGORITHM_APPLICATION_START &&
ohair@286 101 _registeredEncodingAlgorithms == null)) {
ohair@286 102 return null;
ohair@286 103 }
ohair@286 104
ohair@286 105 try {
ohair@286 106 return _values[index] = convertEncodingAlgorithmDataToString(
ohair@286 107 _algorithmIds[index],
ohair@286 108 _algorithmURIs[index],
ohair@286 109 _algorithmData[index]).toString();
ohair@286 110 } catch (IOException e) {
ohair@286 111 return null;
ohair@286 112 } catch (FastInfosetException e) {
ohair@286 113 return null;
ohair@286 114 }
ohair@286 115 }
ohair@286 116
ohair@286 117 public final int getIndex(String qName) {
ohair@286 118 int i = qName.indexOf(':');
ohair@286 119 String prefix = "";
ohair@286 120 String localName = qName;
ohair@286 121 if (i >= 0) {
ohair@286 122 prefix = qName.substring(0, i);
ohair@286 123 localName = qName.substring(i + 1);
ohair@286 124 }
ohair@286 125
ohair@286 126 for (i = 0; i < _attributeCount; i++) {
ohair@286 127 QualifiedName name = _names[i];
ohair@286 128 if (localName.equals(name.localName) &&
ohair@286 129 prefix.equals(name.prefix)) {
ohair@286 130 return i;
ohair@286 131 }
ohair@286 132 }
ohair@286 133 return -1;
ohair@286 134 }
ohair@286 135
ohair@286 136 public final String getType(String qName) {
ohair@286 137 int index = getIndex(qName);
ohair@286 138 if (index >= 0) {
ohair@286 139 return "CDATA";
ohair@286 140 } else {
ohair@286 141 return null;
ohair@286 142 }
ohair@286 143 }
ohair@286 144
ohair@286 145 public final String getValue(String qName) {
ohair@286 146 int index = getIndex(qName);
ohair@286 147 if (index >= 0) {
ohair@286 148 return _values[index];
ohair@286 149 } else {
ohair@286 150 return null;
ohair@286 151 }
ohair@286 152 }
ohair@286 153
ohair@286 154 public final int getIndex(String uri, String localName) {
ohair@286 155 for (int i = 0; i < _attributeCount; i++) {
ohair@286 156 QualifiedName name = _names[i];
ohair@286 157 if (localName.equals(name.localName) &&
ohair@286 158 uri.equals(name.namespaceName)) {
ohair@286 159 return i;
ohair@286 160 }
ohair@286 161 }
ohair@286 162 return -1;
ohair@286 163 }
ohair@286 164
ohair@286 165 public final String getType(String uri, String localName) {
ohair@286 166 int index = getIndex(uri, localName);
ohair@286 167 if (index >= 0) {
ohair@286 168 return "CDATA";
ohair@286 169 } else {
ohair@286 170 return null;
ohair@286 171 }
ohair@286 172 }
ohair@286 173
ohair@286 174 public final String getValue(String uri, String localName) {
ohair@286 175 int index = getIndex(uri, localName);
ohair@286 176 if (index >= 0) {
ohair@286 177 return _values[index];
ohair@286 178 } else {
ohair@286 179 return null;
ohair@286 180 }
ohair@286 181 }
ohair@286 182
ohair@286 183 public final void clear() {
ohair@286 184 for (int i = 0; i < _attributeCount; i++) {
ohair@286 185 _values[i] = null;
ohair@286 186 _algorithmData[i] = null;
ohair@286 187 }
ohair@286 188 _attributeCount = 0;
ohair@286 189 }
ohair@286 190
ohair@286 191 // EncodingAlgorithmAttributes
ohair@286 192
ohair@286 193 public final String getAlgorithmURI(int index) {
ohair@286 194 return _algorithmURIs[index];
ohair@286 195 }
ohair@286 196
ohair@286 197 public final int getAlgorithmIndex(int index) {
ohair@286 198 return _algorithmIds[index];
ohair@286 199 }
ohair@286 200
ohair@286 201 public final Object getAlgorithmData(int index) {
ohair@286 202 return _algorithmData[index];
ohair@286 203 }
ohair@286 204
ohair@286 205 public String getAlpababet(int index) {
ohair@286 206 return null;
ohair@286 207 }
ohair@286 208
ohair@286 209 public boolean getToIndex(int index) {
ohair@286 210 return false;
ohair@286 211 }
ohair@286 212
ohair@286 213 // -----
ohair@286 214
ohair@286 215 public final void addAttribute(QualifiedName name, String value) {
ohair@286 216 if (_attributeCount == _names.length) {
ohair@286 217 resize();
ohair@286 218 }
ohair@286 219 _names[_attributeCount] = name;
ohair@286 220 _values[_attributeCount++] = value;
ohair@286 221 }
ohair@286 222
ohair@286 223 public final void addAttributeWithAlgorithmData(QualifiedName name, String URI, int id, Object data) {
ohair@286 224 if (_attributeCount == _names.length) {
ohair@286 225 resize();
ohair@286 226 }
ohair@286 227 _names[_attributeCount] = name;
ohair@286 228 _values[_attributeCount] = null;
ohair@286 229
ohair@286 230 _algorithmURIs[_attributeCount] = URI;
ohair@286 231 _algorithmIds[_attributeCount] = id;
ohair@286 232 _algorithmData[_attributeCount++] = data;
ohair@286 233 }
ohair@286 234
ohair@286 235 public final QualifiedName getQualifiedName(int index) {
ohair@286 236 return _names[index];
ohair@286 237 }
ohair@286 238
ohair@286 239 public final String getPrefix(int index) {
ohair@286 240 return _names[index].prefix;
ohair@286 241 }
ohair@286 242
ohair@286 243 private final void resize() {
ohair@286 244 final int newLength = _attributeCount * 3 / 2 + 1;
ohair@286 245
ohair@286 246 QualifiedName[] names = new QualifiedName[newLength];
ohair@286 247 String[] values = new String[newLength];
ohair@286 248
ohair@286 249 String[] algorithmURIs = new String[newLength];
ohair@286 250 int[] algorithmIds = new int[newLength];
ohair@286 251 Object[] algorithmData = new Object[newLength];
ohair@286 252
ohair@286 253 System.arraycopy(_names, 0, names, 0, _attributeCount);
ohair@286 254 System.arraycopy(_values, 0, values, 0, _attributeCount);
ohair@286 255
ohair@286 256 System.arraycopy(_algorithmURIs, 0, algorithmURIs, 0, _attributeCount);
ohair@286 257 System.arraycopy(_algorithmIds, 0, algorithmIds, 0, _attributeCount);
ohair@286 258 System.arraycopy(_algorithmData, 0, algorithmData, 0, _attributeCount);
ohair@286 259
ohair@286 260 _names = names;
ohair@286 261 _values = values;
ohair@286 262
ohair@286 263 _algorithmURIs = algorithmURIs;
ohair@286 264 _algorithmIds = algorithmIds;
ohair@286 265 _algorithmData = algorithmData;
ohair@286 266 }
ohair@286 267
ohair@286 268 private final StringBuffer convertEncodingAlgorithmDataToString(int identifier, String URI, Object data) throws FastInfosetException, IOException {
ohair@286 269 EncodingAlgorithm ea = null;
ohair@286 270 if (identifier < EncodingConstants.ENCODING_ALGORITHM_BUILTIN_END) {
ohair@286 271 ea = BuiltInEncodingAlgorithmFactory.getAlgorithm(identifier);
ohair@286 272 } else if (identifier == EncodingAlgorithmIndexes.CDATA) {
ohair@286 273 throw new EncodingAlgorithmException(CommonResourceBundle.getInstance().getString("message.CDATAAlgorithmNotSupported"));
ohair@286 274 } else if (identifier >= EncodingConstants.ENCODING_ALGORITHM_APPLICATION_START) {
ohair@286 275 if (URI == null) {
ohair@286 276 throw new EncodingAlgorithmException(CommonResourceBundle.getInstance().getString("message.URINotPresent") + identifier);
ohair@286 277 }
ohair@286 278
ohair@286 279 ea = (EncodingAlgorithm)_registeredEncodingAlgorithms.get(URI);
ohair@286 280 if (ea == null) {
ohair@286 281 throw new EncodingAlgorithmException(CommonResourceBundle.getInstance().getString("message.algorithmNotRegistered") + URI);
ohair@286 282 }
ohair@286 283 } else {
ohair@286 284 // Reserved built-in algorithms for future use
ohair@286 285 // TODO should use sax property to decide if event will be
ohair@286 286 // reported, allows for support through handler if required.
ohair@286 287 throw new EncodingAlgorithmException(CommonResourceBundle.getInstance().getString("message.identifiers10to31Reserved"));
ohair@286 288 }
ohair@286 289
ohair@286 290 final StringBuffer sb = new StringBuffer();
ohair@286 291 ea.convertToCharacters(data, sb);
ohair@286 292 return sb;
ohair@286 293 }
ohair@286 294
ohair@286 295 }

mercurial