com.planetalia.dynject.injection
Class Converters

java.lang.Object
  extended by com.planetalia.dynject.injection.Converters

public class Converters
extends java.lang.Object

Provides a central repository for conversions between different classes. Conversions are applied when the output of one data step cannot be fed directly into the following, or when the output of the last data step is not directly assignable to the property

Author:
Alexander Hristov

Field Summary
static java.lang.Class ANY_NUMERIC_CLASS
          Constant value representing "any numeric class".
static java.lang.String CONVERT_STRING_TO_ENUM
          Constant representing the capability of converting any string into the corresponding enumerated value
static java.lang.String CONVERT_USING_STRING_CONSTRUCTOR
          Constant representing the capability of converting strings into any class that has a public string constructor by creating an instance using that constructor.
 
Constructor Summary
Converters()
           
 
Method Summary
static void clearConverters()
          Removes all registered converters.
static IConverter getConverter(java.lang.Class fromClass, java.lang.Class toClass)
          Returns the converter to use for a specific conversion
static java.lang.Object getProperty(java.lang.String property)
          Returns a configuration property
static boolean isEquivalent(java.lang.Class classA, java.lang.Class classB)
          Checks whether two classes are assignment - equivalent
static boolean isNumeric(java.lang.Class clazz)
          Checks whether a specific value is numeric
static boolean isNumeric(java.lang.Object value)
          Checks whether a specific value is numeric
static void registerConverter(java.lang.Class fromClass, java.lang.Class toClass, IConverter converter)
          Registers a converter
static void registerStandardConverters()
          Used for testing purposes only
 void removeConverter(java.lang.Class fromClass, java.lang.Class toClass)
          Removes a converter previously registered.
static void setProperty(java.lang.String property, java.lang.Object value)
          Configures the overall working of the conversion process by setting a specific feature
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

CONVERT_USING_STRING_CONSTRUCTOR

public static final java.lang.String CONVERT_USING_STRING_CONSTRUCTOR
Constant representing the capability of converting strings into any class that has a public string constructor by creating an instance using that constructor.

See Also:
Constant Field Values

CONVERT_STRING_TO_ENUM

public static final java.lang.String CONVERT_STRING_TO_ENUM
Constant representing the capability of converting any string into the corresponding enumerated value

See Also:
Constant Field Values

ANY_NUMERIC_CLASS

public static final java.lang.Class ANY_NUMERIC_CLASS
Constant value representing "any numeric class". If this value is provided as a source class when registering a converter, it means that the converter is capable of converting any numeric class to the destination class. If this value is provided as a target class when registering a converter, it means that the converter is capable of converting from one specific class to any other numeric class. Obviously, the first case is much more frequent.
Numeric classes are

Constructor Detail

Converters

public Converters()
Method Detail

registerConverter

public static void registerConverter(java.lang.Class fromClass,
                                     java.lang.Class toClass,
                                     IConverter converter)
Registers a converter

Parameters:
fromClass - Source class
toClass - Destination class
converter - Converter instance. Converter instances are reused and must be thread-safe

clearConverters

public static void clearConverters()
Removes all registered converters. Used for unit tests only


removeConverter

public void removeConverter(java.lang.Class fromClass,
                            java.lang.Class toClass)
Removes a converter previously registered. The from and to classes must match exactly the original registration

Parameters:
fromClass - Source class or interface
toClass - Target class or interface

isNumeric

public static boolean isNumeric(java.lang.Class clazz)
Checks whether a specific value is numeric

Parameters:
clazz - Class to check
Returns:
true if it is numeric, false otherwise

isNumeric

public static boolean isNumeric(java.lang.Object value)
Checks whether a specific value is numeric

Parameters:
value - Value to check
Returns:
true if it is numeric, false otherwise

getConverter

public static IConverter getConverter(java.lang.Class fromClass,
                                      java.lang.Class toClass)
Returns the converter to use for a specific conversion

Parameters:
fromClass - Source class
toClass - Destination class
Returns:
Converter to use, or null if no converter is available

registerStandardConverters

public static void registerStandardConverters()
Used for testing purposes only


setProperty

public static void setProperty(java.lang.String property,
                               java.lang.Object value)
Configures the overall working of the conversion process by setting a specific feature

Parameters:
property - Property to set
value - value

getProperty

public static java.lang.Object getProperty(java.lang.String property)
Returns a configuration property

Parameters:
property -
Returns:
Value of the requested property

isEquivalent

public static boolean isEquivalent(java.lang.Class classA,
                                   java.lang.Class classB)
Checks whether two classes are assignment - equivalent

Parameters:
classA - First class to check
classB - Second class to check
Returns:
True if both classes are equivalent