org.codehaus.waffle.bind.converters
Class StringListValueConverter

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

public class StringListValueConverter
extends AbstractValueConverter

ValueConverter that converts CSV values to List of Strings. A null or empty value (once trimmed) will be returned as an empty list (behaviour which can be overridden via the convertMissingValue(java.lang.String, java.lang.String, java.lang.Object...) method). The message keys and default values used are:

The patterns are also optionally injectable via Properties in the constructor and take precedence over the ones configured in the messages resources.

Author:
Mauro Talevi

Field Summary
static java.lang.String BIND_ERROR_LIST_KEY
           
static java.lang.String DEFAULT_LIST_MESSAGE
           
 
Constructor Summary
StringListValueConverter(MessageResources messageResources)
           
StringListValueConverter(MessageResources messageResources, java.util.Properties patterns)
           
 
Method Summary
 boolean accept(java.lang.reflect.Type type)
          Accepts parameterized types of raw type List and argument type String
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
protected  java.util.List<java.lang.String> listValues(java.lang.String value)
           
 
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
 

Field Detail

BIND_ERROR_LIST_KEY

public static final java.lang.String BIND_ERROR_LIST_KEY
See Also:
Constant Field Values

DEFAULT_LIST_MESSAGE

public static final java.lang.String DEFAULT_LIST_MESSAGE
See Also:
Constant Field Values
Constructor Detail

StringListValueConverter

public StringListValueConverter(MessageResources messageResources)

StringListValueConverter

public StringListValueConverter(MessageResources messageResources,
                                java.util.Properties patterns)
Method Detail

accept

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

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

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

listValues

protected java.util.List<java.lang.String> listValues(java.lang.String value)

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 AbstractValueConverter
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.