org.fudgemsg.xml
Class FudgeXMLStreamWriter

java.lang.Object
  extended by org.fudgemsg.xml.FudgeXMLSettings
      extended by org.fudgemsg.xml.FudgeXMLStreamWriter
All Implemented Interfaces:
Closeable, Flushable, FudgeStreamWriter

public class FudgeXMLStreamWriter
extends FudgeXMLSettings
implements FudgeStreamWriter

Implementation of a FudgeStreamWriter that writes XML to a text stream. This can be used for XML output, or can be used to assist in developing/debugging a streaming serializer without having to inspect the binary output from a FudgeDataOutputStreamWriter.

This code should adhere to the XML Fudge Message specification.

Note that no pretty printing options are available here. This implementation uses the systems default XMLOutputFactory if only passed a Writer object at construction. If you require control over the output, you will need to use a suitable XMLStreamWriter implementation that allows it. For example javanet.staxutils.


Nested Class Summary
 
Nested classes/interfaces inherited from class org.fudgemsg.xml.FudgeXMLSettings
FudgeXMLSettings.XMLEnvelopeAttribute, FudgeXMLSettings.XMLFieldAttribute
 
Field Summary
 
Fields inherited from class org.fudgemsg.xml.FudgeXMLSettings
ALIAS_BOOLEAN_FALSE_0, ALIAS_BOOLEAN_FALSE_F, ALIAS_BOOLEAN_FALSE_OFF, ALIAS_BOOLEAN_TRUE_1, ALIAS_BOOLEAN_TRUE_ON, ALIAS_BOOLEAN_TRUE_T, ALIAS_FIELD_ATTRIBUTE_ORDINAL_INDEX, ALIAS_FIELD_ATTRIBUTE_ORDINAL_KEY, DEFAULT_BOOLEAN_FALSE, DEFAULT_BOOLEAN_TRUE, DEFAULT_ENCODING_BASE64, DEFAULT_ENVELOPE_ATTRIBUTE_PROCESSINGDIRECTIVES, DEFAULT_ENVELOPE_ATTRIBUTE_SCHEMAVERSION, DEFAULT_ENVELOPE_ATTRIBUTE_TAXONOMY, DEFAULT_ENVELOPE_ELEMENT, DEFAULT_FIELD_ATTRIBUTE_ENCODING, DEFAULT_FIELD_ATTRIBUTE_NAME, DEFAULT_FIELD_ATTRIBUTE_ORDINAL, DEFAULT_FIELD_ATTRIBUTE_TYPE, DEFAULT_FIELD_ELEMENT
 
Constructor Summary
FudgeXMLStreamWriter(FudgeContext fudgeContext, Writer writer)
          Creates a new FudgeXMLStreamWriter for writing to the target XML device.
FudgeXMLStreamWriter(FudgeContext fudgeContext, XMLStreamWriter writer)
          Creates a new FudgeXMLStreamWriter for writing a Fudge stream to an XMLStreamWriter.
FudgeXMLStreamWriter(FudgeXMLSettings settings, FudgeContext fudgeContext, Writer writer)
           
FudgeXMLStreamWriter(FudgeXMLSettings settings, FudgeContext fudgeContext, XMLStreamWriter writer)
           
 
Method Summary
 void close()
          Flushes and closes this writer and attempts to close the underlying stream if appropriate.
protected  String convertFieldName(String str)
          Remove any invalid characters to leave an XML element name.
 void envelopeComplete()
          Signal the end of the message contained within an envelope.
 void flush()
          Flushes any data from the internal buffers to the target stream and attempts to flush the underlying stream if appropriate.
protected  void fudgeEnvelopeEnd()
           
protected  void fudgeEnvelopeStart(int processingDirectives, int schemaVersion)
           
protected  void fudgeFieldEnd()
           
protected  boolean fudgeFieldStart(Short ordinal, String name, FudgeFieldType type)
           
protected  void fudgeFieldValue(FudgeFieldType type, Object fieldValue)
           
 FudgeTaxonomy getCurrentTaxonomy()
          Returns the taxonomy (if any) that is currently being used to encode fields.
 int getCurrentTaxonomyId()
          Returns the current taxonomy identifier.
protected  FudgeStreamWriter getDelegate()
           
 FudgeContext getFudgeContext()
          Returns the bound FudgeContext used for type and taxonomy resolution.
protected  XMLStreamWriter getWriter()
          Returns the underlying XMLStreamWriter.
 void setCurrentTaxonomyId(int taxonomyId)
          Sets the current taxonomy, by identifier, to be used to encode fields.
protected static FudgeRuntimeException wrapException(String operation, XMLStreamException e)
           
protected  void writeArray(byte[] array)
           
protected  void writeArray(double[] array)
           
protected  void writeArray(float[] array)
           
protected  void writeArray(int[] array)
           
protected  void writeArray(long[] array)
           
protected  void writeArray(short[] array)
           
 void writeEnvelopeHeader(int processingDirectives, int schemaVersion, int messageSize)
          Writes a message envelope header.
 void writeField(FudgeField field)
          Writes a message field.
 void writeField(Short ordinal, String name, FudgeFieldType<?> type, Object fieldValue)
          Writes a message field.
 void writeFields(FudgeFieldContainer msg)
          Writes a set of fields.
 
Methods inherited from class org.fudgemsg.xml.FudgeXMLSettings
addBase64EncodingAlias, addBooleanAlias, addBooleanFalseAlias, addBooleanTrueAlias, addEnvelopeAttributeAlias, addEnvelopeAttributeProcessingDirectivesAlias, addEnvelopeAttributeSchemaVersionAlias, addEnvelopeAttributeTaxonomyAlias, addEnvelopeElementAlias, addFieldAttributeAlias, addFieldAttributeEncodingAlias, addFieldAttributeNameAlias, addFieldAttributeOrdinalAlias, addFieldAttributeTypeAlias, addFieldElementAlias, clearBooleanAliases, clearBooleanFalseAliases, clearBooleanTrueAliases, clearEnvelopeAttributeAliases, clearEnvelopeAttributeProcessingDirectivesAliases, clearEnvelopeAttributeSchemaVersionAliases, clearEnvelopeAttributeTaxonomyAliases, clearEnvelopeElementAliases, clearFieldAttributeAliases, clearFieldAttributeEncodingAliases, clearFieldAttributeNameAliases, clearFieldAttributeOrdinalAliases, clearFieldAttributeTypeAliases, clearFieldElementAliases, fudgeTypeIdToString, getAppendFieldOrdinal, getBase64EncodingAliases, getBase64EncodingName, getBase64UnknownTypes, getBooleanFalse, getBooleanTrue, getEnvelopeAttribute, getEnvelopeAttributeProcessingDirectives, getEnvelopeAttributeSchemaVersion, getEnvelopeAttributesToName, getEnvelopeAttributeTaxonomy, getEnvelopeElementAliases, getEnvelopeElementName, getFieldAttribute, getFieldAttributeEncoding, getFieldAttributeName, getFieldAttributeOrdinal, getFieldAttributesToName, getFieldAttributeType, getFieldElementAliases, getFieldElementName, getFudgeTypesToIdentifier, getIdentifiersToFudgeType, getNamesToEnvelopeAttribute, getNamesToFieldAttribute, getPreserveFieldNames, getStringsToBoolean, registerFudgeType, setAppendFieldOrdinal, setBase64EncodingName, setBase64UnknownTypes, setBooleanFalse, setBooleanTrue, setEnvelopeAttribute, setEnvelopeAttributeProcessingDirectives, setEnvelopeAttributeSchemaVersion, setEnvelopeAttributeTaxonomy, setEnvelopeElementName, setFieldAttribute, setFieldAttributeEncoding, setFieldAttributeName, setFieldAttributeOrdinal, setFieldAttributeType, setFieldElementName, setPreserveFieldNames, stringToFudgeTypeId
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

FudgeXMLStreamWriter

public FudgeXMLStreamWriter(FudgeContext fudgeContext,
                            Writer writer)
Creates a new FudgeXMLStreamWriter for writing to the target XML device.

Parameters:
fudgeContext - the FudgeContext
writer - the underlying Writer

FudgeXMLStreamWriter

public FudgeXMLStreamWriter(FudgeXMLSettings settings,
                            FudgeContext fudgeContext,
                            Writer writer)

FudgeXMLStreamWriter

public FudgeXMLStreamWriter(FudgeContext fudgeContext,
                            XMLStreamWriter writer)
Creates a new FudgeXMLStreamWriter for writing a Fudge stream to an XMLStreamWriter.

Parameters:
fudgeContext - the FudgeContext
writer - the underlying Writer

FudgeXMLStreamWriter

public FudgeXMLStreamWriter(FudgeXMLSettings settings,
                            FudgeContext fudgeContext,
                            XMLStreamWriter writer)
Method Detail

getWriter

protected XMLStreamWriter getWriter()
Returns the underlying XMLStreamWriter.

Returns:
the XMLStreamWriter

wrapException

protected static FudgeRuntimeException wrapException(String operation,
                                                     XMLStreamException e)
Parameters:
operation - the operation being attempted when the exception was caught
e - the exception caught

getDelegate

protected FudgeStreamWriter getDelegate()

close

public void close()
Flushes and closes this writer and attempts to close the underlying stream if appropriate.

