wicket.util.convert
Class Converter

java.lang.Object
  extended by wicket.util.convert.Converter
All Implemented Interfaces:
java.io.Serializable, IConverter, ILocalizable

public class Converter
extends java.lang.Object
implements IConverter

Implementation of IConverter interface, which converts objects from one class to another. This class allows specific type converters implementing the ITypeConverter interface to be registered as conversion operations for specific types. By default this class registers type converters for Date, String and all Java primitive types and their wrapper classes.

To convert from a Double value to a String value you can use the generalized converter interface:

 final IConverter converter = new ConverterFactory().newConverter();
 converter.setLocale(Locale.US);
 converter.convert(new Double(7.1), String.class);
 
Or this can be accomplished by directly using the StringConverter type conversion class (which is registered as a type converter on the IConverter returned by the converter factory above).
 final StringConverter converter = new StringConverter(Locale.US);
 converter.convert(new Double(7.1));
 
When using Wicket, you should rarely need to use any of the conversion classes directly. There are convenient validators and conversion features built into Wicket that you can use directly.

Author:
Eelco Hillenius, Jonathan Locke
See Also:
IConverterFactory, Serialized Form

Constructor Summary
Converter()
          Constructor
Converter(java.util.Locale locale)
          Constructor
 
Method Summary
 void clear()
          Removes all registered converters.
 java.lang.Object convert(java.lang.Object value, java.lang.Class c)
          Converts the given value to class c.
 ITypeConverter get(java.lang.Class c)
          Gets the type converter that is registered for class c.
 IConverter getDefaultConverter()
          Gets the converter that is to be used when no registered converter is found.
 java.util.Locale getLocale()
          Gets the locale.
 ITypeConverter remove(java.lang.Class c)
          Removes the type converter currently registered for class c.
 ITypeConverter set(java.lang.Class c, ITypeConverter converter)
          Registers a converter for use with class c.
 void setDefaultConverter(IConverter defaultConverter)
          Sets the converter that is to be used when no registered converter is found.
 void setLocale(java.util.Locale locale)
          Sets the locale.
 java.lang.String toString(java.lang.Object value)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Converter

public Converter()
Constructor


Converter

public Converter(java.util.Locale locale)
Constructor

Parameters:
locale - The locale
Method Detail

clear

public final void clear()
Removes all registered converters.


convert

public final java.lang.Object convert(java.lang.Object value,
                                      java.lang.Class c)
Converts the given value to class c.

Specified by:
convert in interface IConverter
Parameters:
value - The value to convert
c - The class to convert to
Returns:
The converted value
See Also:
IConverter.convert(java.lang.Object, java.lang.Class)

get

public final ITypeConverter get(java.lang.Class c)
Gets the type converter that is registered for class c.

Parameters:
c - The class to get the type converter for
Returns:
The type converter that is registered for class c or null if no type converter was registered for class c

getDefaultConverter

public final IConverter getDefaultConverter()
Gets the converter that is to be used when no registered converter is found.

Returns:
the converter that is to be used when no registered converter is found

getLocale

public final java.util.Locale getLocale()
Description copied from interface: ILocalizable
Gets the locale.

Specified by:
getLocale in interface ILocalizable
Returns:
The locale
See Also:
ILocalizable.getLocale()

remove

public final ITypeConverter remove(java.lang.Class c)
Removes the type converter currently registered for class c.

Parameters:
c - The class for which the converter registration should be removed
Returns:
The converter that was registered for class c before removal or null if none was registered

set

public final ITypeConverter set(java.lang.Class c,
                                ITypeConverter converter)
Registers a converter for use with class c.

Parameters:
converter - The converter to add
c - The class for which the converter should be used
Returns:
The previous registered converter for class c or null if none was registered yet for class c

setDefaultConverter

public final void setDefaultConverter(IConverter defaultConverter)
Sets the converter that is to be used when no registered converter is found. This allows converter chaining.

Parameters:
defaultConverter - The converter that is to be used when no registered converter is found

setLocale

public void setLocale(java.util.Locale locale)
Description copied from interface: ILocalizable
Sets the locale.

Specified by:
setLocale in interface ILocalizable
Parameters:
locale - The locale
See Also:
ILocalizable.setLocale(java.util.Locale)

toString

public java.lang.String toString(java.lang.Object value)
Parameters:
value - The value to convert to a String
Returns:
The string


Copyright © 2004-2007 Wicket developers. All Rights Reserved.