org.cubeengine.converter
Class ConverterManager

java.lang.Object
  extended by org.cubeengine.converter.ConverterManager

public class ConverterManager
extends Object

This Class manages all Converter for a CodecManager or a Codec


Constructor Summary
protected ConverterManager(ConverterManager fallbackManager)
           
 
Method Summary
<T> T
convertFromNode(Node node, Type type)
          Converts a Node into an Object of given Type
<T> Node
convertToNode(T object)
          Converts a convertible Object into a Node
static ConverterManager defaultManager()
          Returns a ConverterManager with the default converters
protected  Object fromNode(Node node, Type type)
          When no converter was found directly this method is called in order to try to convert the object anyways.
<ConverterT>
ConverterT
getConverterByClass(Class<ConverterT> clazz)
          Returns the converter of given class
 Converter matchConverter(Class clazz)
          Matches a registered Converter
 ConverterManager registerConverter(Converter converter, Class... classes)
          Registers a Converter for given Class
 ConverterManager removeConverter(Class clazz)
          Removes a Converter from this manager
 ConverterManager removeConverters()
          Removes all registered converters
 ConverterManager subManager()
          Returns a new ConverterManager using this manager as fallback
protected
<T> Node
toNode(T object)
          When no converter was found directly this method is called in order to try to convert the object anyways.
 ConverterManager withFallback(ConverterManager defaultManager)
          Changes the fallback ConverterManager of this converter
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ConverterManager

protected ConverterManager(ConverterManager fallbackManager)
Method Detail

defaultManager

public static ConverterManager defaultManager()
Returns a ConverterManager with the default converters

Returns:
the manager

subManager

public final ConverterManager subManager()
Returns a new ConverterManager using this manager as fallback

Returns:
the new ConverterManager

registerConverter

public final ConverterManager registerConverter(Converter converter,
                                                Class... classes)
Registers a Converter for given Class

Parameters:
converter - the converter
classes - the class

removeConverter

public final ConverterManager removeConverter(Class clazz)
Removes a Converter from this manager

Parameters:
clazz - the class of the converter to remove

removeConverters

public final ConverterManager removeConverters()
Removes all registered converters


matchConverter

public final Converter matchConverter(Class clazz)
                               throws ConverterNotFoundException
Matches a registered Converter

Parameters:
clazz - the class to match for
Returns:
a matching converter
Throws:
ConverterNotFoundException

convertToNode

public final <T> Node convertToNode(T object)
                         throws ConversionException
Converts a convertible Object into a Node

Parameters:
object - the Object
Returns:
the serialized Node
Throws:
ConversionException

toNode

protected <T> Node toNode(T object)
               throws ConversionException
When no converter was found directly this method is called in order to try to convert the object anyways. Primarily used to convert Arrays.

Parameters:
object - the object to convert
Returns:
the converted object or null if not converted
Throws:
ConversionException

convertFromNode

public final <T> T convertFromNode(Node node,
                                   Type type)
                        throws ConversionException
Converts a Node into an Object of given Type

Parameters:
node - the node
type - the type of the object
Returns:
the converted Node
Throws:
ConversionException

fromNode

protected Object fromNode(Node node,
                          Type type)
                   throws ConversionException
When no converter was found directly this method is called in order to try to convert the object anyways. Primarily used to convert Arrays.

Parameters:
node - the node to convert
type - the type to convert to
Returns:
the converted node or null if not converted
Throws:
ConversionException

withFallback

public ConverterManager withFallback(ConverterManager defaultManager)
Changes the fallback ConverterManager of this converter

Parameters:
defaultManager - the ConverterManager to fallback to
Returns:
fluent interface

getConverterByClass

public final <ConverterT> ConverterT getConverterByClass(Class<ConverterT> clazz)
Returns the converter of given class

Type Parameters:
ConverterT - the converter Type
Parameters:
clazz - the class
Returns:
the converter for given class or null if not registered or found


Copyright © 2013–2017. All rights reserved.