com.ctc.wstx.sw
Class TypedStreamWriter

java.lang.Object
  extended by org.codehaus.stax2.ri.Stax2WriterImpl
      extended by com.ctc.wstx.sw.BaseStreamWriter
          extended by com.ctc.wstx.sw.TypedStreamWriter
All Implemented Interfaces:
OutputConfigFlags, XMLStreamConstants, XMLStreamWriter, TypedXMLStreamWriter, Validatable, ValidationContext, XMLStreamWriter2
Direct Known Subclasses:
BaseNsStreamWriter, NonNsStreamWriter

public abstract class TypedStreamWriter
extends BaseStreamWriter

Intermediate base class that implements Typed Access API (Stax2 v3) for all (repairing, non-repairing, non-namespace) native stream writer implementations.


Field Summary
protected  ValueEncoderFactory mValueEncoderFactory
          When outputting using Typed Access API, we will need encoders.
 
Fields inherited from class com.ctc.wstx.sw.BaseStreamWriter
ATTR_MIN_ARRAYCOPY, CHAR_SPACE, DEFAULT_COPYBUFFER_LEN, mAnyOutput, mCfgAutomaticEmptyElems, mCfgCDataAsText, mCfgCopyDefaultAttrs, mCheckAttrs, mCheckStructure, mConfig, mCopyBuffer, mDtdRootElem, mEmptyElement, mEncoding, MIN_ARRAYCOPY, mReturnNullForDefaultNamespace, mStartElementOpen, mState, mValidator, mVldContent, mVldProbHandler, mWriter, mXml11, STATE_EPILOG, STATE_PROLOG, STATE_TREE
 
Fields inherited from interface com.ctc.wstx.cfg.OutputConfigFlags
CFG_ADD_SPACE_AFTER_EMPTY_ELEM, CFG_AUTO_CLOSE_OUTPUT, CFG_AUTOMATIC_EMPTY_ELEMENTS, CFG_AUTOMATIC_END_ELEMENTS, CFG_AUTOMATIC_NS, CFG_COPY_DEFAULT_ATTRS, CFG_ENABLE_NS, CFG_ESCAPE_CR, CFG_FIX_CONTENT, CFG_OUTPUT_CDATA_AS_TEXT, CFG_VALIDATE_ATTR, CFG_VALIDATE_CONTENT, CFG_VALIDATE_NAMES, CFG_VALIDATE_STRUCTURE
 
Fields inherited from interface javax.xml.stream.XMLStreamConstants
ATTRIBUTE, CDATA, CHARACTERS, COMMENT, DTD, END_DOCUMENT, END_ELEMENT, ENTITY_DECLARATION, ENTITY_REFERENCE, NAMESPACE, NOTATION_DECLARATION, PROCESSING_INSTRUCTION, SPACE, START_DOCUMENT, START_ELEMENT
 
Constructor Summary
protected TypedStreamWriter(XmlWriter xw, String enc, WriterConfig cfg)
           
 
Method Summary
protected  ValueEncoderFactory valueEncoderFactory()
           
 void writeBinary(Base64Variant v, byte[] value, int from, int length)
           
 void writeBinary(byte[] value, int from, int length)
           Write binary content as base64 encoded characters to the output.
 void writeBinaryAttribute(Base64Variant v, String prefix, String nsURI, String localName, byte[] value)
           
 void writeBinaryAttribute(String prefix, String nsURI, String localName, byte[] value)
          Write a byte array attribute.
 void writeBoolean(boolean value)
          Write a boolean value to the output as textual element content.
 void writeBooleanAttribute(String prefix, String nsURI, String localName, boolean value)
          Write a boolean value to the output as attribute value.
 void writeDecimal(BigDecimal value)
          Write a decimal value to the output as textual element content.
 void writeDecimalAttribute(String prefix, String nsURI, String localName, BigDecimal value)
           
 void writeDouble(double value)
          Write a double value to the output as textual element content.
 void writeDoubleArray(double[] value, int from, int length)
           
 void writeDoubleArrayAttribute(String prefix, String nsURI, String localName, double[] value)
           
 void writeDoubleAttribute(String prefix, String nsURI, String localName, double value)
           
 void writeFloat(float value)
          Write a float value to the output as textual element content.
 void writeFloatArray(float[] value, int from, int length)
           
 void writeFloatArrayAttribute(String prefix, String nsURI, String localName, float[] value)
           
 void writeFloatAttribute(String prefix, String nsURI, String localName, float value)
           
 void writeInt(int value)
          Write an int value to the output as textual element content.
 void writeIntArray(int[] value, int from, int length)
          Write int array to the output.
 void writeIntArrayAttribute(String prefix, String nsURI, String localName, int[] value)
          Write int array attribute.
 void writeIntAttribute(String prefix, String nsURI, String localName, int value)
          Write an integer value to the output as attribute value.
 void writeInteger(BigInteger value)
           
 void writeIntegerAttribute(String prefix, String nsURI, String localName, BigInteger value)
           
 void writeLong(long value)
          Write a long value to the output as textual element content.
 void writeLongArray(long[] value, int from, int length)
           
 void writeLongArrayAttribute(String prefix, String nsURI, String localName, long[] value)
           
 void writeLongAttribute(String prefix, String nsURI, String localName, long value)
          Write an long value to the output as attribute value.
 void writeQName(QName name)
           
 void writeQNameAttribute(String prefix, String nsURI, String localName, QName name)
           
protected abstract  void writeTypedAttribute(String prefix, String nsURI, String localName, AsciiValueEncoder enc)
          Method that will write attribute with value that is known not to require additional escaping.
protected  void writeTypedElement(AsciiValueEncoder enc)
           
 
Methods inherited from class com.ctc.wstx.sw.BaseStreamWriter
addDefaultAttribute, close, closeCompletely, closeStartElement, copyEventFromReader, copyStartElement, doReportProblem, doReportProblem, doWriteStartDocument, findAttributeIndex, flush, getAttributeCount, getAttributeLocalName, getAttributeNamespace, getAttributePrefix, getAttributeType, getAttributeValue, getAttributeValue, getBaseUri, getCopyBuffer, getCopyBuffer, getCurrentElementName, getEncoding, getLocation, getNamespaceContext, getNamespaceURI, getPrefix, getProperty, getTopElementDesc, getValidationLocation, getXmlVersion, inPrologOrEpilog, isNotationDeclared, isPropertySupported, isUnparsedEntityDeclared, isValidating, reportIllegalArg, reportIllegalMethod, reportInvalidContent, reportNwfAttr, reportNwfAttr, reportNwfContent, reportNwfContent, reportNwfStructure, reportNwfStructure, reportProblem, reportValidationProblem, reportValidationProblem, reportValidationProblem, reportValidationProblem, reportValidationProblem, reportValidationProblem, setDefaultNamespace, setNamespaceContext, setPrefix, setProperty, setValidationProblemHandler, stopValidatingAgainst, stopValidatingAgainst, throwFromIOE, throwOutputError, throwOutputError, toString, validateAgainst, validateQNamePrefix, verifyRootElement, verifyWriteCData, verifyWriteDTD, wrapAsRawWriter, wrapAsTextWriter, writeAttribute, writeAttribute, writeAttribute, writeCData, writeCData, writeCharacters, writeCharacters, writeCharacters, writeComment, writeDefaultNamespace, writeDTD, writeDTD, writeDTD, writeEmptyElement, writeEmptyElement, writeEmptyElement, writeEndDocument, writeEndElement, writeEndElement, writeEntityRef, writeFullEndElement, writeNamespace, writeProcessingInstruction, writeProcessingInstruction, writeRaw, writeRaw, writeRaw, writeSpace, writeSpace, writeStartDocument, writeStartDocument, writeStartDocument, writeStartDocument, writeStartElement, writeStartElement, writeStartElement, writeStartElement
 
Methods inherited from class org.codehaus.stax2.ri.Stax2WriterImpl
copyStartElement
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

mValueEncoderFactory

protected ValueEncoderFactory mValueEncoderFactory
When outputting using Typed Access API, we will need encoders. If so, they will created by lazily-constructed factory

Constructor Detail

TypedStreamWriter

protected TypedStreamWriter(XmlWriter xw,
                            String enc,
                            WriterConfig cfg)
Method Detail

valueEncoderFactory

protected final ValueEncoderFactory valueEncoderFactory()

writeBoolean

public void writeBoolean(boolean value)
                  throws XMLStreamException
Description copied from interface: TypedXMLStreamWriter
Write a boolean value to the output as textual element content. The lexical representation of content is defined by the XML Schema boolean data type.

