Prev Class | Next Class | Frames | No Frames |
Summary: Nested | Field | Method | Constr | Detail: Nested | Field | Method | Constr |
java.lang.Object
org.apache.commons.beanutils.converters.AbstractArrayConverter
org.apache.commons.beanutils.converters.BooleanArrayConverter
public final class BooleanArrayConverter
extends AbstractArrayConverter
Converter
implementation that converts an incoming
String into a primitive array of boolean. On a conversion failure, returns
a specified default value or throws a ConversionException
depending
on how this instance is constructed.
By default, the values to be converted are expected to be those
recognised by a default instance of BooleanConverter. A customised
BooleanConverter can be provided in order to recognise alternative values
as true/false.
Field Summary | |
private static BooleanConverter |
|
static Class |
|
protected BooleanConverter |
|
Fields inherited from class org.apache.commons.beanutils.converters.AbstractArrayConverter | |
NO_DEFAULT , defaultValue , strings , useDefault |
Constructor Summary | |
| |
| |
|
Method Summary | |
Object |
|
Methods inherited from class org.apache.commons.beanutils.converters.AbstractArrayConverter | |
convert , parseElements |
private static final BooleanConverter DEFAULT_CONVERTER
The converter that all instances of this class will use to do individual string->boolean conversions, unless overridden in the constructor.
public static final Class MODEL
Type which this class converts its input to. This value can be used as a parameter to the ConvertUtils.register method.
protected final BooleanConverter booleanConverter
This object is used to perform the conversion of individual strings into Boolean/boolean values.
public BooleanArrayConverter()
Create aConverter
that will throw aConversionException
if a conversion error occurs. Conversion of strings to boolean values will be done via a default instance of class BooleanConverter.
public BooleanArrayConverter(Object defaultValue)
Create aConverter
that will return the specified default value if a conversion error occurs. Conversion of strings to boolean values will be done via a default instance of class BooleanConverter.
- Parameters:
defaultValue
- The default value to be returned
public BooleanArrayConverter(BooleanConverter converter, Object defaultValue)
Create aConverter
that will return the specified default value if a conversion error occurs. Conversion of strings to boolean values will be done via the specified converter.
- Parameters:
converter
- is the converter object that will be used to convert each input string-value into a boolean.defaultValue
- is the default value to be returned by method convert if conversion fails; null is a valid default value. See the documentation for method "convert" for more information. The value BooleanArrayConverter.NO_DEFAULT may be passed here to specify that an exception should be thrown on conversion failure.
public Object convert(Class type, Object value)
Convert the specified input object into an output object of type array-of-boolean. If the input value is null, then the default value specified in the constructor is returned. If no such value was provided, then a ConversionException is thrown instead. If the input value is of type String[] then the returned array shall be of the same size as this array, with a true or false value in each array element depending on the result of applying method BooleanConverter.convert to each string. For all other types of value, the object's toString method is expected to return a string containing a comma-separated list of values, eg "true, false, true". See the documentation forAbstractArrayConverter.parseElements(String)
for more information on the exact formats supported. If the result of value.toString() cannot be split into separate words, then the default value is also returned (or an exception thrown). If any of the elements in the value array (or the elements resulting from splitting up value.toString) are not recognised by the BooleanConverter associated with this object, then what happens depends on whether that BooleanConverter has a default value or not: if it does, then that unrecognised element is converted into the BooleanConverter's default value. If the BooleanConverter does not have a default value, then the default value for this object is returned as the complete conversion result (not just for the element), or an exception is thrown if this object has no default value defined.
- Overrides:
- convert in interface AbstractArrayConverter
- Parameters:
type
- is the type to which this value should be converted. In the case of this BooleanArrayConverter class, this value is ignored.value
- is the input value to be converted.
- Returns:
- an object of type boolean[], or the default value if there was any sort of error during conversion and the constructor was provided with a default value.