org.restlet.engine.converter
Class ConverterHelper

java.lang.Object
  extended by org.restlet.engine.Helper
      extended by org.restlet.engine.converter.ConverterHelper
Direct Known Subclasses:
DefaultConverter

public abstract class ConverterHelper
extends Helper

Converter between Representations and regular Java objects.

Author:
Jerome Louvel

Constructor Summary
ConverterHelper()
           
 
Method Summary
protected  List<Class<?>> addObjectClass(List<Class<?>> objectClasses, Class<?> objectClass)
          Adds an object class to the given list.
protected  List<VariantInfo> addVariant(List<VariantInfo> variants, VariantInfo userVariant)
          Adds a variant to the given list.
abstract  List<Class<?>> getObjectClasses(Variant source)
          Returns the list of object classes that can be converted from a given variant.
abstract  List<VariantInfo> getVariants(Class<?> source)
          Returns the list of variants that can be converted from a given object class.
abstract  float score(Object source, Variant target, UniformResource resource)
          Scores the affinity of this helper with the source class.
abstract
<T> float
score(Representation source, Class<T> target, UniformResource resource)
          Scores the affinity of this helper with the source class.
abstract
<T> T
toObject(Representation source, Class<T> target, UniformResource resource)
          Converts a Representation into a regular Java object.
abstract  Representation toRepresentation(Object source, Variant target, UniformResource resource)
          Converts a regular Java object into a Representation.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ConverterHelper

public ConverterHelper()
Method Detail

addObjectClass

protected List<Class<?>> addObjectClass(List<Class<?>> objectClasses,
                                        Class<?> objectClass)
Adds an object class to the given list. Creates a new list if necessary.

Parameters:
objectClasses - The object classes list to update or null.
objectClass - The object class to add.
Returns:
The input object classes list or a new one.

addVariant

protected List<VariantInfo> addVariant(List<VariantInfo> variants,
                                       VariantInfo userVariant)
Adds a variant to the given list. Creates a new list if necessary.

Parameters:
variants - The variants list to update or null.
userVariant - The variant to add if not null.
Returns:
The input variants list or a new one.

getObjectClasses

public abstract List<Class<?>> getObjectClasses(Variant source)
Returns the list of object classes that can be converted from a given variant.

Parameters:
source - The source variant.
Returns:
The list of object class that can be converted.

getVariants

public abstract List<VariantInfo> getVariants(Class<?> source)
Returns the list of variants that can be converted from a given object class. The preferred variant should be set in first position.

Parameters:
source - The source object class.
Returns:
The list of variants that can be converted.

score

public abstract <T> float score(Representation source,
                                Class<T> target,
                                UniformResource resource)
Scores the affinity of this helper with the source class.

Parameters:
source - The source representation to convert.
target - The expected class of the Java object.
resource - The calling resource.
Returns:
The affinity score of this helper.

score

public abstract float score(Object source,
                            Variant target,
                            UniformResource resource)
Scores the affinity of this helper with the source class.

Parameters:
source - The source object to convert.
target - The expected representation metadata.
resource - The calling resource.
Returns:
The affinity score of this helper.

toObject

public abstract <T> T toObject(Representation source,
                               Class<T> target,
                               UniformResource resource)
                    throws IOException
Converts a Representation into a regular Java object.

Type Parameters:
T - The expected class of the Java object.
Parameters:
source - The source representation to convert.
target - The expected class of the Java object.
resource - The calling resource.
Returns:
The converted Java object.
Throws:
IOException

toRepresentation

public abstract Representation toRepresentation(Object source,
                                                Variant target,
                                                UniformResource resource)
                                         throws IOException
Converts a regular Java object into a Representation.

Parameters:
source - The source object to convert.
target - The expected representation metadata.
resource - The calling resource.
Returns:
The converted representation.
Throws:
IOException


Copyright © 2005-2010 Noelios Technologies.