Specified by:
close in interface Closeable
Specified by:
close in interface FudgeStreamWriter

flush

public void flush()
Flushes any data from the internal buffers to the target stream and attempts to flush the underlying stream if appropriate.

Specified by:
flush in interface Flushable
Specified by:
flush in interface FudgeStreamWriter

getFudgeContext

public FudgeContext getFudgeContext()
Returns the bound FudgeContext used for type and taxonomy resolution.

Specified by:
getFudgeContext in interface FudgeStreamWriter
Returns:
the FudgeContext

getCurrentTaxonomy

public FudgeTaxonomy getCurrentTaxonomy()
Returns the taxonomy (if any) that is currently being used to encode fields. Returns null if no taxonomy is specified or the taxonomy identifier cannot be resolved by the bound FudgeContext.

Specified by:
getCurrentTaxonomy in interface FudgeStreamWriter
Returns:
the FudgeTaxonomy

setCurrentTaxonomyId

public void setCurrentTaxonomyId(int taxonomyId)
Sets the current taxonomy, by identifier, to be used to encode fields.

Specified by:
setCurrentTaxonomyId in interface FudgeStreamWriter
Parameters:
taxonomyId - the taxonomy identifier

getCurrentTaxonomyId

public int getCurrentTaxonomyId()
Returns the current taxonomy identifier.

Specified by:
getCurrentTaxonomyId in interface FudgeStreamWriter
Returns:
current taxonomy identifier

writeEnvelopeHeader

public void writeEnvelopeHeader(int processingDirectives,
                                int schemaVersion,
                                int messageSize)
Writes a message envelope header.

Specified by:
writeEnvelopeHeader in interface FudgeStreamWriter
Parameters:
processingDirectives - the processing directive flags
schemaVersion - the schema version value
messageSize - the Fudge encoded size of the underlying message, including the message envelope

envelopeComplete

public void envelopeComplete()
Signal the end of the message contained within an envelope. An implementation may not need to take any action at this point as the end of the envelope can be detected based on the message size in the header.

Specified by:
envelopeComplete in interface FudgeStreamWriter

writeFields

public void writeFields(FudgeFieldContainer msg)
Writes a set of fields.

Specified by:
writeFields in interface FudgeStreamWriter
Parameters:
msg - the fields to write.

writeField

public void writeField(FudgeField field)
Writes a message field.

Specified by:
writeField in interface FudgeStreamWriter
Parameters:
field - the message field to write

writeField

public void writeField(Short ordinal,
                       String name,
                       FudgeFieldType<?> type,
                       Object fieldValue)
Description copied from interface: FudgeStreamWriter
Writes a message field.

Specified by:
writeField in interface FudgeStreamWriter
Parameters:
ordinal - the ordinal index of the field, or null to omit.
name - the name of the field, null to omit. If the ordinal is omitted and the name matches an entry in the current taxonomy the name will be replaced by the taxonomy resolved ordinal.
type - the type of the underlying data
fieldValue - value of the field

fudgeEnvelopeStart

protected void fudgeEnvelopeStart(int processingDirectives,
                                  int schemaVersion)
                           throws XMLStreamException
Throws:
XMLStreamException

convertFieldName

protected String convertFieldName(String str)
Remove any invalid characters to leave an XML element name.


writeArray

protected void writeArray(byte[] array)
                   throws XMLStreamException
Throws:
XMLStreamException

writeArray

protected void writeArray(short[] array)
                   throws XMLStreamException
Throws:
XMLStreamException

writeArray

protected void writeArray(int[] array)
                   throws XMLStreamException
Throws:
XMLStreamException

writeArray

protected void writeArray(long[] array)
                   throws XMLStreamException
Throws:
XMLStreamException

writeArray

protected void writeArray(float[] array)
                   throws XMLStreamException
Throws:
XMLStreamException

writeArray

protected void writeArray(double[] array)
                   throws XMLStreamException
Throws:
XMLStreamException

fudgeFieldStart

protected boolean fudgeFieldStart(Short ordinal,
                                  String name,
                                  FudgeFieldType type)
                           throws XMLStreamException
Throws:
XMLStreamException

fudgeFieldValue

protected void fudgeFieldValue(FudgeFieldType type,
                               Object fieldValue)
                        throws XMLStreamException
Throws:
XMLStreamException

fudgeFieldEnd

protected void fudgeFieldEnd()
                      throws XMLStreamException
Throws:
XMLStreamException

fudgeEnvelopeEnd

protected void fudgeEnvelopeEnd()
                         throws XMLStreamException
Throws:
XMLStreamException


Copyright 2009-Present by OpenGamma Inc. and individual contributors
Released under the Apache License, Version 2.0