All Packages  Class Hierarchy  This Package  Previous  Next  Index

Class org.xmlmiddleware.conversions.formatters.BooleanFormatter

java.lang.Object
   |
   +----org.xmlmiddleware.conversions.formatters.BooleanFormatter

public class BooleanFormatter
extends Object
implements StringFormatter
Implements the StringFormatter interface for boolean values.

The accepted string forms of true are:

    TRUE
    YES
    1
 

The accepted string forms of false are:

    FALSE
    NO
    0
 

All are case insensitive.

This class can easily be sub-classed to recognize other words as true and false. To do this, simply override the value of the trueValues and falseValues arrays and provide the string values to be recognized as true and false. The first value in each array is used as the output of the format method, and the caseSensitive variable states whether values are case sensitive or not.

For example, the following code creates a case-sensitive German version of Boolean formatter:

    public class GermanBooleanFormatter
       extends BooleanFormatter
       implements StringFormatter
    {
       public GermanBooleanFormatter() {super();}
       public String[] trueValues = {"wahr", "ja"};
       public String[] falseValues = {"falsch", "nein"};
       public boolean caseSensitive = true;
    }
 

Version:
2.0
Author:
Ronald Bourret, 2001

Variable Index

 o caseSensitive
Whether the strings in trueValues and falseValues are case sensitive.
 o falseValues
An array of strings to be recognized as false.
 o trueValues
An array of strings to be recognized as true.

Constructor Index

 o BooleanFormatter()

Method Index

 o canConvert(int)
Whether the class can convert to/from a certain type of object.
 o format(Object)
Convert a Boolean to a string.
 o parse(String, int)
Parse a boolean string.

Variables

 o trueValues
 public String trueValues[]
An array of strings to be recognized as true.

The first string is used as the output value of format().

 o falseValues
 public String falseValues[]
An array of strings to be recognized as false.

The first string is used as the output value of format().

 o caseSensitive
 public boolean caseSensitive
Whether the strings in trueValues and falseValues are case sensitive.

Constructors

 o BooleanFormatter
 public BooleanFormatter()

Methods

 o parse
 public Object parse(String s,
                     int jdbcType) throws XMLMiddlewareException
Parse a boolean string.

Parameters:
The - string to parse.
A - JDBC Types value indicating the type of object to return. This must be Types.BIT.
Returns:
A Boolean.
Throws: XMLMiddlewareException
Thrown if the string can't be parsed or the type isn't BIT.
 o format
 public String format(Object o) throws XMLMiddlewareException
Convert a Boolean to a string.

Parameters:
The - Boolean
Returns:
The string
Throws: XMLMiddlewareException
Thrown if the object is not a Boolean.
 o canConvert
 public boolean canConvert(int type)
Whether the class can convert to/from a certain type of object.

This method returns true for Types.BIT. It returns false for all other types.

Parameters:
type - The JDBC Types value corresponding to the object type.
Returns:
Whether the type is supported

All Packages  Class Hierarchy  This Package  Previous  Next  Index