org.xwiki.properties.converter
Class AbstractConverter

java.lang.Object
  extended by org.xwiki.properties.converter.AbstractConverter
All Implemented Interfaces:
Converter
Direct Known Subclasses:
AbstractCollectionConverter

public abstract class AbstractConverter
extends Object
implements Converter

Helper base class for a Converter component.

Commonly a new component is supposed to implements convertToString(Object) and convertToType(Class, Object).

Since:
2.0M2
Version:
$Id: de657eb5eb1818290c4d4a6f92c990d29b5a2a19 $

Constructor Summary
AbstractConverter()
           
 
Method Summary
<T> T
convert(Type targetType, Object sourceValue)
           
protected  String convertToString(Object value)
          Convert the input object into a String.
protected
<T> T
convertToType(Class<T> type, Object value)
          Deprecated. since 3.0M1 overwrite convertToType(Type, Object) instead
protected
<T> T
convertToType(Type targetType, Object value)
          Convert the input object into an output object of the specified type.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AbstractConverter

public AbstractConverter()
Method Detail

convert

public <T> T convert(Type targetType,
                     Object sourceValue)
Specified by:
convert in interface Converter
Type Parameters:
T - the type in which the provided value has to be converted
Parameters:
targetType - the type in which the provided value has to be converted
sourceValue - the value to convert
Returns:
the converted value

convertToString

protected String convertToString(Object value)
Convert the input object into a String.

N.B.This implementation simply uses the value's toString() method and should be overridden if a more sophisticated mechanism for conversion to a String is required.

Parameters:
value - The input value to be converted.
Returns:
the converted String value.

convertToType

protected <T> T convertToType(Type targetType,
                              Object value)
Convert the input object into an output object of the specified type.

Typical implementations will provide a minimum of String --> type conversion.

Type Parameters:
T - the type in which the provided value has o be converted
Parameters:
targetType - Data type to which this value should be converted.
value - The input value to be converted.
Returns:
The converted value.
Since:
3.0M1

convertToType

@Deprecated
protected <T> T convertToType(Class<T> type,
                                         Object value)
Deprecated. since 3.0M1 overwrite convertToType(Type, Object) instead

Convert the input object into an output object of the specified type.

Typical implementations will provide a minimum of String --> type conversion.

Type Parameters:
T - the type in which the provided value has o be converted
Parameters:
type - Data type to which this value should be converted.
value - The input value to be converted.
Returns:
The converted value.


Copyright © 2004-2012 XWiki. All Rights Reserved.