Parameters:
value - The boolean value to write.
Throws:
XMLStreamException

writeInt

public void writeInt(int value)
              throws XMLStreamException
Description copied from interface: TypedXMLStreamWriter
Write an int value to the output as textual element content. The lexical representation of content is defined by the XML Schema integer data type.

Throws:
XMLStreamException

writeLong

public void writeLong(long value)
               throws XMLStreamException
Description copied from interface: TypedXMLStreamWriter
Write a long value to the output as textual element content. The lexical representation of content is defined by the XML Schema long data type.

Throws:
XMLStreamException

writeFloat

public void writeFloat(float value)
                throws XMLStreamException
Description copied from interface: TypedXMLStreamWriter
Write a float value to the output as textual element content. The lexical representation of content is defined by the XML Schema float data type.

Throws:
XMLStreamException

writeDouble

public void writeDouble(double value)
                 throws XMLStreamException
Description copied from interface: TypedXMLStreamWriter
Write a double value to the output as textual element content. The lexical representation of content is defined by the XML Schema double data type.

Throws:
XMLStreamException

writeInteger

public void writeInteger(BigInteger value)
                  throws XMLStreamException
Throws:
XMLStreamException

writeDecimal

public void writeDecimal(BigDecimal value)
                  throws XMLStreamException
Description copied from interface: TypedXMLStreamWriter
Write a decimal value to the output as textual element content. The lexical representation of content is defined by the XML Schema decimal data type.

Throws:
XMLStreamException

writeQName

public void writeQName(QName name)
                throws XMLStreamException
Throws:
XMLStreamException

writeIntArray

public final void writeIntArray(int[] value,
                                int from,
                                int length)
                         throws XMLStreamException
Description copied from interface: TypedXMLStreamWriter

Write int array to the output. The lexical representation of a int array is defined by the following XML schema type:

    <xs:simpleType name="intArray">
       <xs:list itemType="xs:int"/>
    </xs:simpleType>
whose lexical space is a list of space-separated ints. This method can be called multiple times to write the array in chunks.

Parameters:
value - The array from which to write the ints.
from - The index in the array from which writing starts.
length - The number of ints to write.
Throws:
XMLStreamException

writeLongArray

public void writeLongArray(long[] value,
                           int from,
                           int length)
                    throws XMLStreamException
Throws:
XMLStreamException

writeFloatArray

public void writeFloatArray(float[] value,
                            int from,
                            int length)
                     throws XMLStreamException
Throws:
XMLStreamException

writeDoubleArray

public void writeDoubleArray(double[] value,
                             int from,
                             int length)
                      throws XMLStreamException
Throws:
XMLStreamException

writeBinary

public void writeBinary(byte[] value,
                        int from,
                        int length)
                 throws XMLStreamException
Description copied from interface: TypedXMLStreamWriter

Write binary content as base64 encoded characters to the output. The lexical representation of a byte array is defined by the XML Schema base64Binary data type. This method can be called multiple times to write the array in chunks; but if so, callers should write output in chunks divisible by 3 (natural atomic unit of base64 output, which avoids padding) to maximize interoperability.

Note: base64 variant defaults to Base64Variants.MIME.

Parameters:
value - The array from which to write the bytes.
from - The index in the array from which writing starts.
length - The number of bytes to write.
Throws:
XMLStreamException

writeBinary

public void writeBinary(Base64Variant v,
                        byte[] value,
                        int from,
                        int length)
                 throws XMLStreamException
Throws:
XMLStreamException

writeTypedElement

protected final void writeTypedElement(AsciiValueEncoder enc)
                                throws XMLStreamException
Throws:
XMLStreamException

writeBooleanAttribute

public void writeBooleanAttribute(String prefix,
                                  String nsURI,
                                  String localName,
                                  boolean value)
                           throws XMLStreamException
Description copied from interface: TypedXMLStreamWriter
Write a boolean value to the output as attribute value. The lexical representation of content is defined by the XML Schema boolean data type.

Parameters:
prefix - The attribute's prefix. Null or "" if no prefix is to be used
nsURI - The attribute's URI (can be either null or empty String for "no namespace")
localName - The attribute's local name
value - The boolean value to write.
Throws:
XMLStreamException

writeIntAttribute

public void writeIntAttribute(String prefix,
                              String nsURI,
                              String localName,
                              int value)
                       throws XMLStreamException
