org.apache.commons.beanutils.converters

Class AbstractArrayConverter

Implemented Interfaces:
Converter
Known Direct Subclasses:
BooleanArrayConverter, ByteArrayConverter, CharacterArrayConverter, DoubleArrayConverter, FloatArrayConverter, IntegerArrayConverter, LongArrayConverter, ShortArrayConverter, StringArrayConverter

public abstract class AbstractArrayConverter
extends java.lang.Object
implements Converter

Convenience base class for converters that translate the String representation of an array into a corresponding array of primitives object. This class encapsulates the functionality required to parse the String into a list of String elements that can later be individually converted to the appropriate primitive type.

The input syntax accepted by the parseElements() method is designed to be compatible with the syntax used to initialize arrays in a Java source program, except that only String literal values are supported. For maximum flexibility, the surrounding '{' and '}' characters are optional, and individual elements may be separated by any combination of whitespace and comma characters.

Version:
$Revision: 1.6 $ $Date: 2004/02/28 13:18:34 $
Author:
Craig R. McClanahan
Since:
1.4

Field Summary

protected Object
defaultValue
The default value specified to our Constructor, if any.
protected static String[]
strings
Model object for string arrays.
protected boolean
useDefault
Should we return the default value on conversion errors?

Method Summary

abstract Object
convert(Class type, Object value)
Convert the specified input object into an output object of the specified type.
protected List
parseElements(String svalue)
Parse an incoming String of the form similar to an array initializer in the Java language into a List individual Strings for each element, according to the following rules.

Field Details

defaultValue

protected Object defaultValue
The default value specified to our Constructor, if any.

strings

protected static String[] strings
Model object for string arrays.

useDefault

protected boolean useDefault
Should we return the default value on conversion errors?

Method Details

convert

public abstract Object convert(Class type,
                               Object value)
Convert the specified input object into an output object of the specified type. This method must be implemented by a concrete subclass.
Specified by:
convert in interface Converter
Parameters:
type - Data type to which this value should be converted
value - The input value to be converted

parseElements

protected List parseElements(String svalue)
Parse an incoming String of the form similar to an array initializer in the Java language into a List individual Strings for each element, according to the following rules.
  • The string must have matching '{' and '}' delimiters around a comma-delimited list of values.
  • Whitespace before and after each element is stripped.
  • If an element is itself delimited by matching single or double quotes, the usual rules for interpreting a quoted String apply.
Parameters:
svalue - String value to be parsed

Copyright (c) 2001-2004 - Apache Software Foundation