org.jboss.util.coerce
Class CoercionHandler

java.lang.Object
  extended byorg.jboss.util.coerce.CoercionHandler
Direct Known Subclasses:
BoundCoercionHandler (src)

public abstract class CoercionHandler
extends java.lang.Object

An abstract class to allow extending the default behavior of Objects.coerce(Object,Class) when it is not possible to implement Coercible (src) directly in the target class or where coercion is desired from an unrelated class. Also provides a registry for all of the currently installed handlers.


Constructor Summary
CoercionHandler()
           
 
Method Summary
abstract  java.lang.Object coerce(java.lang.Object value, java.lang.Class type)
          Coerce the given value into the specified type.
static CoercionHandler (src) create(java.lang.Class type)
          Create a CoercionHandler for the given class type.
 java.lang.Class getType()
          Get the target class type for this CoercionHandler.
static void install(BoundCoercionHandler (src)  handler)
          Install a BoundCoercionHandler.
static void install(java.lang.Class type, CoercionHandler (src)  handler)
          Install a CoercionHandler for a given class type.
static boolean isInstalled(java.lang.Class type)
          Check if there is a CoercionHandler installed for the given class.
static CoercionHandler (src) lookup(java.lang.Class type)
          Lookup the CoercionHandler for a given class.
static void uninstall(java.lang.Class type)
          Uninstall a CoercionHandler for a given class type.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CoercionHandler

public CoercionHandler()
Method Detail

coerce

public abstract java.lang.Object coerce(java.lang.Object value,
                                        java.lang.Class type)
                                 throws CoercionException (src) 
Coerce the given value into the specified type.

Parameters:
value - Value to coerce
type - Object type to coerce into
Returns:
Coerced value
Throws:
CoercionException (src) - Failed to coerce

getType

public java.lang.Class getType()
Get the target class type for this CoercionHandler.

Returns:
Class type
Throws:
NotImplementedException (src) - Handler is not bound

install

public static void install(java.lang.Class type,
                           CoercionHandler (src)  handler)
Install a CoercionHandler for a given class type.

Parameters:
handler - Coercion handler
Throws:
NullArgumentException (src) - type or handler

install

public static void install(BoundCoercionHandler (src)  handler)
Install a BoundCoercionHandler.

Parameters:
handler - Bound coercion handler
Throws:
NullArgumentException (src) - handler

uninstall

public static void uninstall(java.lang.Class type)
Uninstall a CoercionHandler for a given class type.

Parameters:
type - Class type
Throws:
NullArgumentException (src) - type

isInstalled

public static boolean isInstalled(java.lang.Class type)
Check if there is a CoercionHandler installed for the given class.

Parameters:
type - Class type
Returns:
True if there is a CoercionHandler

lookup

public static CoercionHandler (src)  lookup(java.lang.Class type)
Lookup the CoercionHandler for a given class.

Parameters:
type - Class type
Returns:
A CoercionHandler or null if there is no installed handler
Throws:
NullArgumentException (src) - type

create

public static CoercionHandler (src)  create(java.lang.Class type)
Create a CoercionHandler for the given class type.

Parameters:
type - Class type
Returns:
A CoercionHandler instance for the given class type.
Throws:
CoercionException (src) - No installed handler for type