org.fudgemsg
Class FudgeTypeDictionary

java.lang.Object
  extended by org.fudgemsg.FudgeTypeDictionary

public class FudgeTypeDictionary
extends Object

The dictionary of all known Fudge types.

In order to efficiently send messages, Fudge needs to know the type of each piece of data. This dictionary keeps track of all the known types.

This class is mutable and thread-safe via concurrent collections.


Field Summary
static byte BOOLEAN_TYPE_ID
          Standard Fudge field type: boolean.
static byte BYTE_ARR_128_TYPE_ID
          Standard Fudge field type: byte array of length 128.
static byte BYTE_ARR_16_TYPE_ID
          Standard Fudge field type: byte array of length 16.
static byte BYTE_ARR_20_TYPE_ID
          Standard Fudge field type: byte array of length 20.
static byte BYTE_ARR_256_TYPE_ID
          Standard Fudge field type: byte array of length 256.
static byte BYTE_ARR_32_TYPE_ID
          Standard Fudge field type: byte array of length 32.
static byte BYTE_ARR_4_TYPE_ID
          Standard Fudge field type: byte array of length 4.
static byte BYTE_ARR_512_TYPE_ID
          Standard Fudge field type: byte array of length 512.
static byte BYTE_ARR_64_TYPE_ID
          Standard Fudge field type: byte array of length 64.
static byte BYTE_ARR_8_TYPE_ID
          Standard Fudge field type: byte array of length 8.
static byte BYTE_ARRAY_TYPE_ID
          Standard Fudge field type: byte array.
static byte BYTE_TYPE_ID
          Standard Fudge field type: 8-bit signed integer.
static byte DATE_TYPE_ID
          Standard Fudge field type: date.
static byte DATETIME_TYPE_ID
          Standard Fudge field type: combined date and time.
static byte DOUBLE_ARRAY_TYPE_ID
          Standard Fudge field type: array of 64-bit floating point.
static byte DOUBLE_TYPE_ID
          Standard Fudge field type: 64-bit floating point.
static byte FLOAT_ARRAY_TYPE_ID
          Standard Fudge field type: array of 32-bit floating point.
static byte FLOAT_TYPE_ID
          Standard Fudge field type: 32-bit floating point.
static byte FUDGE_MSG_TYPE_ID
          Standard Fudge field type: embedded Fudge sub-message.
static byte INDICATOR_TYPE_ID
          Standard Fudge field type: unsized indicator value.
static byte INT_ARRAY_TYPE_ID
          Standard Fudge field type: array of 32-bit signed integers.
static byte INT_TYPE_ID
          Standard Fudge field type: 32-bit signed integer.
static byte LONG_ARRAY_TYPE_ID
          Standard Fudge field type: array of 64-bit signed integers.
static byte LONG_TYPE_ID
          Standard Fudge field type: 64-bit signed integer.
static byte SHORT_ARRAY_TYPE_ID
          Standard Fudge field type: array of 16-bit signed integers.
static byte SHORT_TYPE_ID
          Standard Fudge field type: 16-bit signed integer.
static byte STRING_TYPE_ID
          Standard Fudge field type: string.
static byte TIME_TYPE_ID
          Standard Fudge field type: time.
 
Constructor Summary
  FudgeTypeDictionary()
          Creates a new dictionary configured with the default types from the Fudge specification.
protected FudgeTypeDictionary(FudgeTypeDictionary other)
          Creates a new dictionary as a clone of another.
 
Method Summary
 void addAllAnnotatedSecondaryTypes()
          Scans all files available to common classpath loading system heuristics to determine which ones have the FudgeSecondaryType annotation, and registers those as appropriate secondary types.
 void addAnnotatedSecondaryTypeClass(String className)
          Add a class which is known to have a FudgeBuilderFor annotation as an object or message builder (or both).
 void addType(FudgeFieldType<?> type, Class<?>... alternativeTypes)
          Register a new type with the dictionary.
 void addTypeConverter(FudgeTypeConverter<?,?> converter, Class<?>... types)
          Registers a new type conversion with the dictionary.
<T> boolean
canConvertField(Class<T> clazz, FudgeField field)
          Type conversion test for secondary types.
 FudgeFieldType<?> getByJavaType(Class<?> javaType)
          Resolves a Java class to a FudgeFieldType registered with this dictionary.
 FudgeFieldType<?> getByTypeId(int typeId)
          Obtain a known type by the type ID specified.
<T> T
getFieldValue(Class<T> clazz, FudgeField field)
          Type conversion for secondary types.
protected
<T> FudgeTypeConverter<Object,T>
getTypeConverter(Class<T> javaType)
          Resolves a Java class to a FudgeTypeConverter.
 UnknownFudgeFieldType getUnknownType(int typeId)
          Obtain an unknown type wrapper for the type ID specified.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

INDICATOR_TYPE_ID

