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

Tue, 06 Mar 2012 16:09:35 -0800

author
ohair
date
Tue, 06 Mar 2012 16:09:35 -0800
changeset 286
f50545b5e2f1
parent 0
373ffda63c9a
permissions
-rw-r--r--

7150322: Stop using drop source bundles in jaxws
Reviewed-by: darcy, ohrstrom

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.sax;
aoqi@0 29
aoqi@0 30 import com.sun.xml.internal.fastinfoset.Encoder;
aoqi@0 31 import com.sun.xml.internal.fastinfoset.EncodingConstants;
aoqi@0 32 import com.sun.xml.internal.fastinfoset.QualifiedName;
aoqi@0 33 import com.sun.xml.internal.org.jvnet.fastinfoset.sax.FastInfosetWriter;
aoqi@0 34 import com.sun.xml.internal.fastinfoset.util.LocalNameQualifiedNamesMap;
aoqi@0 35 import java.io.IOException;
aoqi@0 36 import com.sun.xml.internal.org.jvnet.fastinfoset.EncodingAlgorithmIndexes;
aoqi@0 37 import com.sun.xml.internal.org.jvnet.fastinfoset.FastInfosetException;
aoqi@0 38 import com.sun.xml.internal.org.jvnet.fastinfoset.RestrictedAlphabet;
aoqi@0 39 import com.sun.xml.internal.org.jvnet.fastinfoset.sax.EncodingAlgorithmAttributes;
aoqi@0 40 import org.xml.sax.Attributes;
aoqi@0 41 import org.xml.sax.SAXException;
aoqi@0 42 import com.sun.xml.internal.fastinfoset.CommonResourceBundle;
aoqi@0 43
aoqi@0 44 /**
aoqi@0 45 * The Fast Infoset SAX serializer.
aoqi@0 46 * <p>
aoqi@0 47 * Instantiate this serializer to serialize a fast infoset document in accordance
aoqi@0 48 * with the SAX API.
aoqi@0 49 * <p>
aoqi@0 50 * This utilizes the SAX API in a reverse manner to that of parsing. It is the
aoqi@0 51 * responsibility of the client to call the appropriate event methods on the
aoqi@0 52 * SAX handlers, and to ensure that such a sequence of methods calls results
aoqi@0 53 * in the production well-formed fast infoset documents. The
aoqi@0 54 * SAXDocumentSerializer performs no well-formed checks.
aoqi@0 55 *
aoqi@0 56 * <p>
aoqi@0 57 * More than one fast infoset document may be encoded to the
aoqi@0 58 * {@link java.io.OutputStream}.
aoqi@0 59 */
aoqi@0 60 public class SAXDocumentSerializer extends Encoder implements FastInfosetWriter {
aoqi@0 61 protected boolean _elementHasNamespaces = false;
aoqi@0 62
aoqi@0 63 protected boolean _charactersAsCDATA = false;
aoqi@0 64
aoqi@0 65 protected SAXDocumentSerializer(boolean v) {
aoqi@0 66 super(v);
aoqi@0 67 }
aoqi@0 68
aoqi@0 69 public SAXDocumentSerializer() {
aoqi@0 70 }
aoqi@0 71
aoqi@0 72
aoqi@0 73 public void reset() {
aoqi@0 74 super.reset();
aoqi@0 75
aoqi@0 76 _elementHasNamespaces = false;
aoqi@0 77 _charactersAsCDATA = false;
aoqi@0 78 }
aoqi@0 79
aoqi@0 80 // ContentHandler
aoqi@0 81
aoqi@0 82 public final void startDocument() throws SAXException {
aoqi@0 83 try {
aoqi@0 84 reset();
aoqi@0 85 encodeHeader(false);
aoqi@0 86 encodeInitialVocabulary();
aoqi@0 87 } catch (IOException e) {
aoqi@0 88 throw new SAXException("startDocument", e);
aoqi@0 89 }
aoqi@0 90 }
aoqi@0 91
aoqi@0 92 public final void endDocument() throws SAXException {
aoqi@0 93 try {
aoqi@0 94 encodeDocumentTermination();
aoqi@0 95 } catch (IOException e) {
aoqi@0 96 throw new SAXException("endDocument", e);
aoqi@0 97 }
aoqi@0 98 }
aoqi@0 99
aoqi@0 100 public void startPrefixMapping(String prefix, String uri) throws SAXException {
aoqi@0 101 try {
aoqi@0 102 if (_elementHasNamespaces == false) {
aoqi@0 103 encodeTermination();
aoqi@0 104
aoqi@0 105 // Mark the current buffer position to flag attributes if necessary
aoqi@0 106 mark();
aoqi@0 107 _elementHasNamespaces = true;
aoqi@0 108
aoqi@0 109 // Write out Element byte with namespaces
aoqi@0 110 write(EncodingConstants.ELEMENT | EncodingConstants.ELEMENT_NAMESPACES_FLAG);
aoqi@0 111 }
aoqi@0 112
aoqi@0 113 encodeNamespaceAttribute(prefix, uri);
aoqi@0 114 } catch (IOException e) {
aoqi@0 115 throw new SAXException("startElement", e);
aoqi@0 116 }
aoqi@0 117 }
aoqi@0 118
aoqi@0 119 public final void startElement(String namespaceURI, String localName, String qName, Attributes atts) throws SAXException {
aoqi@0 120 // TODO consider using buffer for encoding of attributes, then pre-counting is not necessary
aoqi@0 121 final int attributeCount = (atts != null && atts.getLength() > 0)
aoqi@0 122 ? countAttributes(atts) : 0;
aoqi@0 123 try {
aoqi@0 124 if (_elementHasNamespaces) {
aoqi@0 125 _elementHasNamespaces = false;
aoqi@0 126
aoqi@0 127 if (attributeCount > 0) {
aoqi@0 128 // Flag the marked byte with attributes
aoqi@0 129 _octetBuffer[_markIndex] |= EncodingConstants.ELEMENT_ATTRIBUTE_FLAG;
aoqi@0 130 }
aoqi@0 131 resetMark();
aoqi@0 132
aoqi@0 133 write(EncodingConstants.TERMINATOR);
aoqi@0 134
aoqi@0 135 _b = 0;
aoqi@0 136 } else {
aoqi@0 137 encodeTermination();
aoqi@0 138
aoqi@0 139 _b = EncodingConstants.ELEMENT;
aoqi@0 140 if (attributeCount > 0) {
aoqi@0 141 _b |= EncodingConstants.ELEMENT_ATTRIBUTE_FLAG;
aoqi@0 142 }
aoqi@0 143 }
aoqi@0 144
aoqi@0 145 encodeElement(namespaceURI, qName, localName);
aoqi@0 146
aoqi@0 147 if (attributeCount > 0) {
aoqi@0 148 encodeAttributes(atts);
aoqi@0 149 }
aoqi@0 150 } catch (IOException e) {
aoqi@0 151 throw new SAXException("startElement", e);
aoqi@0 152 } catch (FastInfosetException e) {
aoqi@0 153 throw new SAXException("startElement", e);
aoqi@0 154 }
aoqi@0 155 }
aoqi@0 156
aoqi@0 157 public final void endElement(String namespaceURI, String localName, String qName) throws SAXException {
aoqi@0 158 try {
aoqi@0 159 encodeElementTermination();
aoqi@0 160 } catch (IOException e) {
aoqi@0 161 throw new SAXException("endElement", e);
aoqi@0 162 }
aoqi@0 163 }
aoqi@0 164
aoqi@0 165 public final void characters(char[] ch, int start, int length) throws SAXException {
aoqi@0 166 if (length <= 0) {
aoqi@0 167 return;
aoqi@0 168 }
aoqi@0 169
aoqi@0 170 if (getIgnoreWhiteSpaceTextContent() &&
aoqi@0 171 isWhiteSpace(ch, start, length)) return;
aoqi@0 172
aoqi@0 173 try {
aoqi@0 174 encodeTermination();
aoqi@0 175
aoqi@0 176 if (!_charactersAsCDATA) {
aoqi@0 177 encodeCharacters(ch, start, length);
aoqi@0 178 } else {
aoqi@0 179 encodeCIIBuiltInAlgorithmDataAsCDATA(ch, start, length);
aoqi@0 180 }
aoqi@0 181 } catch (IOException e) {
aoqi@0 182 throw new SAXException(e);
aoqi@0 183 } catch (FastInfosetException e) {
aoqi@0 184 throw new SAXException(e);
aoqi@0 185 }
aoqi@0 186 }
aoqi@0 187
aoqi@0 188 public final void ignorableWhitespace(char[] ch, int start, int length) throws SAXException {
aoqi@0 189 if (getIgnoreWhiteSpaceTextContent()) return;
aoqi@0 190
aoqi@0 191 characters(ch, start, length);
aoqi@0 192 }
aoqi@0 193
aoqi@0 194 public final void processingInstruction(String target, String data) throws SAXException {
aoqi@0 195 try {
aoqi@0 196 if (getIgnoreProcesingInstructions()) return;
aoqi@0 197
aoqi@0 198 if (target.length() == 0) {
aoqi@0 199 throw new SAXException(CommonResourceBundle.getInstance().
aoqi@0 200 getString("message.processingInstructionTargetIsEmpty"));
aoqi@0 201 }
aoqi@0 202 encodeTermination();
aoqi@0 203
aoqi@0 204 encodeProcessingInstruction(target, data);
aoqi@0 205 } catch (IOException e) {
aoqi@0 206 throw new SAXException("processingInstruction", e);
aoqi@0 207 }
aoqi@0 208 }
aoqi@0 209
aoqi@0 210 public final void setDocumentLocator(org.xml.sax.Locator locator) {
aoqi@0 211 }
aoqi@0 212
aoqi@0 213 public final void skippedEntity(String name) throws SAXException {
aoqi@0 214 }
aoqi@0 215
aoqi@0 216
aoqi@0 217
aoqi@0 218 // LexicalHandler
aoqi@0 219
aoqi@0 220 public final void comment(char[] ch, int start, int length) throws SAXException {
aoqi@0 221 try {
aoqi@0 222 if (getIgnoreComments()) return;
aoqi@0 223
aoqi@0 224 encodeTermination();
aoqi@0 225
aoqi@0 226 encodeComment(ch, start, length);
aoqi@0 227 } catch (IOException e) {
aoqi@0 228 throw new SAXException("startElement", e);
aoqi@0 229 }
aoqi@0 230 }
aoqi@0 231
aoqi@0 232 public final void startCDATA() throws SAXException {
aoqi@0 233 _charactersAsCDATA = true;
aoqi@0 234 }
aoqi@0 235
aoqi@0 236 public final void endCDATA() throws SAXException {
aoqi@0 237 _charactersAsCDATA = false;
aoqi@0 238 }
aoqi@0 239
aoqi@0 240 public final void startDTD(String name, String publicId, String systemId) throws SAXException {
aoqi@0 241 if (getIgnoreDTD()) return;
aoqi@0 242
aoqi@0 243 try {
aoqi@0 244 encodeTermination();
aoqi@0 245
aoqi@0 246 encodeDocumentTypeDeclaration(publicId, systemId);
aoqi@0 247 encodeElementTermination();
aoqi@0 248 } catch (IOException e) {
aoqi@0 249 throw new SAXException("startDTD", e);
aoqi@0 250 }
aoqi@0 251 }
aoqi@0 252
aoqi@0 253 public final void endDTD() throws SAXException {
aoqi@0 254 }
aoqi@0 255
aoqi@0 256 public final void startEntity(String name) throws SAXException {
aoqi@0 257 }
aoqi@0 258
aoqi@0 259 public final void endEntity(String name) throws SAXException {
aoqi@0 260 }
aoqi@0 261
aoqi@0 262
aoqi@0 263 // EncodingAlgorithmContentHandler
aoqi@0 264
aoqi@0 265 public final void octets(String URI, int id, byte[] b, int start, int length) throws SAXException {
aoqi@0 266 if (length <= 0) {
aoqi@0 267 return;
aoqi@0 268 }
aoqi@0 269
aoqi@0 270 try {
aoqi@0 271 encodeTermination();
aoqi@0 272
aoqi@0 273 encodeNonIdentifyingStringOnThirdBit(URI, id, b, start, length);
aoqi@0 274 } catch (IOException e) {
aoqi@0 275 throw new SAXException(e);
aoqi@0 276 } catch (FastInfosetException e) {
aoqi@0 277 throw new SAXException(e);
aoqi@0 278 }
aoqi@0 279 }
aoqi@0 280
aoqi@0 281 public final void object(String URI, int id, Object data) throws SAXException {
aoqi@0 282 try {
aoqi@0 283 encodeTermination();
aoqi@0 284
aoqi@0 285 encodeNonIdentifyingStringOnThirdBit(URI, id, data);
aoqi@0 286 } catch (IOException e) {
aoqi@0 287 throw new SAXException(e);
aoqi@0 288 } catch (FastInfosetException e) {
aoqi@0 289 throw new SAXException(e);
aoqi@0 290 }
aoqi@0 291 }
aoqi@0 292
aoqi@0 293
aoqi@0 294 // PrimitiveTypeContentHandler
aoqi@0 295
aoqi@0 296 public final void bytes(byte[] b, int start, int length) throws SAXException {
aoqi@0 297 if (length <= 0) {
aoqi@0 298 return;
aoqi@0 299 }
aoqi@0 300
aoqi@0 301 try {
aoqi@0 302 encodeTermination();
aoqi@0 303
aoqi@0 304 encodeCIIOctetAlgorithmData(EncodingAlgorithmIndexes.BASE64, b, start, length);
aoqi@0 305 } catch (IOException e) {
aoqi@0 306 throw new SAXException(e);
aoqi@0 307 }
aoqi@0 308 }
aoqi@0 309
aoqi@0 310 public final void shorts(short[] s, int start, int length) throws SAXException {
aoqi@0 311 if (length <= 0) {
aoqi@0 312 return;
aoqi@0 313 }
aoqi@0 314
aoqi@0 315 try {
aoqi@0 316 encodeTermination();
aoqi@0 317
aoqi@0 318 encodeCIIBuiltInAlgorithmData(EncodingAlgorithmIndexes.SHORT, s, start, length);
aoqi@0 319 } catch (IOException e) {
aoqi@0 320 throw new SAXException(e);
aoqi@0 321 } catch (FastInfosetException e) {
aoqi@0 322 throw new SAXException(e);
aoqi@0 323 }
aoqi@0 324 }
aoqi@0 325
aoqi@0 326 public final void ints(int[] i, int start, int length) throws SAXException {
aoqi@0 327 if (length <= 0) {
aoqi@0 328 return;
aoqi@0 329 }
aoqi@0 330
aoqi@0 331 try {
aoqi@0 332 encodeTermination();
aoqi@0 333
aoqi@0 334 encodeCIIBuiltInAlgorithmData(EncodingAlgorithmIndexes.INT, i, start, length);
aoqi@0 335 } catch (IOException e) {
aoqi@0 336 throw new SAXException(e);
aoqi@0 337 } catch (FastInfosetException e) {
aoqi@0 338 throw new SAXException(e);
aoqi@0 339 }
aoqi@0 340 }
aoqi@0 341
aoqi@0 342 public final void longs(long[] l, int start, int length) throws SAXException {
aoqi@0 343 if (length <= 0) {
aoqi@0 344 return;
aoqi@0 345 }
aoqi@0 346
aoqi@0 347 try {
aoqi@0 348 encodeTermination();
aoqi@0 349
aoqi@0 350 encodeCIIBuiltInAlgorithmData(EncodingAlgorithmIndexes.LONG, l, start, length);
aoqi@0 351 } catch (IOException e) {
aoqi@0 352 throw new SAXException(e);
aoqi@0 353 } catch (FastInfosetException e) {
aoqi@0 354 throw new SAXException(e);
aoqi@0 355 }
aoqi@0 356 }
aoqi@0 357
aoqi@0 358 public final void booleans(boolean[] b, int start, int length) throws SAXException {
aoqi@0 359 if (length <= 0) {
aoqi@0 360 return;
aoqi@0 361 }
aoqi@0 362
aoqi@0 363 try {
aoqi@0 364 encodeTermination();
aoqi@0 365
aoqi@0 366 encodeCIIBuiltInAlgorithmData(EncodingAlgorithmIndexes.BOOLEAN, b, start, length);
aoqi@0 367 } catch (IOException e) {
aoqi@0 368 throw new SAXException(e);
aoqi@0 369 } catch (FastInfosetException e) {
aoqi@0 370 throw new SAXException(e);
aoqi@0 371 }
aoqi@0 372 }
aoqi@0 373
aoqi@0 374 public final void floats(float[] f, int start, int length) throws SAXException {
aoqi@0 375 if (length <= 0) {
aoqi@0 376 return;
aoqi@0 377 }
aoqi@0 378
aoqi@0 379 try {
aoqi@0 380 encodeTermination();
aoqi@0 381
aoqi@0 382 encodeCIIBuiltInAlgorithmData(EncodingAlgorithmIndexes.FLOAT, f, start, length);
aoqi@0 383 } catch (IOException e) {
aoqi@0 384 throw new SAXException(e);
aoqi@0 385 } catch (FastInfosetException e) {
aoqi@0 386 throw new SAXException(e);
aoqi@0 387 }
aoqi@0 388 }
aoqi@0 389
aoqi@0 390 public final void doubles(double[] d, int start, int length) throws SAXException {
aoqi@0 391 if (length <= 0) {
aoqi@0 392 return;
aoqi@0 393 }
aoqi@0 394
aoqi@0 395 try {
aoqi@0 396 encodeTermination();
aoqi@0 397
aoqi@0 398 encodeCIIBuiltInAlgorithmData(EncodingAlgorithmIndexes.DOUBLE, d, start, length);
aoqi@0 399 } catch (IOException e) {
aoqi@0 400 throw new SAXException(e);
aoqi@0 401 } catch (FastInfosetException e) {
aoqi@0 402 throw new SAXException(e);
aoqi@0 403 }
aoqi@0 404 }
aoqi@0 405
aoqi@0 406 public void uuids(long[] msblsb, int start, int length) throws SAXException {
aoqi@0 407 if (length <= 0) {
aoqi@0 408 return;
aoqi@0 409 }
aoqi@0 410
aoqi@0 411 try {
aoqi@0 412 encodeTermination();
aoqi@0 413
aoqi@0 414 encodeCIIBuiltInAlgorithmData(EncodingAlgorithmIndexes.UUID, msblsb, start, length);
aoqi@0 415 } catch (IOException e) {
aoqi@0 416 throw new SAXException(e);
aoqi@0 417 } catch (FastInfosetException e) {
aoqi@0 418 throw new SAXException(e);
aoqi@0 419 }
aoqi@0 420 }
aoqi@0 421
aoqi@0 422
aoqi@0 423 // RestrictedAlphabetContentHandler
aoqi@0 424
aoqi@0 425 public void numericCharacters(char ch[], int start, int length) throws SAXException {
aoqi@0 426 if (length <= 0) {
aoqi@0 427 return;
aoqi@0 428 }
aoqi@0 429
aoqi@0 430 try {
aoqi@0 431 encodeTermination();
aoqi@0 432
aoqi@0 433 final boolean addToTable = isCharacterContentChunkLengthMatchesLimit(length);
aoqi@0 434 encodeNumericFourBitCharacters(ch, start, length, addToTable);
aoqi@0 435 } catch (IOException e) {
aoqi@0 436 throw new SAXException(e);
aoqi@0 437 } catch (FastInfosetException e) {
aoqi@0 438 throw new SAXException(e);
aoqi@0 439 }
aoqi@0 440 }
aoqi@0 441
aoqi@0 442 public void dateTimeCharacters(char ch[], int start, int length) throws SAXException {
aoqi@0 443 if (length <= 0) {
aoqi@0 444 return;
aoqi@0 445 }
aoqi@0 446
aoqi@0 447 try {
aoqi@0 448 encodeTermination();
aoqi@0 449
aoqi@0 450 final boolean addToTable = isCharacterContentChunkLengthMatchesLimit(length);
aoqi@0 451 encodeDateTimeFourBitCharacters(ch, start, length, addToTable);
aoqi@0 452 } catch (IOException e) {
aoqi@0 453 throw new SAXException(e);
aoqi@0 454 } catch (FastInfosetException e) {
aoqi@0 455 throw new SAXException(e);
aoqi@0 456 }
aoqi@0 457 }
aoqi@0 458
aoqi@0 459 public void alphabetCharacters(String alphabet, char ch[], int start, int length) throws SAXException {
aoqi@0 460 if (length <= 0) {
aoqi@0 461 return;
aoqi@0 462 }
aoqi@0 463
aoqi@0 464 try {
aoqi@0 465 encodeTermination();
aoqi@0 466
aoqi@0 467 final boolean addToTable = isCharacterContentChunkLengthMatchesLimit(length);
aoqi@0 468 encodeAlphabetCharacters(alphabet, ch, start, length, addToTable);
aoqi@0 469 } catch (IOException e) {
aoqi@0 470 throw new SAXException(e);
aoqi@0 471 } catch (FastInfosetException e) {
aoqi@0 472 throw new SAXException(e);
aoqi@0 473 }
aoqi@0 474 }
aoqi@0 475
aoqi@0 476 // ExtendedContentHandler
aoqi@0 477
aoqi@0 478 public void characters(char[] ch, int start, int length, boolean index) throws SAXException {
aoqi@0 479 if (length <= 0) {
aoqi@0 480 return;
aoqi@0 481 }
aoqi@0 482
aoqi@0 483 if (getIgnoreWhiteSpaceTextContent() &&
aoqi@0 484 isWhiteSpace(ch, start, length)) return;
aoqi@0 485
aoqi@0 486 try {
aoqi@0 487 encodeTermination();
aoqi@0 488
aoqi@0 489 if (!_charactersAsCDATA) {
aoqi@0 490 encodeNonIdentifyingStringOnThirdBit(ch, start, length, _v.characterContentChunk, index, true);
aoqi@0 491 } else {
aoqi@0 492 encodeCIIBuiltInAlgorithmDataAsCDATA(ch, start, length);
aoqi@0 493 }
aoqi@0 494 } catch (IOException e) {
aoqi@0 495 throw new SAXException(e);
aoqi@0 496 } catch (FastInfosetException e) {
aoqi@0 497 throw new SAXException(e);
aoqi@0 498 }
aoqi@0 499 }
aoqi@0 500
aoqi@0 501
aoqi@0 502
aoqi@0 503 protected final int countAttributes(Attributes atts) {
aoqi@0 504 // Count attributes ignoring any in the XMLNS namespace
aoqi@0 505 // Note, such attributes may be produced when transforming from a DOM node
aoqi@0 506 int count = 0;
aoqi@0 507 for (int i = 0; i < atts.getLength(); i++) {
aoqi@0 508 final String uri = atts.getURI(i);
aoqi@0 509 if (uri == "http://www.w3.org/2000/xmlns/" || uri.equals("http://www.w3.org/2000/xmlns/")) {
aoqi@0 510 continue;
aoqi@0 511 }
aoqi@0 512 count++;
aoqi@0 513 }
aoqi@0 514 return count;
aoqi@0 515 }
aoqi@0 516
aoqi@0 517 protected void encodeAttributes(Attributes atts) throws IOException, FastInfosetException {
aoqi@0 518 boolean addToTable;
aoqi@0 519 boolean mustBeAddedToTable;
aoqi@0 520 String value;
aoqi@0 521 if (atts instanceof EncodingAlgorithmAttributes) {
aoqi@0 522 final EncodingAlgorithmAttributes eAtts = (EncodingAlgorithmAttributes)atts;
aoqi@0 523 Object data;
aoqi@0 524 String alphabet;
aoqi@0 525 for (int i = 0; i < eAtts.getLength(); i++) {
aoqi@0 526 if (encodeAttribute(atts.getURI(i), atts.getQName(i), atts.getLocalName(i))) {
aoqi@0 527 data = eAtts.getAlgorithmData(i);
aoqi@0 528 // If data is null then there is no algorithm data
aoqi@0 529 if (data == null) {
aoqi@0 530 value = eAtts.getValue(i);
aoqi@0 531 addToTable = isAttributeValueLengthMatchesLimit(value.length());
aoqi@0 532 mustBeAddedToTable = eAtts.getToIndex(i);
aoqi@0 533
aoqi@0 534 alphabet = eAtts.getAlpababet(i);
aoqi@0 535 if (alphabet == null) {
aoqi@0 536 encodeNonIdentifyingStringOnFirstBit(value, _v.attributeValue, addToTable, mustBeAddedToTable);
aoqi@0 537 } else if (alphabet == RestrictedAlphabet.DATE_TIME_CHARACTERS) {
aoqi@0 538 encodeDateTimeNonIdentifyingStringOnFirstBit(
aoqi@0 539 value, addToTable, mustBeAddedToTable);
aoqi@0 540 } else if (alphabet == RestrictedAlphabet.NUMERIC_CHARACTERS) {
aoqi@0 541 encodeNumericNonIdentifyingStringOnFirstBit(
aoqi@0 542 value, addToTable, mustBeAddedToTable);
aoqi@0 543 } else {
aoqi@0 544 encodeNonIdentifyingStringOnFirstBit(value, _v.attributeValue, addToTable, mustBeAddedToTable);
aoqi@0 545 }
aoqi@0 546 } else {
aoqi@0 547 encodeNonIdentifyingStringOnFirstBit(eAtts.getAlgorithmURI(i),
aoqi@0 548 eAtts.getAlgorithmIndex(i), data);
aoqi@0 549 }
aoqi@0 550 }
aoqi@0 551 }
aoqi@0 552 } else {
aoqi@0 553 for (int i = 0; i < atts.getLength(); i++) {
aoqi@0 554 if (encodeAttribute(atts.getURI(i), atts.getQName(i), atts.getLocalName(i))) {
aoqi@0 555 value = atts.getValue(i);
aoqi@0 556 addToTable = isAttributeValueLengthMatchesLimit(value.length());
aoqi@0 557 encodeNonIdentifyingStringOnFirstBit(value, _v.attributeValue, addToTable, false);
aoqi@0 558 }
aoqi@0 559 }
aoqi@0 560 }
aoqi@0 561 _b = EncodingConstants.TERMINATOR;
aoqi@0 562 _terminate = true;
aoqi@0 563 }
aoqi@0 564
aoqi@0 565 protected void encodeElement(String namespaceURI, String qName, String localName) throws IOException {
aoqi@0 566 LocalNameQualifiedNamesMap.Entry entry = _v.elementName.obtainEntry(qName);
aoqi@0 567 if (entry._valueIndex > 0) {
aoqi@0 568 QualifiedName[] names = entry._value;
aoqi@0 569 for (int i = 0; i < entry._valueIndex; i++) {
aoqi@0 570 final QualifiedName n = names[i];
aoqi@0 571 if ((namespaceURI == n.namespaceName || namespaceURI.equals(n.namespaceName))) {
aoqi@0 572 encodeNonZeroIntegerOnThirdBit(names[i].index);
aoqi@0 573 return;
aoqi@0 574 }
aoqi@0 575 }
aoqi@0 576 }
aoqi@0 577
aoqi@0 578 encodeLiteralElementQualifiedNameOnThirdBit(namespaceURI, getPrefixFromQualifiedName(qName),
aoqi@0 579 localName, entry);
aoqi@0 580 }
aoqi@0 581
aoqi@0 582 protected boolean encodeAttribute(String namespaceURI, String qName, String localName) throws IOException {
aoqi@0 583 LocalNameQualifiedNamesMap.Entry entry = _v.attributeName.obtainEntry(qName);
aoqi@0 584 if (entry._valueIndex > 0) {
aoqi@0 585 QualifiedName[] names = entry._value;
aoqi@0 586 for (int i = 0; i < entry._valueIndex; i++) {
aoqi@0 587 if ((namespaceURI == names[i].namespaceName || namespaceURI.equals(names[i].namespaceName))) {
aoqi@0 588 encodeNonZeroIntegerOnSecondBitFirstBitZero(names[i].index);
aoqi@0 589 return true;
aoqi@0 590 }
aoqi@0 591 }
aoqi@0 592 }
aoqi@0 593
aoqi@0 594 return encodeLiteralAttributeQualifiedNameOnSecondBit(namespaceURI, getPrefixFromQualifiedName(qName),
aoqi@0 595 localName, entry);
aoqi@0 596 }
aoqi@0 597 }

mercurial