Description copied from interface: TypedXMLStreamWriter
Write an integer value to the output as attribute value. The lexical representation of content is defined by the XML Schema integer data type.

Parameters:
prefix - The attribute's prefix. Null or "" if no prefix is to be used
nsURI - The attribute's URI (can be either null or empty String for "no namespace")
localName - The attribute's local name
value - The integer value to write.
Throws:
XMLStreamException

writeLongAttribute

public void writeLongAttribute(String prefix,
                               String nsURI,
                               String localName,
                               long value)
                        throws XMLStreamException
Description copied from interface: TypedXMLStreamWriter
Write an long value to the output as attribute value. The lexical representation of content is defined by the XML Schema long data type.

Parameters:
prefix - The attribute's prefix. Null or "" if no prefix is to be used
nsURI - The attribute's URI (can be either null or empty String for "no namespace")
localName - The attribute's local name
value - The long value to write.
Throws:
XMLStreamException

writeFloatAttribute

public void writeFloatAttribute(String prefix,
                                String nsURI,
                                String localName,
                                float value)
                         throws XMLStreamException
Throws:
XMLStreamException

writeDoubleAttribute

public void writeDoubleAttribute(String prefix,
                                 String nsURI,
                                 String localName,
                                 double value)
                          throws XMLStreamException
Throws:
XMLStreamException

writeIntegerAttribute

public void writeIntegerAttribute(String prefix,
                                  String nsURI,
                                  String localName,
                                  BigInteger value)
                           throws XMLStreamException
Throws:
XMLStreamException

writeDecimalAttribute

public void writeDecimalAttribute(String prefix,
                                  String nsURI,
                                  String localName,
                                  BigDecimal value)
                           throws XMLStreamException
Throws:
XMLStreamException

writeQNameAttribute

public void writeQNameAttribute(String prefix,
                                String nsURI,
                                String localName,
                                QName name)
                         throws XMLStreamException
Throws:
XMLStreamException

writeIntArrayAttribute

public void writeIntArrayAttribute(String prefix,
                                   String nsURI,
                                   String localName,
                                   int[] value)
                            throws XMLStreamException
Description copied from interface: TypedXMLStreamWriter

Write int array attribute. The lexical representation of a int array is defined by the following XML schema type:

    <xs:simpleType name="intArray">
       <xs:list itemType="xs:int"/>
    </xs:simpleType>
whose lexical space is a list of space-separated ints.

Parameters:
prefix - The attribute's prefix.
nsURI - The attribute's URI.
localName - The attribute's local name.
value - The array from which to write the ints.
Throws:
XMLStreamException

writeLongArrayAttribute

public void writeLongArrayAttribute(String prefix,
                                    String nsURI,
                                    String localName,
                                    long[] value)
                             throws XMLStreamException
Throws:
XMLStreamException

writeFloatArrayAttribute

public void writeFloatArrayAttribute(String prefix,
                                     String nsURI,
                                     String localName,
                                     float[] value)
                              throws XMLStreamException
Throws:
XMLStreamException

writeDoubleArrayAttribute

public void writeDoubleArrayAttribute(String prefix,
                                      String nsURI,
                                      String localName,
                                      double[] value)
                               throws XMLStreamException
Throws:
XMLStreamException

writeBinaryAttribute

public void writeBinaryAttribute(String prefix,
                                 String nsURI,
                                 String localName,
                                 byte[] value)
                          throws XMLStreamException
Description copied from interface: TypedXMLStreamWriter

Write a byte array attribute. The lexical representation of a byte array is defined by the XML Schema base64Binary data type.

Note: base64 variant defaults to Base64Variants.MIME.

Parameters:
prefix - The attribute's prefix.
nsURI - The attribute's URI.
localName - The attribute's local name.
value - The array from which to write the bytes.
Throws:
XMLStreamException

writeBinaryAttribute

public void writeBinaryAttribute(Base64Variant v,
                                 String prefix,
                                 String nsURI,
                                 String localName,
                                 byte[] value)
                          throws XMLStreamException
Throws:
XMLStreamException

writeTypedAttribute

protected abstract void writeTypedAttribute(String prefix,
                                            String nsURI,
                                            String localName,
                                            AsciiValueEncoder enc)
                                     throws XMLStreamException
Method that will write attribute with value that is known not to require additional escaping.

Throws:
XMLStreamException