|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.fudgemsg.mapping.FudgeObjectDictionary
public class FudgeObjectDictionary
Extensible dictionary of types that Fudge can convert to and from wire format.
This class contains a cache of mappings from Java types to Fudge messages.
There is one instance of the dictionary per context
.
Mappings may be added in three main ways.
The simplest way is to create an instance of FudgeBuilder
and call the
addBuilder
method. This will register an instance of the builder for a specific type.
Subclasses of the type will not use the builder.
The second mechanism is classpath scanning. Simply annotate the builder class with
FudgeBuilderFor
, and call addAllClasspathBuilders
.
The method can be slow when operating on a large classpath.
The system property org.fudgemsg.autoscan
allows this to be done automatically.
The third method is generic builders. This class contains a single instance of
FudgeBuilderFactory
, which is capable of creating builders on demand.
See FudgeDefaultBuilderFactory
for the default list of handled types.
Further generic builders can be registered with the factory.
These generic builders will handle subclasses of the registered type.
All builder caching is done in this class. The factory is not responsible for caching.
Registering a different factory, or registering additional/different generic builders can change the default behavior for unrecognized types. As such, it is recommended to only initialize the dictionary at system startup. However, the cache is concurrent, so will handle later additions.
Field Summary | |
---|---|
static String |
AUTO_CLASSPATH_SCAN_PROPERTY
The name of the property to be set (to any value) to automatically scan the classpath for builders on startup. |
Constructor Summary | |
---|---|
FudgeObjectDictionary()
Constructs a new (initially empty) FudgeObjectDictionary . |
|
FudgeObjectDictionary(FudgeObjectDictionary other)
Constructs a new FudgeObjectDictionary as a clone of another. |
Method Summary | ||
---|---|---|
void |
addAllAnnotatedBuilders()
Scans all files available to common classpath loading system heuristics to determine which ones have the FudgeBuilderFor annotation, and registers those as appropriate
builders. |
|
void |
addAnnotatedBuilderClass(String className)
Add a class which is known to have a FudgeBuilderFor annotation as an object or message
builder (or both). |
|
void |
addAnnotatedGenericBuilderClass(String className)
Add a class which is known to have a GenericFudgeBuilderFor annotation as builder. |
|
|
addBuilder(Class<T> clazz,
FudgeBuilder<T> builder)
Registers a new FudgeBuilder with this dictionary to be used for a given class. |
|
|
addMessageBuilder(Class<T> clazz,
FudgeMessageBuilder<? super T> builder)
Registers a new FudgeMessageBuilder with this dictionary to be used for a given class. |
|
|
addObjectBuilder(Class<T> clazz,
FudgeObjectBuilder<? extends T> builder)
Registers a new FudgeObjectBuilder with this dictionary to be used for a given class. |
|
FudgeBuilderFactory |
getDefaultBuilderFactory()
Returns the current builder factory for unregistered types. |
|
Class<?> |
getDefaultObjectClass(int maxOrdinal)
Returns the class indicated by a default serialization scheme. |
|
|
getMessageBuilder(Class<T> clazz)
Returns a FudgeMessageBuilder for the given class to convert a Fudge message to a Java object. |
|
|
getObjectBuilder(Class<T> clazz)
Returns a FudgeObjectBuilder for the given class to convert a Fudge message to a Java object. |
|
boolean |
isDefaultObject(Class<?> clazz)
Tests if the specification requires a default serialization, for example lists, maps, sets and arrays. |
|
void |
setDefaultBuilderFactory(FudgeBuilderFactory defaultBuilderFactory)
Sets the builder factory to use for types that are not explicitly registered here. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final String AUTO_CLASSPATH_SCAN_PROPERTY
Constructor Detail |
---|
public FudgeObjectDictionary()
FudgeObjectDictionary
.
public FudgeObjectDictionary(FudgeObjectDictionary other)
FudgeObjectDictionary
as a clone of another.
other
- the FudgeObjectDictionary
to cloneMethod Detail |
---|
public FudgeBuilderFactory getDefaultBuilderFactory()
FudgeBuilderFactory
.public void setDefaultBuilderFactory(FudgeBuilderFactory defaultBuilderFactory)
FudgeBuilderFactory
implementations are made using the FudgeBuilderFactoryAdapter
, constructed with the previously set factory so that the behaviours
can be chained.
defaultBuilderFactory
- the FudgeBuilderFactory
to usepublic <T> void addObjectBuilder(Class<T> clazz, FudgeObjectBuilder<? extends T> builder)
FudgeObjectBuilder
with this dictionary to be used for a given class. The same builder can be registered against
multiple classes. A class can only have one registered FudgeObjectBuilder
- registering a second will overwrite the previous
registration.
T
- Java type of the objects created by the builderclazz
- the Java class to register the builder againstbuilder
- the builder to registerpublic <T> void addMessageBuilder(Class<T> clazz, FudgeMessageBuilder<? super T> builder)
FudgeMessageBuilder
with this dictionary to be used for a given class. The same builder can be registered against
multiple classes. A class can only have one registered FudgeMessageBuilder
- registering a second will overwrite the previous
registration.
T
- Java type of the objects processed by the builderclazz
- the Java class to register the builder againstbuilder
- builder to registerpublic <T> void addBuilder(Class<T> clazz, FudgeBuilder<T> builder)
FudgeBuilder
with this dictionary to be used for a given class. A FudgeBuilder
is simply a combined FudgeMessageBuilder
and FudgeObjectBuilder
so this method is the same as calling addMessageBuilder(Class,FudgeMessageBuilder)
and addObjectBuilder(Class,FudgeObjectBuilder)
.
T
- Java type of the objects processed by the builderclazz
- the Java class to register the builder againstbuilder
- builder to registerpublic <T> FudgeObjectBuilder<T> getObjectBuilder(Class<T> clazz)
FudgeObjectBuilder
for the given class to convert a Fudge message to a Java object. If none is already registered for the class,
it will attempt to create one using the registered FudgeBuilderFactory
. If it is not possible to create a builder (e.g. for an interface) returns null
.
T
- Java type of the objects to be builtclazz
- the Java class to look up
null
if none is availablepublic <T> FudgeMessageBuilder<T> getMessageBuilder(Class<T> clazz)
FudgeMessageBuilder
for the given class to convert a Fudge message to a Java object. If none is already registered for the class,
it will attempt to create one using the registered FudgeBuilderFactory
. If it is not possible to create a builder returns null
.
T
- Java type of the objects to be builtclazz
- the Java class to look up
null
if none is availablepublic boolean isDefaultObject(Class<?> clazz)
0
.
clazz
- the class to test, not null
true
if the object has a default serialization scheme.public Class<?> getDefaultObjectClass(int maxOrdinal)
maxOrdinal
- the highest ordinal used, or 0
if no field ordinals were present.
null
if the ordinal is not recognisedpublic void addAllAnnotatedBuilders()
FudgeBuilderFor
annotation, and registers those as appropriate
builders.
This is potentially a very expensive operation, and as such is optional.
public void addAnnotatedBuilderClass(String className)
FudgeBuilderFor
annotation as an object or message
builder (or both).
className
- The fully qualified name of the builder class.public void addAnnotatedGenericBuilderClass(String className)
GenericFudgeBuilderFor
annotation as builder.
className
- The fully qualified name of the builder class.
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |