org.apache.commons.convert.conversion
Class DefaultValueDecorator

java.lang.Object
  extended by org.apache.commons.convert.conversion.DefaultValueDecorator

public class DefaultValueDecorator
extends Object

A utility class for decorating conversions and factories with default value behaviour.

Each public static method on this class will decorate the input conversion/factory with additional behaviour. Depending on the method it may return a default value in the case of an exception or null value

To use this facility, create an instance of the conversion/factory as normal. Then pass it to one of the static methods on this class. Finally add it as per normal to the ConverterRegistry.

Since:
1.0
Version:
$Id: DefaultValueDecorator.java 155441 2005-02-26 13:19:22Z dirkv $
Author:
Stephen Colebourne, Oliver Heger

Constructor Summary
protected DefaultValueDecorator()
          Restricted constructor.
 
Method Summary
static ConversionFactory defaultException(ConversionFactory factory, Object defaultValue)
          Creates a ConversionFactory that decorates the original and adds behaviour to return a default value when the conversion throws an exception.
static Conversion defaultException(Conversion conversion, Object defaultValue)
          Creates a Conversion that decorates the original and adds behaviour to return a default value when the conversion throws an exception.
static ConversionFactory defaultNullAndException(ConversionFactory factory, Object defaultValue)
          Creates a ConversionFactory that decorates the original and adds behaviour to return a default value for null input, null result and when an exception occurs.
static Conversion defaultNullAndException(Conversion conversion, Object defaultValue)
          Creates a Conversion that decorates the original and adds behaviour to return a default value for null input, null result and when an exception occurs.
static ConversionFactory defaultNullInput(ConversionFactory factory, Object defaultValue)
          Creates a ConversionFactory that decorates the original and adds behaviour to return a default value when the conversion input is null.
static Conversion defaultNullInput(Conversion conversion, Object defaultValue)
          Creates a Conversion that decorates the original and adds behaviour to return a default value when the conversion input is null.
static ConversionFactory defaultNullResult(ConversionFactory factory, Object defaultValue)
          Creates a ConversionFactory that decorates the original and adds behaviour to return a default value when the conversion results in null.
static Conversion defaultNullResult(Conversion conversion, Object defaultValue)
          Creates a Conversion that decorates the original and adds behaviour to return a default value when the conversion results in null.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DefaultValueDecorator

protected DefaultValueDecorator()
Restricted constructor.

Method Detail

defaultNullResult

public static Conversion defaultNullResult(Conversion conversion,
                                           Object defaultValue)
Creates a Conversion that decorates the original and adds behaviour to return a default value when the conversion results in null.

Parameters:
conversion - the conversion to decorate, not null
defaultValue - the value to return if conversion result is null
Returns:
the decorated conversion

defaultNullInput

public static Conversion defaultNullInput(Conversion conversion,
                                          Object defaultValue)
Creates a Conversion that decorates the original and adds behaviour to return a default value when the conversion input is null.

Parameters:
conversion - the conversion to decorate, not null
defaultValue - the value to return if conversion input is null
Returns:
the decorated conversion

defaultException

public static Conversion defaultException(Conversion conversion,
                                          Object defaultValue)
Creates a Conversion that decorates the original and adds behaviour to return a default value when the conversion throws an exception.

Parameters:
conversion - the conversion to decorate, not null
defaultValue - the value to return if conversion throws an exception
Returns:
the decorated conversion

defaultNullAndException

public static Conversion defaultNullAndException(Conversion conversion,
                                                 Object defaultValue)
Creates a Conversion that decorates the original and adds behaviour to return a default value for null input, null result and when an exception occurs.

Parameters:
conversion - the conversion to decorate, not null
defaultValue - the default value to return
Returns:
the decorated conversion

defaultNullResult

public static ConversionFactory defaultNullResult(ConversionFactory factory,
                                                  Object defaultValue)
Creates a ConversionFactory that decorates the original and adds behaviour to return a default value when the conversion results in null.

Parameters:
factory - the factory to decorate, not null
defaultValue - the value to return if conversion result is null
Returns:
the decorated factory

defaultNullInput

public static ConversionFactory defaultNullInput(ConversionFactory factory,
                                                 Object defaultValue)
Creates a ConversionFactory that decorates the original and adds behaviour to return a default value when the conversion input is null.

Parameters:
factory - the factory to decorate, not null
defaultValue - the value to return if conversion input is null
Returns:
the decorated factory

defaultException

public static ConversionFactory defaultException(ConversionFactory factory,
                                                 Object defaultValue)
Creates a ConversionFactory that decorates the original and adds behaviour to return a default value when the conversion throws an exception.

Parameters:
factory - the factory to decorate, not null
defaultValue - the value to return if conversion throws an exception
Returns:
the decorated factory

defaultNullAndException

public static ConversionFactory defaultNullAndException(ConversionFactory factory,
                                                        Object defaultValue)
Creates a ConversionFactory that decorates the original and adds behaviour to return a default value for null input, null result and when an exception occurs.

Parameters:
factory - the factory to decorate, not null
defaultValue - the default value to return
Returns:
the decorated factory


Copyright © 2003-2010 The Apache Software Foundation. All Rights Reserved.