com.vaadin.data.util.converter
Interface Converter<PRESENTATION,MODEL>

Type Parameters:
MODEL - The model type. Must be compatible with what getModelType() returns.
PRESENTATION - The presentation type. Must be compatible with what getPresentationType() returns.
All Superinterfaces:
Serializable
All Known Implementing Classes:
DateToLongConverter, ReverseConverter, StringToBooleanConverter, StringToDateConverter, StringToDoubleConverter, StringToIntegerConverter, StringToNumberConverter

public interface Converter<PRESENTATION,MODEL>
extends Serializable

Interface that implements conversion between a model and a presentation type.

Typically convertToPresentation(Object, Locale) and convertToModel(Object, Locale) should be symmetric so that chaining these together returns the original result for all input but this is not a requirement.

Converters must not have any side effects (never update UI from inside a converter).

All Converters must be stateless and thread safe.

If conversion of a value fails, a Converter.ConversionException is thrown.

Since:
7.0
Version:
7.0.0.alpha3
Author:
Vaadin Ltd.

Nested Class Summary
static class Converter.ConversionException
          An exception that signals that the value passed to convertToPresentation(Object, Locale) or convertToModel(Object, Locale) could not be converted.
 
Method Summary
 MODEL convertToModel(PRESENTATION value, Locale locale)
          Converts the given value from target type to source type.
 PRESENTATION convertToPresentation(MODEL value, Locale locale)
          Converts the given value from source type to target type.
 Class<MODEL> getModelType()
          The source type of the converter.
 Class<PRESENTATION> getPresentationType()
          The target type of the converter.
 

Method Detail

convertToModel

MODEL convertToModel(PRESENTATION value,
                     Locale locale)
                     throws Converter.ConversionException
Converts the given value from target type to source type.

A converter can optionally use locale to do the conversion.

A converter should in most cases be symmetric so chaining convertToPresentation(Object, Locale) and convertToModel(Object, Locale) should return the original value.

Parameters:
value - The value to convert, compatible with the target type. Can be null
locale - The locale to use for conversion. Can be null.
Returns:
The converted value compatible with the source type
Throws:
Converter.ConversionException - If the value could not be converted

convertToPresentation

PRESENTATION convertToPresentation(MODEL value,
                                   Locale locale)
                                   throws Converter.ConversionException
Converts the given value from source type to target type.

A converter can optionally use locale to do the conversion.

A converter should in most cases be symmetric so chaining convertToPresentation(Object, Locale) and convertToModel(Object, Locale) should return the original value.

Parameters:
value - The value to convert, compatible with the target type. Can be null
locale - The locale to use for conversion. Can be null.
Returns:
The converted value compatible with the source type
Throws:
Converter.ConversionException - If the value could not be converted

getModelType

Class<MODEL> getModelType()
The source type of the converter. Values of this type can be passed to convertToPresentation(Object, Locale).

Returns:
The source type

getPresentationType

Class<PRESENTATION> getPresentationType()
The target type of the converter. Values of this type can be passed to convertToModel(Object, Locale).

Returns:
The target type


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