/* * Copyright 2011 Vaadin Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); you may not * use this file except in compliance with the License. You may obtain a copy of * the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the * License for the specific language governing permissions and limitations under * the License. */ package com.vaadin.data.util.converter; import java.io.Serializable; import java.util.Locale; /** * Interface that implements conversion between a model and a presentation type. *
* Typically {@link #convertToPresentation(Object, Locale)} and * {@link #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 {@link ConversionException} is thrown. *
* * @param* A converter can optionally use locale to do the conversion. *
* A converter should in most cases be symmetric so chaining * {@link #convertToPresentation(Object, Locale)} and * {@link #convertToModel(Object, Locale)} should return the original value. * * @param value * The value to convert, compatible with the target type. Can be * null * @param locale * The locale to use for conversion. Can be null. * @return The converted value compatible with the source type * @throws ConversionException * If the value could not be converted */ public MODEL convertToModel(PRESENTATION value, Locale locale) throws 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 * {@link #convertToPresentation(Object, Locale)} and * {@link #convertToModel(Object, Locale)} should return the original value. * * @param value * The value to convert, compatible with the target type. Can be * null * @param locale * The locale to use for conversion. Can be null. * @return The converted value compatible with the source type * @throws ConversionException * If the value could not be converted */ public PRESENTATION convertToPresentation(MODEL value, Locale locale) throws ConversionException; /** * The source type of the converter. * * Values of this type can be passed to * {@link #convertToPresentation(Object, Locale)}. * * @return The source type */ public ClassConversionException
without a detail
* message.
*/
public ConversionException() {
}
/**
* Constructs a new ConversionException
with the specified
* detail message.
*
* @param msg
* the detail message
*/
public ConversionException(String msg) {
super(msg);
}
/**
* Constructs a new {@code ConversionException} with the specified
* cause.
*
* @param cause
* The cause of the the exception
*/
public ConversionException(Throwable cause) {
super(cause);
}
/**
* Constructs a new ConversionException
with the specified
* detail message and cause.
*
* @param message
* the detail message
* @param cause
* The cause of the the exception
*/
public ConversionException(String message, Throwable cause) {
super(message, cause);
}
}
}