org.granite.messaging.amf.io.convert
Class Converters

java.lang.Object
  extended by org.granite.messaging.amf.io.convert.Converters

public class Converters
extends Object

Author:
Franck WOLFF
See Also:
Converter, Reverter

Constructor Summary
Converters(List<Class<? extends Converter>> converterClasses)
          Constructs a new Converters instance with the supplied list of converters (possibly reverters).
 
Method Summary
 Object convert(Object value, Type targetType)
          Converts the supplied object to the supplied target type.
 Converter getConverter(Object value, Type targetType)
          Returns a suitable converter for supplied parameters or null if no converter can be found.
 Converter getConverter(Object value, Type targetType, boolean throwNotFoundException)
          Returns a suitable converter for supplied parameters or either returns null if no converter can be found or throws a NoConverterFoundException.
 Converter[] getConverters()
           
 boolean hasReverters()
          Returns true if at least one reverter is configured for this Converters instance.
 Object revert(Object value)
          Revert back to standard, AMF3 known Java type the supplied value.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Converters

public Converters(List<Class<? extends Converter>> converterClasses)
           throws NoSuchMethodException,
                  IllegalAccessException,
                  InvocationTargetException,
                  InstantiationException
Constructs a new Converters instance with the supplied list of converters (possibly reverters).

Parameters:
converterClasses - the list of all used converters.
Throws:
NoSuchMethodException - if one of the Converter does not have a constructor with a Converters parameter.
IllegalAccessException - if something goes wrong when creating an instance of one of the supplied Converter classes.
InvocationTargetException - if something goes wrong when creating an instance of one of the supplied Converter classes.
InstantiationException - if something goes wrong when creating an instance of one of the supplied Converter classes.
Method Detail

getConverter

public Converter getConverter(Object value,
                              Type targetType)
Returns a suitable converter for supplied parameters or null if no converter can be found. This method is equivalent to the getConverter(Object, Type, boolean) method with the throwNotFoundException parameter set to false.

Parameters:
value - the value to be converted
targetType - the type of the converted value
Returns:
a Converter instance or null if no suitable converter can be found

getConverter

public Converter getConverter(Object value,
                              Type targetType,
                              boolean throwNotFoundException)
                       throws NoConverterFoundException
Returns a suitable converter for supplied parameters or either returns null if no converter can be found or throws a NoConverterFoundException.

Parameters:
value - the value to be converted
targetType - the type of the converted value
throwNotFoundException - should an exception be thrown if no converter is found?
Returns:
a Converter instance or null if no suitable converter can be found
Throws:
NoConverterFoundException - if the throwNotFoundException parameter is set to true and no converter can be found.

convert

public Object convert(Object value,
                      Type targetType)
               throws NoConverterFoundException
Converts the supplied object to the supplied target type. This method is a simple shortcut for: this.getConverter(value, target, true).convert(value, targetType).

Parameters:
value - the object to be converted.
targetType - the target type.
Returns:
the converted object.
Throws:
NoConverterFoundException - if no suitable converter can be found.

hasReverters

public boolean hasReverters()
Returns true if at least one reverter is configured for this Converters instance.

Returns:
true if at least one reverter is configured for this Converters instance.

revert

public Object revert(Object value)
Revert back to standard, AMF3 known Java type the supplied value. This method iterates on all configured Reverters and returns the Reverter.revert(Object) method result if the Reverter.canRevert(Object) method returns true for the current Reverter instance.

Parameters:
value - the value to be reverted.
Returns:
the reverted value (same instance if none of the configured reverters apply).

getConverters

public Converter[] getConverters()