All Packages  Class Hierarchy  This Package  Previous  Next  Index

Interface org.xmlmiddleware.conversions.formatters.StringFormatter

public interface StringFormatter
Interface for custom formatting classes.

Classes that are used with the FormatClass element in the XML-DBMS mapping language must implement this interface and provide a no-argument constructor. Such classes sometimes support formatting for only a single type of object, such as Boolean. Other times, they support formatting for a number of object types, such as all numeric types or all date/time types.

This interface uses JDBC Types values to specify the types of the underlying objects. The type mapping is as follows, and corresponds to the default mapping of JDBC types to Java, except for the binary types, which are mapped to ByteArray.

 BINARY, VARBINARY, LONGVARBINARY:  org.xmlmiddleware.conversions.ByteArray
CHAR, VARCHAR, LONGVARCHAR: String
DATE, TIME, TIMESTAMP: java.sql.Date
BIGINT: Long
INTEGER: Integer
SMALLINT: Short
TINYINT: Byte
DECIMAL, NUMERIC: BigDecimal
DOUBLE, FLOAT: Double
REAL: Float
BIT: Boolean

NOTE: One possible use of custom formatting classes is a to convert binary data to/from Base64. This could easily be done by wrapping a Base64 converter with an Formatter class.

Version:
2.0
Author:
Ronald Bourret, 2001

Method Index

 o canConvert(int)
Whether the implementing class can convert to/from a certain type of object.
 o format(Object)
Serialize an object as a string.
 o parse(String, int)
Parse a string and create an object.

Methods

 o parse
 public abstract Object parse(String s,
                              int jdbcType) throws XMLMiddlewareException
Parse a string and create an object.

Parameters:
s - The string to parse.
jdbcType - A JDBC Types value indicating the type of object to return.
Returns:
The object
Throws: XMLMiddlewareException
Thrown if the string can't be parsed by the implementing class.
 o format
 public abstract String format(Object o) throws XMLMiddlewareException
Serialize an object as a string.

The implementing class will generally support only a specific type of object, such as an Integer or a Date.

Parameters:
o - The object to serialize.
Returns:
The string
Throws: XMLMiddlewareException
Thrown if the object can't be serialized. This usually occurs when the object is of a type not recognized by the implementing class, such as when the implementing class operates only on Integers and the calling code passes a Date.
 o canConvert
 public abstract boolean canConvert(int type)
Whether the implementing class can convert to/from a certain type of object.

This method is generally used by tools to determine whether a given formatter is appropriate for a column.

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