to.etc.domui.converter
Class ConverterRegistry

java.lang.Object
  extended by to.etc.domui.converter.ConverterRegistry

public class ConverterRegistry
extends java.lang.Object

A repository of Converter instances.

Author:
Frits Jalvingh Created on Jun 12, 2008

Constructor Summary
ConverterRegistry()
           
 
Method Summary
static
<X,T extends IConverter<X>>
X
convertStringToValue(java.lang.Class<T> clz, java.util.Locale loc, java.lang.String in)
          Convert a String value to some object, using the specified converter.
static
<X,T extends IConverter<X>>
X
convertStringToValue(java.lang.Class<T> clz, java.lang.String in)
          Convert a String value to some object, using the specified converter.
static
<X> java.lang.String
convertToString(PropertyMetaModel<X> pmm, X value)
          Convert the value which is for a given property to a presentation string.
static
<X> X
convertURLStringToValue(java.lang.Class<X> toType, java.lang.String svalue)
          Convert the URL string passed to some object value.
static
<X,T extends IConverter<X>>
java.lang.String
convertValueToString(java.lang.Class<T> clz, java.util.Locale loc, X in)
          Convert some object to a String value, using the specified converter.
static
<X,T extends IConverter<X>>
java.lang.String
convertValueToString(java.lang.Class<T> clz, X in)
          Convert some object to a String value, using the specified converter.
static
<X> IConverter<X>
findBestConverter(PropertyMetaModel<X> pmm)
          Obtain the very best presentation converter we can find for the specified property.
static
<X> IConverter<X>
findConverter(java.lang.Class<X> clz)
          Finds the best converter to convert a value of the specified type to a string.
static
<X> IConverter<X>
findConverter(java.lang.Class<X> clz, PropertyMetaModel<X> pmm)
          Finds the best converter to convert a value of the specified type (and the optionally specified metadata) to a string.
static
<X> IConverter<X>
findURLConverter(java.lang.Class<X> totype)
          Find an URL converter to convert to the given type.
static
<X> IConverter<X>
getConverter(java.lang.Class<X> clz, PropertyMetaModel<X> pmm)
          Gets the best converter to convert a value of the specified type (and the optionally specified metadata) to a string.
static
<X,T extends IConverter<X>>
T
getConverterInstance(java.lang.Class<T> clz)
          Get an instance of a given converter type.
static void register(IConverterFactory cf)
          Registers the specified converter factory.
static
<X> void
registerURLConverter(java.lang.Class<X> totype, IConverter<X> c)
          Register an URL converter for the specified class.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ConverterRegistry

public ConverterRegistry()
Method Detail

getConverterInstance

public static <X,T extends IConverter<X>> T getConverterInstance(java.lang.Class<T> clz)
Get an instance of a given converter type. Instances are cached and reused.

Parameters:
clz -
Returns:

convertStringToValue

public static <X,T extends IConverter<X>> X convertStringToValue(java.lang.Class<T> clz,
                                                                 java.util.Locale loc,
                                                                 java.lang.String in)
                              throws java.lang.Exception
Convert a String value to some object, using the specified converter.

Parameters:
clz -
loc -
in -
Returns:
Throws:
java.lang.Exception

convertValueToString

public static <X,T extends IConverter<X>> java.lang.String convertValueToString(java.lang.Class<T> clz,
                                                                                java.util.Locale loc,
                                                                                X in)
                                             throws java.lang.Exception
Convert some object to a String value, using the specified converter.

Parameters:
clz -
loc -
in -
Returns:
Throws:
java.lang.Exception

convertStringToValue

public static <X,T extends IConverter<X>> X convertStringToValue(java.lang.Class<T> clz,
                                                                 java.lang.String in)
                              throws java.lang.Exception
Convert a String value to some object, using the specified converter. This uses the "current" locale.

Parameters:
clz -
in -
Returns:
Throws:
java.lang.Exception

convertValueToString

public static <X,T extends IConverter<X>> java.lang.String convertValueToString(java.lang.Class<T> clz,
                                                                                X in)
                                             throws java.lang.Exception
Convert some object to a String value, using the specified converter. This uses the "current" locale.

Parameters:
clz -
in -
Returns:
Throws:
java.lang.Exception

registerURLConverter

public static <X> void registerURLConverter(java.lang.Class<X> totype,
                                            IConverter<X> c)
Register an URL converter for the specified class.

Parameters:
totype -
c -

findURLConverter

public static <X> IConverter<X> findURLConverter(java.lang.Class<X> totype)
Find an URL converter to convert to the given type.

Parameters:
totype -
Returns:

convertURLStringToValue

public static <X> X convertURLStringToValue(java.lang.Class<X> toType,
                                            java.lang.String svalue)
                                 throws java.lang.Exception
Convert the URL string passed to some object value.

Parameters:
toType -
svalue -
Returns:
Throws:
java.lang.Exception

register

public static void register(IConverterFactory cf)
Registers the specified converter factory.


findConverter

public static <X> IConverter<X> findConverter(java.lang.Class<X> clz,
                                              PropertyMetaModel<X> pmm)
Finds the best converter to convert a value of the specified type (and the optionally specified metadata) to a string. This walks the converter factory list and finds the best converter to use. If no factory accepts the type this returns null. To get a valid converter all of the time use getConverter(); this returns the "default converter" if no specific converter could be found.

Parameters:
clz - The class type of the value to convert
pmm - The metadata for the property, or null if unknown.
Returns:
A converter instance, or null if no factory claimed the type.

findConverter

public static <X> IConverter<X> findConverter(java.lang.Class<X> clz)
Finds the best converter to convert a value of the specified type to a string. This walks the converter factory list and finds the best converter to use. If no factory accepts the type this returns null. To get a valid converter all of the time use getConverter(); this returns the "default converter" if no specific converter could be found.

Parameters:
clz - The class type of the value to convert

getConverter

public static <X> IConverter<X> getConverter(java.lang.Class<X> clz,
                                             PropertyMetaModel<X> pmm)
Gets the best converter to convert a value of the specified type (and the optionally specified metadata) to a string. This walks the converter factory list and finds the best converter to use. If no factory accepts the type this returns the default converter.

Parameters:
clz - The class type of the value to convert
pmm - The metadata for the property, or null if unknown.
Returns:
A converter instance.

convertToString

public static <X> java.lang.String convertToString(PropertyMetaModel<X> pmm,
                                                   X value)
Convert the value which is for a given property to a presentation string.

Type Parameters:
X -
Parameters:
pmm -
value -
Returns:

findBestConverter

public static <X> IConverter<X> findBestConverter(PropertyMetaModel<X> pmm)
Obtain the very best presentation converter we can find for the specified property.

Parameters:
pmm -
Returns: