org.fudgemsg
Class AlternativeFudgeStreamWriter

java.lang.Object
  extended by org.fudgemsg.AlternativeFudgeStreamWriter
All Implemented Interfaces:
Closeable, Flushable, FudgeStreamWriter
Direct Known Subclasses:
FudgeJSONStreamWriter

public abstract class AlternativeFudgeStreamWriter
extends Object
implements FudgeStreamWriter

Abstract implementation of a FudgeStreamWriter that detects major state changes and invokes other methods. Can be used to build alternative stream writers for converting streamed Fudge messages to XML, JSON or other formats.


Constructor Summary
protected AlternativeFudgeStreamWriter(FudgeContext fudgeContext)
          Creates a new AlternativeFudgeStreamWriter instance.
 
Method Summary
 void close()
          No action taken.
 void envelopeComplete()
          Signal the end of the message contained within an envelope.
 void flush()
          No action taken.
protected  void fudgeEnvelopeEnd()
          Called at the end of the envelope after all fields have been processed.
protected  void fudgeEnvelopeStart(int processingDirectives, int schemaVersion)
          Called when a Fudge message envelope is starting.
protected  void fudgeFieldEnd()
          Called after a field has been processed.
protected  boolean fudgeFieldStart(Short ordinal, String name, FudgeFieldType<?> type)
          Called as a field starts.
protected  void fudgeFieldValue(FudgeFieldType<?> type, Object fieldValue)
          Called between fudgeFieldStart(java.lang.Short, java.lang.String, org.fudgemsg.FudgeFieldType) and fudgeFieldEnd() for fields that are not sub messages.
protected  void fudgeSubMessageEnd()
          Called when a sub-message has been processed, before fudgeFieldEnd() is called for the field.
protected  void fudgeSubMessageStart()
          Called after fudgeFieldStart(java.lang.Short, java.lang.String, org.fudgemsg.FudgeFieldType) when a sub-message is starting.
 FudgeTaxonomy getCurrentTaxonomy()
          Returns the taxonomy (if any) that is currently being used to encode fields.
 int getCurrentTaxonomyId()
          Returns the current taxonomy identifier.
 FudgeContext getFudgeContext()
          Returns the bound FudgeContext used for type and taxonomy resolution.
 void setCurrentTaxonomyId(int taxonomyId)
          Sets the current taxonomy, by identifier, to be used to encode fields.
 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 java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AlternativeFudgeStreamWriter

protected AlternativeFudgeStreamWriter(FudgeContext fudgeContext)
Creates a new AlternativeFudgeStreamWriter instance.

Parameters:
fudgeContext - the associated FudgeContext
Method Detail

close

public void close()
No action taken.

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

flush

public void flush()
No action taken.

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)
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)
Called when a Fudge message envelope is starting.

Parameters:
processingDirectives - the envelope processing directives
schemaVersion - the envelope schema version

fudgeEnvelopeEnd

protected void fudgeEnvelopeEnd()
Called at the end of the envelope after all fields have been processed.


fudgeFieldStart

protected boolean fudgeFieldStart(Short ordinal,
                                  String name,
                                  FudgeFieldType<?> type)
Called as a field starts.

Parameters:
ordinal - the field ordinal
name - the field name
type - the field type
Returns:
true to continue processing the field, false to ignore it (fudgeFieldValue(org.fudgemsg.FudgeFieldType, java.lang.Object), fudgeSubMessageStart(), fudgeSubMessageEnd() and fudgeFieldEnd() will not be called for this field)

fudgeFieldEnd

protected void fudgeFieldEnd()
Called after a field has been processed.


fudgeFieldValue

protected void fudgeFieldValue(FudgeFieldType<?> type,
                               Object fieldValue)
Called between fudgeFieldStart(java.lang.Short, java.lang.String, org.fudgemsg.FudgeFieldType) and fudgeFieldEnd() for fields that are not sub messages.

Parameters:
type - the field type
fieldValue - the value

fudgeSubMessageStart

protected void fudgeSubMessageStart()
Called after fudgeFieldStart(java.lang.Short, java.lang.String, org.fudgemsg.FudgeFieldType) when a sub-message is starting.


fudgeSubMessageEnd

protected void fudgeSubMessageEnd()
Called when a sub-message has been processed, before fudgeFieldEnd() is called for the field.



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