org.fudgemsg.mapping
Class FudgeSerializationContext

java.lang.Object
  extended by org.fudgemsg.mapping.FudgeSerializationContext
All Implemented Interfaces:
FudgeMessageFactory

public class FudgeSerializationContext
extends Object
implements FudgeMessageFactory

The central point for Fudge message to Java Object serialisation on a given stream. Note that the deserialiser cannot process cyclic object graphs at the moment because of the way the builder interfaces are structured (i.e. we don't have access to an outer object until it's builder returned) so this will not send any.


Constructor Summary
FudgeSerializationContext(FudgeContext fudgeContext)
          Creates a new FudgeSerializationContext for the given FudgeContext.
 
Method Summary
static MutableFudgeFieldContainer addClassHeader(MutableFudgeFieldContainer message, Class<?> clazz)
          Adds class names to a message with ordinal 0 for use by a deserializer.
static MutableFudgeFieldContainer addClassHeader(MutableFudgeFieldContainer message, Class<?> clazz, Class<?> receiverTarget)
          Adds partial class names to a message with ordinal 0 for use by a deserializer.
 FudgeContext getFudgeContext()
          Returns the associated FudgeContext.
 MutableFudgeFieldContainer newMessage()
          Creates an initially empty message.
 MutableFudgeFieldContainer newMessage(FudgeFieldContainer fromMessage)
          Creates a new message initially populated with the supplied message.
 void objectToFudgeMsg(MutableFudgeFieldContainer message, String name, Integer ordinal, Object object)
          Add a Java object to a Fudge message (MutableFudgeFieldContainer instance) either natively if the associated FudgeTypeDictionary recognises it, or as a sub-message using the serialization framework.
 MutableFudgeFieldContainer objectToFudgeMsg(Object object)
          Converts a Java object to a Fudge message MutableFudgeFieldContainer instance using a FudgeMessageBuilder registered against the object's class in the current FudgeObjectDictionary.
 void objectToFudgeMsgWithClassHeaders(MutableFudgeFieldContainer message, String name, Integer ordinal, Object object)
          Add a Java object to a Fudge message (MutableFudgeFieldContainer instance) either natively if the associated FudgeTypeDictionary recognises it, or as a sub-message using the serialization framework.
 void objectToFudgeMsgWithClassHeaders(MutableFudgeFieldContainer message, String name, Integer ordinal, Object object, Class<?> receiverTarget)
          Add a Java object to a Fudge message (MutableFudgeFieldContainer instance) either natively if the associated FudgeTypeDictionary recognises it, or as a sub-message using the serialization framework.
 void reset()
          Resets the buffers used for object graph logics.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

FudgeSerializationContext

public FudgeSerializationContext(FudgeContext fudgeContext)
Creates a new FudgeSerializationContext for the given FudgeContext.

Parameters:
fudgeContext - the FudgeContext to use
Method Detail

reset

public void reset()
Resets the buffers used for object graph logics. Calling reset() on this context should match a call to FudgeDeserializationContext.reset() on the context used by the deserialiser to keep the states of both sender and receiver consistent.


newMessage

public MutableFudgeFieldContainer newMessage()
Creates an initially empty message.

Specified by:
newMessage in interface FudgeMessageFactory
Returns:
the empty message container, not null

newMessage

public MutableFudgeFieldContainer newMessage(FudgeFieldContainer fromMessage)
Creates a new message initially populated with the supplied message.

Specified by:
newMessage in interface FudgeMessageFactory
Parameters:
fromMessage - the source message to copy fields from, not null
Returns:
the new message container, not null

getFudgeContext

public FudgeContext getFudgeContext()
Returns the associated FudgeContext.

Returns:
the FudgeContext

objectToFudgeMsg

public void objectToFudgeMsg(MutableFudgeFieldContainer message,
                             String name,
                             Integer ordinal,
                             Object object)
Add a Java object to a Fudge message (MutableFudgeFieldContainer instance) either natively if the associated FudgeTypeDictionary recognises it, or as a sub-message using the serialization framework.

Parameters:
message - the message to add this object to
name - field name to add with, or null for none
ordinal - ordinal index to add with, or null for none
object - value to add

objectToFudgeMsgWithClassHeaders

public void objectToFudgeMsgWithClassHeaders(MutableFudgeFieldContainer message,
                                             String name,
                                             Integer ordinal,
                                             Object object)
Add a Java object to a Fudge message (MutableFudgeFieldContainer instance) either natively if the associated FudgeTypeDictionary recognises it, or as a sub-message using the serialization framework. If encoded as a sub-message, class header fields are added. This can make deserialization easier but increases the message length.

Parameters:
message - the message to add this object to
name - field name to add with, or null for none
ordinal - ordinal index to add with, or null for none
object - value to add

objectToFudgeMsgWithClassHeaders

public void objectToFudgeMsgWithClassHeaders(MutableFudgeFieldContainer message,
                                             String name,
                                             Integer ordinal,
                                             Object object,
                                             Class<?> receiverTarget)
Add a Java object to a Fudge message (MutableFudgeFieldContainer instance) either natively if the associated FudgeTypeDictionary recognises it, or as a sub-message using the serialization framework. If encoded as a sub-message, class header fields are added. This can make deserialization easier but increases the message length. It is assumed that the deserializer will already know the target class by other means, so the message payload may end up being smaller than with objectToFudgeMsgWithClassHeaders(MutableFudgeFieldContainer,String,Integer,Object).

Parameters:
message - the message to add this object to
name - field name to add with, or null for none
ordinal - ordinal index to add with, or null for none
object - value to add
receiverTarget - the Java class the receiver will expect

objectToFudgeMsg

public MutableFudgeFieldContainer objectToFudgeMsg(Object object)
Converts a Java object to a Fudge message MutableFudgeFieldContainer instance using a FudgeMessageBuilder registered against the object's class in the current FudgeObjectDictionary. Note that a mutable container is returned (from the definition of FudgeMessageBuilder so that the caller is able to append additional data to the message if required, e.g. addClassHeader(MutableFudgeFieldContainer,Class).

Parameters:
object - the Java object to serialize
Returns:
the Fudge message created

addClassHeader

public static MutableFudgeFieldContainer addClassHeader(MutableFudgeFieldContainer message,
                                                        Class<?> clazz)
Adds class names to a message with ordinal 0 for use by a deserializer. The preferred class name is written first, followed by subsequent super-classes that may be acceptable if the deserializer doesn't recognize them.

Parameters:
message - the message to add the fields to
clazz - the Java class to add type data for
Returns:
message the modified message (allows this to be used inline)

addClassHeader

public static MutableFudgeFieldContainer addClassHeader(MutableFudgeFieldContainer message,
                                                        Class<?> clazz,
                                                        Class<?> receiverTarget)
Adds partial class names to a message with ordinal 0 for use by a deserializer. The preferred class name is written first, followed by subsequent super-classes that may be acceptable. It is assumed that the deserializer will already know the target class by other means, so the message payload ends up being smaller than with addClassHeader(MutableFudgeFieldContainer,Class).

Parameters:
message - the message to add the fields to
clazz - the Java class to add type data for
receiverTarget - the Java class the receiver will expect
Returns:
message the modified message (allows this to be used inline)


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