net.sf.mmm.util.value.base
Class AbstractGenericValueConverter<SOURCE>

java.lang.Object
  extended by net.sf.mmm.util.component.base.AbstractComponent
      extended by net.sf.mmm.util.component.base.AbstractLoggableComponent
          extended by net.sf.mmm.util.value.base.AbstractGenericValueConverter<SOURCE>
Type Parameters:
SOURCE - is the generic type of the values to convert.
All Implemented Interfaces:
GenericValueConverter<SOURCE>
Direct Known Subclasses:
AbstractComposedValueConverter, StringValueConverterImpl

public abstract class AbstractGenericValueConverter<SOURCE>
extends AbstractLoggableComponent
implements GenericValueConverter<SOURCE>

This is the abstract base implementation of the GenericValueConverter interface.

Since:
1.0.1
Author:
Joerg Hohwiller (hohwille at users.sourceforge.net)

Constructor Summary
AbstractGenericValueConverter()
          The constructor.
 
Method Summary
<TARGET> TARGET
convertValue(SOURCE value, Object valueSource, Class<TARGET> targetClass)
          This method converts the given value to the given type.
<TARGET> TARGET
convertValue(SOURCE value, Object valueSource, Class<TARGET> targetClass, TARGET defaultValue)
          This method converts the given value to the given type.
<TARGET> TARGET
convertValue(SOURCE value, Object valueSource, Class<TARGET> type, Type targetType, TARGET defaultValue)
          This method converts the given value to the given type.
<TARGET extends Number>
TARGET
convertValue(SOURCE value, Object valueSource, TARGET minimum, TARGET maximum)
          This method converts the given value to a numeric type and also validates that it is in the given range from minimum to maximum.
<TARGET extends Number>
TARGET
convertValue(SOURCE value, Object valueSource, TARGET minimum, TARGET maximum, TARGET defaultValue)
          This method gets a numeric value and also validates that it is in the given range from minimum to maximum.
 
Methods inherited from class net.sf.mmm.util.component.base.AbstractLoggableComponent
doInitialize, getLogger, setLogger
 
Methods inherited from class net.sf.mmm.util.component.base.AbstractComponent
doInitialized, getInitializationState, initialize
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface net.sf.mmm.util.value.api.GenericValueConverter
convertValue
 

Constructor Detail

AbstractGenericValueConverter

public AbstractGenericValueConverter()
The constructor.

Method Detail

convertValue

public <TARGET> TARGET convertValue(SOURCE value,
                                    Object valueSource,
                                    Class<TARGET> targetClass)
                    throws ValueNotSetException,
                           WrongValueTypeException
This method converts the given value to the given type.

Specified by:
convertValue in interface GenericValueConverter<SOURCE>
Type Parameters:
TARGET - is the type to convert to.
Parameters:
value - is the value to convert. It may be null.
valueSource - describes the source of the value. This may be the filename where the value was read from, an XPath where the value was located in an XML document, etc. It is used in exceptions thrown if something goes wrong. This will help to find the problem easier.
targetClass - is the type the value should be converted to.
Returns:
the value converted to type.
Throws:
ValueNotSetException - if the given value is null.
WrongValueTypeException - if the given value is NOT null but can NOT be converted to the given type (e.g. if value is "12x" and type is Integer.class).

convertValue

public final <TARGET> TARGET convertValue(SOURCE value,
                                          Object valueSource,
                                          Class<TARGET> type,
                                          Type targetType,
                                          TARGET defaultValue)
                          throws WrongValueTypeException
This method converts the given value to the given type.

Specified by:
convertValue in interface GenericValueConverter<SOURCE>
Type Parameters:
TARGET - is the type to convert to.
Parameters:
value - is the value to convert. It may be null.
valueSource - describes the source of the value. This may be the filename where the value was read from, an XPath where the value was located in an XML document, etc. It is used in exceptions thrown if something goes wrong. This will help to find the problem easier.
type - is the type the value should be converted to. It is the raw-type of the given targetType.
targetType - is the type to convert the value to. It is potentially generic and therefore contains more detailed information than targetClass. E.g. the targetClass may be java.util.List while this targetType could be java.util.List<Long>. This could help e.g. if the value is a string like "2, 47, 4252525". The caller may supply the targetClass again here.
defaultValue - is returned if the given value is null. It may also be null.
Returns:
the value converted to type or the defaultValue if value was null. It will only return null if both value and defaultValue are null.
Throws:
WrongValueTypeException - if the given value is NOT null but can NOT be converted to the given type (e.g. if value is "12x" and type is Integer.class).

convertValue

public <TARGET> TARGET convertValue(SOURCE value,
                                    Object valueSource,
                                    Class<TARGET> targetClass,
                                    TARGET defaultValue)
                    throws WrongValueTypeException
This method converts the given value to the given type.

Specified by:
convertValue in interface GenericValueConverter<SOURCE>
Type Parameters:
TARGET - is the type to convert to.
Parameters:
value - is the value to convert. It may be null.
valueSource - describes the source of the value. This may be the filename where the value was read from, an XPath where the value was located in an XML document, etc. It is used in exceptions thrown if something goes wrong. This will help to find the problem easier.
targetClass - is the type the value should be converted to.
defaultValue - is returned if the given value is null. It may also be null.
Returns:
the value converted to type or the defaultValue if value was null. It will only return null if both value and defaultValue are null.
Throws:
WrongValueTypeException - if the given value is NOT null but can NOT be converted to the given type (e.g. if value is "12x" and type is Integer.class).

convertValue

public <TARGET extends Number> TARGET convertValue(SOURCE value,
                                                   Object valueSource,
                                                   TARGET minimum,
                                                   TARGET maximum,
                                                   TARGET defaultValue)
                                   throws WrongValueTypeException,
                                          ValueOutOfRangeException
This method gets a numeric value and also validates that it is in the given range from minimum to maximum.

Specified by:
convertValue in interface GenericValueConverter<SOURCE>
Type Parameters:
TARGET - is the numeric-type to convert to.
Parameters:
value - is the value to convert. It may be null.
valueSource - describes the source of the value. This may be the filename where the value was read from, an XPath where the value was located in an XML document, etc. It is used in exceptions thrown if something goes wrong. This will help to find the problem easier.
minimum - is the minimum number allowed. Use MIN_VALUE (e.g. Double.MIN_VALUE) if unbound.
maximum - is the maximum number allowed. Use MAX_VALUE (e.g. Long.MAX_VALUE) if unbound.
defaultValue - is the default returned if value is null. It may be null. Else it must be in the given range from minimum to maximum.
Returns:
the given value converted to <TARGET> in the range from minimum to maximum or the defaultValue if value is null. Will only be null if both value and defaultValue are null.
Throws:
WrongValueTypeException - if the value is NO number.
ValueOutOfRangeException - if the value is NOT in the given range from minimum to maximum.

convertValue

public <TARGET extends Number> TARGET convertValue(SOURCE value,
                                                   Object valueSource,
                                                   TARGET minimum,
                                                   TARGET maximum)
                                   throws ValueNotSetException,
                                          WrongValueTypeException,
                                          ValueOutOfRangeException
This method converts the given value to a numeric type and also validates that it is in the given range from minimum to maximum.

Specified by:
convertValue in interface GenericValueConverter<SOURCE>
Type Parameters:
TARGET - is the numeric-type to convert to.
Parameters:
value - is the value to convert. It may be null.
valueSource - describes the source of the value. This may be the filename where the value was read from, an XPath where the value was located in an XML document, etc. It is used in exceptions thrown if something goes wrong. This will help to find the problem easier.
minimum - is the minimum number allowed. Use MIN_VALUE (e.g. Double.MIN_VALUE) if unbound.
maximum - is the maximum number allowed. Use MAX_VALUE (e.g. Long.MAX_VALUE) if unbound.
Returns:
the requested value in the given range from minimum and maximum.
Throws:
ValueNotSetException - if the given value is null.
WrongValueTypeException - if the value is NO number.
ValueOutOfRangeException - if the value is NOT in the given range from minimum to maximum.


Copyright © 2001-2010 mmm-Team. All Rights Reserved.