org.fudgemsg.types
Class SecondaryFieldType<SecondaryType,PrimitiveType>

java.lang.Object
  extended by org.fudgemsg.FudgeFieldType<SecondaryType>
      extended by org.fudgemsg.types.SecondaryFieldTypeBase<SecondaryType,PrimitiveType,PrimitiveType>
          extended by org.fudgemsg.types.SecondaryFieldType<SecondaryType,PrimitiveType>
Type Parameters:
SecondaryType - secondary type
PrimitiveType - type there is a primary FudgeFieldType for
All Implemented Interfaces:
Serializable, FudgeTypeConverter<PrimitiveType,SecondaryType>
Direct Known Subclasses:
JavaMathBigDecimalFieldType, JavaUtilTimeZoneFieldType, JavaUtilUUIDFieldType, JSR310DateProviderFieldType, JSR310DateTimeProviderFieldType, JSR310InstantFieldType, JSR310InstantProviderFieldType, JSR310OffsetDateFieldType, JSR310OffsetDateTimeFieldType, JSR310TimeProviderFieldType, JSR310TimeZoneFieldType

public abstract class SecondaryFieldType<SecondaryType,PrimitiveType>
extends SecondaryFieldTypeBase<SecondaryType,PrimitiveType,PrimitiveType>

The type definition for a secondary field type that converts Java objects to a more fundamental Fudge type. This approach is more lightweight than the tools available in the mapping package, but also limited as there is no access to the FudgeContext when the conversion takes place.

See Also:
Serialized Form

Constructor Summary
protected SecondaryFieldType(FudgeFieldType<PrimitiveType> type, Class<SecondaryType> javaType)
          Creates a new secondary type on top of an existing Fudge type.
 
Method Summary
 boolean canConvertPrimary(Class<? extends PrimitiveType> clazz)
          Returns true if this converter can manipulate the requested class.
 SecondaryType primaryToSecondary(PrimitiveType object)
          Converts Fudge primitive data to the secondary type.
 SecondaryType readValue(DataInput input, int dataSize)
          Reads a value of this type to the output.
 void writeValue(DataOutput output, SecondaryType value)
          Writes a value of this type to the output.
 
Methods inherited from class org.fudgemsg.types.SecondaryFieldTypeBase
getPrimaryType, getVariableSize, secondaryToPrimary
 
Methods inherited from class org.fudgemsg.FudgeFieldType
equals, getFixedSize, getJavaType, getTypeId, hashCode, isVariableSize, toString
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

SecondaryFieldType

protected SecondaryFieldType(FudgeFieldType<PrimitiveType> type,
                             Class<SecondaryType> javaType)
Creates a new secondary type on top of an existing Fudge type.

Parameters:
type - existing Fudge primitive type
javaType - Java type for conversion
Method Detail

primaryToSecondary

public SecondaryType primaryToSecondary(PrimitiveType object)
Converts Fudge primitive data to the secondary type. This is an optional operation - it will only be invoked if the user attempts to convert from the underlying type used for transport back to the secondary type. An implementation may assume that the object parameter is not null.

Parameters:
object - the Fudge data
Returns:
a secondary type instance

canConvertPrimary

public boolean canConvertPrimary(Class<? extends PrimitiveType> clazz)
Returns true if this converter can manipulate the requested class.

Parameters:
clazz - to query
Returns:
true if a call to FudgeTypeConverter.primaryToSecondary(Primary) will succeed, false if it would fail

writeValue

public void writeValue(DataOutput output,
                       SecondaryType value)
                throws IOException
Writes a value of this type to the output.

This is intended for use by variable width types and must write the given value. The implementation must write exactly the number of bytes returned by the size calculation.

Overrides:
writeValue in class SecondaryFieldTypeBase<SecondaryType,PrimitiveType,PrimitiveType>
Parameters:
output - the output target to write the value to, not null
value - the value to write
Throws:
IOException - if an error occurs, which must be wrapped by the caller

readValue

public SecondaryType readValue(DataInput input,
                               int dataSize)
                        throws IOException
Reads a value of this type to the output.

This is intended for use by variable width types and must read the given value. The implementation must read exactly the number of bytes passed into the method.

Overrides:
readValue in class SecondaryFieldTypeBase<SecondaryType,PrimitiveType,PrimitiveType>
Parameters:
input - the input source to read the value from, not null
dataSize - the number of bytes of data to read
Returns:
the value that was read
Throws:
IOException - if an error occurs, which must be wrapped by the caller


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