org.restlet.engine.converter
Class DefaultConverter

java.lang.Object
  extended by org.restlet.engine.Helper
      extended by org.restlet.engine.converter.ConverterHelper
          extended by org.restlet.engine.converter.DefaultConverter

public class DefaultConverter
extends ConverterHelper

Converter for the built-in Representation classes.

Author:
Jerome Louvel

Constructor Summary
DefaultConverter()
           
 
Method Summary
 List<Class<?>> getObjectClasses(Variant source)
          Returns the list of object classes that can be converted from a given variant.
 List<VariantInfo> getVariants(Class<?> source)
          Returns the list of variants that can be converted from a given object class.
 float score(Object source, Variant target, Resource resource)
          Scores the affinity of this helper with the source class.
<T> float
score(Representation source, Class<T> target, Resource resource)
          Scores the affinity of this helper with the source class.
<T> T
toObject(Representation source, Class<T> target, Resource resource)
          Converts a Representation into a regular Java object.
 Representation toRepresentation(Object source, Variant target, Resource resource)
          Converts a regular Java object into a Representation.
<T> void
updatePreferences(List<Preference<MediaType>> preferences, Class<T> entity)
          Updates the preferences of the given ClientInfo object with conversion capabilities for the given entity class.
 
Methods inherited from class org.restlet.engine.converter.ConverterHelper
addObjectClass, addVariant, addVariants, getVariants, updatePreferences
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DefaultConverter

public DefaultConverter()
Method Detail

getObjectClasses

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

Specified by:
getObjectClasses in class ConverterHelper
Parameters:
source - The source variant.
Returns:
The list of object class that can be converted.

getVariants

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

Specified by:
getVariants in class ConverterHelper
Parameters:
source - The source object class.
Returns:
The list of variants that can be converted.

score

public float score(Object source,
                   Variant target,
                   Resource resource)
Description copied from class: ConverterHelper
Scores the affinity of this helper with the source class.

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

score

public <T> float score(Representation source,
                       Class<T> target,
                       Resource resource)
Description copied from class: ConverterHelper
Scores the affinity of this helper with the source class.

Specified by:
score in class ConverterHelper
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.

toObject

public <T> T toObject(Representation source,
                      Class<T> target,
                      Resource resource)
           throws IOException
Description copied from class: ConverterHelper
Converts a Representation into a regular Java object.

Specified by:
toObject in class ConverterHelper
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 Representation toRepresentation(Object source,
                                       Variant target,
                                       Resource resource)
                                throws IOException
Description copied from class: ConverterHelper
Converts a regular Java object into a Representation.

Specified by:
toRepresentation in class ConverterHelper
Parameters:
source - The source object to convert.
target - The expected representation metadata.
resource - The calling resource.
Returns:
The converted representation.
Throws:
IOException

updatePreferences

public <T> void updatePreferences(List<Preference<MediaType>> preferences,
                                  Class<T> entity)
Description copied from class: ConverterHelper
Updates the preferences of the given ClientInfo object with conversion capabilities for the given entity class.

Overrides:
updatePreferences in class ConverterHelper
Parameters:
preferences - The media type preferences.
entity - The entity class to convert.


Copyright © 2005-2013 Restlet.