org.codehaus.waffle.bind.converters
Class NumberListValueConverter

java.lang.Object
  extended by org.codehaus.waffle.bind.converters.AbstractValueConverter
      extended by org.codehaus.waffle.bind.converters.StringListValueConverter
          extended by org.codehaus.waffle.bind.converters.NumberListValueConverter
All Implemented Interfaces:
ValueConverter

public class NumberListValueConverter
extends StringListValueConverter

ValueConverter that converts a CSV value to a List of Numbers. It extends StringListValueConverter to provide number parsing of the string values using the NumberFormat instance provided (which defaults to NumberFormat.getInstance()) and if not successful returns the string values themselves.

Author:
Mauro Talevi

Field Summary
 
Fields inherited from class org.codehaus.waffle.bind.converters.StringListValueConverter
BIND_ERROR_LIST_KEY, DEFAULT_LIST_MESSAGE
 
Constructor Summary
NumberListValueConverter(MessageResources messageResources)
           
NumberListValueConverter(MessageResources messageResources, java.util.Properties patterns, java.text.NumberFormat numberFormat)
           
 
Method Summary
 boolean accept(java.lang.reflect.Type type)
          Accepts parameterized types of raw type List and argument type Number
protected  java.lang.Object convertMissingValue(java.lang.String key, java.lang.String defaultMessage, java.lang.Object... parameters)
          Handles the case of a missing value.
 java.lang.Object convertValue(java.lang.String propertyName, java.lang.String value, java.lang.reflect.Type toType)
          Converts a String value to an Object of a given type
 
Methods inherited from class org.codehaus.waffle.bind.converters.StringListValueConverter
listValues
 
Methods inherited from class org.codehaus.waffle.bind.converters.AbstractValueConverter
acceptList, acceptMapOfLists, changePatterns, getPatterns, matches, messageFor, missingValue, newBindException, patternFor, split
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

NumberListValueConverter

public NumberListValueConverter(MessageResources messageResources)

NumberListValueConverter

public NumberListValueConverter(MessageResources messageResources,
                                java.util.Properties patterns,
                                java.text.NumberFormat numberFormat)
Method Detail

accept

public boolean accept(java.lang.reflect.Type type)
Accepts parameterized types of raw type List and argument type Number

Specified by:
accept in interface ValueConverter
Overrides:
accept in class StringListValueConverter
Parameters:
type - the Type a value is to be bound to
Returns:
A boolean true is type is compatible

convertValue

public java.lang.Object convertValue(java.lang.String propertyName,
                                     java.lang.String value,
                                     java.lang.reflect.Type toType)
Description copied from interface: ValueConverter
Converts a String value to an Object of a given type

Specified by:
convertValue in interface ValueConverter
Overrides:
convertValue in class StringListValueConverter
Parameters:
propertyName - the associated property name, which can be null, also needed to present customized error messages.
value - the String value
toType - the Object Type
Returns:
The converted Object

convertMissingValue

protected java.lang.Object convertMissingValue(java.lang.String key,
                                               java.lang.String defaultMessage,
                                               java.lang.Object... parameters)
Description copied from class: AbstractValueConverter
Handles the case of a missing value. By default it return a null converted value, but can be overridden to throw a BindException

Overrides:
convertMissingValue in class StringListValueConverter
Parameters:
key - the error message key
defaultMessage - the default message if key is not found
parameters - the message formatting parameters
Returns:
A converted object when value is missing, null by default.


Copyright © 2008. All Rights Reserved.