org.chwf.converter
Class Converter

java.lang.Object
  |
  +--org.chwf.converter.Converter
Direct Known Subclasses:
BaseNumberConverter, BooleanConverter, CharacterConverter, CurrencyConverter, DateConverter, DefaultConverter, LongDateConverter, SQLDateConverter, SQLTimeConverter, SQLTimestampConverter, StringConverter

public abstract class Converter
extends java.lang.Object

Converter class. It is the superclass for more specific converters.

Author:
Paul Strack

Constructor Summary
protected Converter()
          No-op constructor.
 
Method Summary
static java.lang.String convert(java.lang.Object object)
          Utility method that converts the object to a string using the converter for its class.
abstract  java.lang.String format(java.lang.Object value)
          Format the conversion type as a string.
static Converter getConverter(java.lang.Class type)
          Factory method that gets the converter for the given data type.
static Converter getConverter(java.lang.String type)
          Factory method that gets the converter for the given data type.
 java.lang.String getType()
          The converter's datatype, or null if the type is unknown.
 boolean isSimpleType()
          Returns true if the converted type is simple.
abstract  java.lang.Object parse(java.lang.String value)
          Parse the string value to the conversion type.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Converter

protected Converter()
No-op constructor.

Method Detail

getConverter

public static Converter getConverter(java.lang.Class type)
Factory method that gets the converter for the given data type. This methods uses one of the following:

Parameters:
type - The class being converted.
Returns:
The converter for the class.

getConverter

public static Converter getConverter(java.lang.String type)
Factory method that gets the converter for the given data type. This methods uses one of the following:

Parameters:
type - The datatype being converted.
Returns:
The converter for the datatype.

convert

public static java.lang.String convert(java.lang.Object object)
Utility method that converts the object to a string using the converter for its class.

Parameters:
object - The object.
Returns:
The string value of the object.

parse

public abstract java.lang.Object parse(java.lang.String value)
                                throws ConversionException
Parse the string value to the conversion type. Supported only for simple datatypes.

Parameters:
value - The value being parsed.
Returns:
The resulting object.
Throws:
ConversionException - If parsing fails.

format

public abstract java.lang.String format(java.lang.Object value)
Format the conversion type as a string.

Parameters:
value - The value being format.
Returns:
The resulting string.

getType

public java.lang.String getType()
The converter's datatype, or null if the type is unknown.

Returns:
The converter's datatype.

isSimpleType

public boolean isSimpleType()
Returns true if the converted type is simple. If the type is not simple, then the parse() method will not function. Any type that uses the DefaultConverter is by definition not simple.

Returns:
true if the converted type is simple.


Copyright © 2002-2004, Paul Strack. All Rights Reserved.