public static final byte INDICATOR_TYPE_ID
Standard Fudge field type: unsized indicator value. See Fudge Types for more details.

See Also:
Constant Field Values

BOOLEAN_TYPE_ID

public static final byte BOOLEAN_TYPE_ID
Standard Fudge field type: boolean. See Fudge Types for more details.

See Also:
Constant Field Values

BYTE_TYPE_ID

public static final byte BYTE_TYPE_ID
Standard Fudge field type: 8-bit signed integer. See Fudge Types for more details.

See Also:
Constant Field Values

SHORT_TYPE_ID

public static final byte SHORT_TYPE_ID
Standard Fudge field type: 16-bit signed integer. See Fudge Types for more details.

See Also:
Constant Field Values

INT_TYPE_ID

public static final byte INT_TYPE_ID
Standard Fudge field type: 32-bit signed integer. See Fudge Types for more details.

See Also:
Constant Field Values

LONG_TYPE_ID

public static final byte LONG_TYPE_ID
Standard Fudge field type: 64-bit signed integer. See Fudge Types for more details.

See Also:
Constant Field Values

BYTE_ARRAY_TYPE_ID

public static final byte BYTE_ARRAY_TYPE_ID
Standard Fudge field type: byte array. See Fudge Types for more details.

See Also:
Constant Field Values

SHORT_ARRAY_TYPE_ID

public static final byte SHORT_ARRAY_TYPE_ID
Standard Fudge field type: array of 16-bit signed integers. See Fudge Types for more details.

See Also:
Constant Field Values

INT_ARRAY_TYPE_ID

public static final byte INT_ARRAY_TYPE_ID
Standard Fudge field type: array of 32-bit signed integers. See Fudge Types for more details.

See Also:
Constant Field Values

LONG_ARRAY_TYPE_ID

public static final byte LONG_ARRAY_TYPE_ID
Standard Fudge field type: array of 64-bit signed integers. See Fudge Types for more details.

See Also:
Constant Field Values

FLOAT_TYPE_ID

public static final byte FLOAT_TYPE_ID
Standard Fudge field type: 32-bit floating point. See Fudge Types for more details.

See Also:
Constant Field Values

DOUBLE_TYPE_ID

public static final byte DOUBLE_TYPE_ID
Standard Fudge field type: 64-bit floating point. See Fudge Types for more details.

See Also:
Constant Field Values

FLOAT_ARRAY_TYPE_ID

public static final byte FLOAT_ARRAY_TYPE_ID
Standard Fudge field type: array of 32-bit floating point. See Fudge Types for more details.

See Also:
Constant Field Values

DOUBLE_ARRAY_TYPE_ID

public static final byte DOUBLE_ARRAY_TYPE_ID
Standard Fudge field type: array of 64-bit floating point. See Fudge Types for more details.

See Also:
Constant Field Values

STRING_TYPE_ID

public static final byte STRING_TYPE_ID
Standard Fudge field type: string. See Fudge Types for more details.

See Also:
Constant Field Values

FUDGE_MSG_TYPE_ID

public static final byte FUDGE_MSG_TYPE_ID
Standard Fudge field type: embedded Fudge sub-message. See Fudge Types for more details.

See Also:
Constant Field Values

BYTE_ARR_4_TYPE_ID

public static final byte BYTE_ARR_4_TYPE_ID
Standard Fudge field type: byte array of length 4. See Fudge Types for more details.

See Also:
Constant Field Values

BYTE_ARR_8_TYPE_ID

public static final byte BYTE_ARR_8_TYPE_ID
Standard Fudge field type: byte array of length 8. See Fudge Types for more details.

See Also:
Constant Field Values

BYTE_ARR_16_TYPE_ID

public static final byte BYTE_ARR_16_TYPE_ID
Standard Fudge field type: byte array of length 16. See Fudge Types for more details.

See Also:
Constant Field Values

BYTE_ARR_20_TYPE_ID

public static final byte BYTE_ARR_20_TYPE_ID
Standard Fudge field type: byte array of length 20. See Fudge Types for more details.

See Also:
Constant Field Values

BYTE_ARR_32_TYPE_ID

public static final byte BYTE_ARR_32_TYPE_ID
Standard Fudge field type: byte array of length 32. See Fudge Types for more details.

See Also:
Constant Field Values

BYTE_ARR_64_TYPE_ID

public static final byte BYTE_ARR_64_TYPE_ID
Standard Fudge field type: byte array of length 64. See Fudge Types for more details.

See Also:
Constant Field Values

BYTE_ARR_128_TYPE_ID

public static final byte BYTE_ARR_128_TYPE_ID
Standard Fudge field type: byte array of length 128. See Fudge Types for more details.

See Also:
Constant Field Values

BYTE_ARR_256_TYPE_ID

public static final byte BYTE_ARR_256_TYPE_ID
Standard Fudge field type: byte array of length 256. See Fudge Types for more details.

See Also:
Constant Field Values

BYTE_ARR_512_TYPE_ID

public static final byte BYTE_ARR_512_TYPE_ID
Standard Fudge field type: byte array of length 512. See Fudge Types for more details.

See Also:
Constant Field Values

DATE_TYPE_ID

public static final byte DATE_TYPE_ID
Standard Fudge field type: date. See Fudge Types for more details.

See Also:
Constant Field Values

TIME_TYPE_ID

public static final byte TIME_TYPE_ID
Standard Fudge field type: time. See Fudge Types for more details.

See Also:
Constant Field Values

DATETIME_TYPE_ID

public static final byte DATETIME_TYPE_ID
Standard Fudge field type: combined date and time. See Fudge Types for more details.

See Also:
Constant Field Values
Constructor Detail

FudgeTypeDictionary

public FudgeTypeDictionary()
Creates a new dictionary configured with the default types from the Fudge specification. Some standard secondary types will also be loaded.


FudgeTypeDictionary

protected FudgeTypeDictionary(FudgeTypeDictionary other)
Creates a new dictionary as a clone of another.

Parameters:
other - the dictionary to copy data from
Method Detail

addTypeConverter

public void addTypeConverter(FudgeTypeConverter<?,?> converter,
                             Class<?>... types)
Registers a new type conversion with the dictionary.

A converter will be used by getFieldValue(java.lang.Class, org.fudgemsg.FudgeField) to expand a non-matching type. The secondary type mechanism will register the appropriate conversion automatically when addType(org.fudgemsg.FudgeFieldType, java.lang.Class...) is called.

Parameters:
converter - the converter to register
types - the types to register against

addType

public void addType(FudgeFieldType<?> type,
                    Class<?>... alternativeTypes)
Register a new type with the dictionary.

Custom types that are not part of the Fudge specification should use IDs allocated downwards from 255 for compatibility with future versions that might include additional standard types.

Parameters:
type - the FudgeFieldType definition of the type, not null
alternativeTypes - any additional Java classes that are synonymous with this type

getByJavaType

public FudgeFieldType<?> getByJavaType(Class<?> javaType)
Resolves a Java class to a FudgeFieldType registered with this dictionary.

Parameters:
javaType - the class to resolve
Returns:
the matching Fudge type, null if none is found

getTypeConverter

protected <T> FudgeTypeConverter<Object,T> getTypeConverter(Class<T> javaType)
Resolves a Java class to a FudgeTypeConverter.

A converter may be derived from registration of a SecondaryFieldType, a default conversion between the Java classes that represent the Fudge primitive types, or explicitly registered with addTypeConverter(org.fudgemsg.types.FudgeTypeConverter, java.lang.Class...).

Type Parameters:
T - Java type of the class to look up
Parameters:
javaType - the class to look up
Returns:
the registered converter, null if none is available

getByTypeId

public FudgeFieldType<?> getByTypeId(int typeId)
Obtain a known type by the type ID specified.

For processing unhandled variable-width field types, this method will return null, and getUnknownType(int) should be used if unhandled-type processing is desired.

Parameters:
typeId - the numeric type identifier
Returns:
the type with the specified type identifier, null if no type for the id

getUnknownType

public UnknownFudgeFieldType getUnknownType(int typeId)
Obtain an unknown type wrapper for the type ID specified.

Unknown types allow data to be preserved within a Fudge message even if the application is unable to process it.

Parameters:
typeId - the numeric type identifier
Returns:
A type representing this identifier

getFieldValue

public <T> T getFieldValue(Class<T> clazz,
                           FudgeField field)
                throws IllegalArgumentException
Type conversion for secondary types.

Type Parameters:
T - type to convert to
Parameters:
clazz - the target class for the converted value, not null
field - the field containing the value to convert, null returns null
Returns:
the converted value, null if no value
Throws:
IllegalArgumentException - if the parameters are not valid for conversion

canConvertField

public <T> boolean canConvertField(Class<T> clazz,
                                   FudgeField field)
Type conversion test for secondary types.

Returns true if getFieldValue(java.lang.Class, org.fudgemsg.FudgeField) would return an object instance.

Type Parameters:
T - type to convert to
Parameters:
clazz - the target class for the converted value, not null
field - the field containing the value to convert, null returns false
Returns:
true if a conversion is possible, false otherwise (when getFieldValue(java.lang.Class, org.fudgemsg.FudgeField) might return null or throw an exception)

addAllAnnotatedSecondaryTypes

public void addAllAnnotatedSecondaryTypes()
Scans all files available to common classpath loading system heuristics to determine which ones have the FudgeSecondaryType annotation, and registers those as appropriate secondary types. This is potentially a very expensive operation, and as such is optional.


addAnnotatedSecondaryTypeClass

public void addAnnotatedSecondaryTypeClass(String className)
Add a class which is known to have a FudgeBuilderFor annotation as an object or message builder (or both).

Parameters:
className - the fully qualified name of the builder class.


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