com.vaadin.data.util.converter
Class ConverterUtil

java.lang.Object
  extended by com.vaadin.data.util.converter.ConverterUtil
All Implemented Interfaces:
Serializable

public class ConverterUtil
extends Object
implements Serializable

See Also:
Serialized Form

Constructor Summary
ConverterUtil()
           
 
Method Summary
static boolean canConverterHandle(Converter<?,?> converter, Class<?> presentationType, Class<?> modelType)
          Checks if the given converter can handle conversion between the given presentation and model type
static
<PRESENTATIONTYPE,MODELTYPE>
PRESENTATIONTYPE
convertFromModel(MODELTYPE modelValue, Class<? extends PRESENTATIONTYPE> presentationType, Converter<PRESENTATIONTYPE,MODELTYPE> converter, Locale locale)
          Convert the given value from the data source type to the UI type.
static
<MODELTYPE,PRESENTATIONTYPE>
MODELTYPE
convertToModel(PRESENTATIONTYPE presentationValue, Class<MODELTYPE> modelType, Converter<PRESENTATIONTYPE,MODELTYPE> converter, Locale locale)
           
static
<PRESENTATIONTYPE,MODELTYPE>
Converter<PRESENTATIONTYPE,MODELTYPE>
getConverter(Class<PRESENTATIONTYPE> presentationType, Class<MODELTYPE> modelType, Application application)
          Finds a converter that can convert from the given presentation type to the given model type and back.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ConverterUtil

public ConverterUtil()
Method Detail

getConverter

public static <PRESENTATIONTYPE,MODELTYPE> Converter<PRESENTATIONTYPE,MODELTYPE> getConverter(Class<PRESENTATIONTYPE> presentationType,
                                                                                              Class<MODELTYPE> modelType,
                                                                                              Application application)
Finds a converter that can convert from the given presentation type to the given model type and back. Uses the given application to find a ConverterFactory or, if application is null, uses the Application.getCurrent().

Type Parameters:
PRESENTATIONTYPE - The presentation type
MODELTYPE - The model type
Parameters:
presentationType - The presentation type
modelType - The model type
application - The application to use to find a ConverterFactory or null to use the current application
Returns:
A Converter capable of converting between the given types or null if no converter was found

convertFromModel

public static <PRESENTATIONTYPE,MODELTYPE> PRESENTATIONTYPE convertFromModel(MODELTYPE modelValue,
                                                                             Class<? extends PRESENTATIONTYPE> presentationType,
                                                                             Converter<PRESENTATIONTYPE,MODELTYPE> converter,
                                                                             Locale locale)
                                         throws Converter.ConversionException
Convert the given value from the data source type to the UI type.

Type Parameters:
PRESENTATIONTYPE - Presentation type
Parameters:
modelValue - The model value to convert
presentationType - The type of the presentation value
converter - The converter to (try to) use
locale - The locale to use for conversion
Returns:
The converted value, compatible with the presentation type, or the original value if its type is compatible and no converter is set.
Throws:
Converter.ConversionException - if there is no converter and the type is not compatible with the model type.

convertToModel

public static <MODELTYPE,PRESENTATIONTYPE> MODELTYPE convertToModel(PRESENTATIONTYPE presentationValue,
                                                                    Class<MODELTYPE> modelType,
                                                                    Converter<PRESENTATIONTYPE,MODELTYPE> converter,
                                                                    Locale locale)
                                throws Converter.ConversionException
Type Parameters:
MODELTYPE -
PRESENTATIONTYPE -
Parameters:
presentationValue -
modelType -
converter -
locale -
Returns:
Throws:
Converter.ConversionException

canConverterHandle

public static boolean canConverterHandle(Converter<?,?> converter,
                                         Class<?> presentationType,
                                         Class<?> modelType)
Checks if the given converter can handle conversion between the given presentation and model type

Parameters:
converter - The converter to check
presentationType - The presentation type
modelType - The model type
Returns:
true if the converter supports conversion between the given presentation and model type, false otherwise


Copyright © 2000-2011 Vaadin Ltd. All Rights Reserved.