com.taursys.util
Class DataTypes

java.lang.Object
  extended bycom.taursys.util.DataTypes

public class DataTypes
extends java.lang.Object

This class provides definition, conversion, and simple parsing for known data types.


Field Summary
static int TYPE_BIGDECIMAL
           
static int TYPE_BOOLEAN
           
static int TYPE_BYTE
           
static int TYPE_DATE
           
static int TYPE_DOUBLE
           
static int TYPE_FLOAT
           
static int TYPE_INT
           
static int TYPE_LONG
           
static int TYPE_SHORT
           
static int TYPE_SQL_DATE
           
static int TYPE_STRING
           
static int TYPE_TIME
           
static int TYPE_TIMESTAMP
           
static int TYPE_UNDEFINED
           
 
Method Summary
static void checkJavaDataType(int i)
          Checks given index to ensure it is valid type otherwise throws UnsupportedDataTypeException.
static java.lang.Object convert(int javaDataType, java.lang.Object value)
          Returns an object of the type indicated by javaDataType set from the value of the given object.
static java.lang.String format(int javaDataType, java.lang.Object value)
          Returns a default formatted String for the given object.
static java.lang.Class getClassForType(int javaDatType)
          Returns the Class for the given Java data type.
static int getDataType(java.lang.String className)
          Returns an int id for the given data type or TYPE_UNDEFINED if unknown.
static java.text.DateFormat getDefaultDateFormat()
          Get the default DataFormat used by the parse/format routines.
static java.lang.String getJavaNameForType(int javaDatType)
          Returns the class name for the given Java data type.
static java.lang.Object parse(int javaDataType, java.lang.String value)
          Returns a new object of type indicated by javaDataType with parsed given value.
static void setDefaultDateFormat(java.text.DateFormat dfNew)
          Set the default DataFormat used by the parse/format routines.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

TYPE_UNDEFINED

public static final int TYPE_UNDEFINED
See Also:
Constant Field Values

TYPE_STRING

public static final int TYPE_STRING
See Also:
Constant Field Values

TYPE_BIGDECIMAL

public static final int TYPE_BIGDECIMAL
See Also:
Constant Field Values

TYPE_TIMESTAMP

public static final int TYPE_TIMESTAMP
See Also:
Constant Field Values

TYPE_BOOLEAN

public static final int TYPE_BOOLEAN
See Also:
Constant Field Values

TYPE_INT

public static final int TYPE_INT
See Also:
Constant Field Values

TYPE_BYTE

public static final int TYPE_BYTE
See Also:
Constant Field Values

TYPE_SHORT

public static final int TYPE_SHORT
See Also:
Constant Field Values

TYPE_LONG

public static final int TYPE_LONG
See Also:
Constant Field Values

TYPE_FLOAT

public static final int TYPE_FLOAT
See Also:
Constant Field Values

TYPE_DATE

public static final int TYPE_DATE
See Also:
Constant Field Values

TYPE_TIME

public static final int TYPE_TIME
See Also:
Constant Field Values

TYPE_DOUBLE

public static final int TYPE_DOUBLE
See Also:
Constant Field Values

TYPE_SQL_DATE

public static final int TYPE_SQL_DATE
See Also:
Constant Field Values
Method Detail

getDefaultDateFormat

public static java.text.DateFormat getDefaultDateFormat()
Get the default DataFormat used by the parse/format routines. By default it is initialized to DateFormat.getDateTimeInstance( DateFormat.LONG, DateFormat.LONG).

Returns:
the default DataFormat used by the parse/format routines

setDefaultDateFormat

public static void setDefaultDateFormat(java.text.DateFormat dfNew)
Set the default DataFormat used by the parse/format routines. By default it is initialized to DateFormat.getDateTimeInstance( DateFormat.LONG, DateFormat.LONG).

Parameters:
dfNew - the default DataFormat used by the parse/format routines

getJavaNameForType

public static java.lang.String getJavaNameForType(int javaDatType)
                                           throws UnsupportedDataTypeException
Returns the class name for the given Java data type.

Returns:
Class name for the given Java data type
Throws:
UnsupportedDataTypeException - if the given value is not a known type.

getClassForType

public static java.lang.Class getClassForType(int javaDatType)
                                       throws UnsupportedDataTypeException
Returns the Class for the given Java data type.

Returns:
Class for the given Java data type
Throws:
UnsupportedDataTypeException - if the given value is not a known type.

checkJavaDataType

public static void checkJavaDataType(int i)
                              throws UnsupportedDataTypeException
Checks given index to ensure it is valid type otherwise throws UnsupportedDataTypeException.

Throws:
UnsupportedDataTypeException

getDataType

public static int getDataType(java.lang.String className)
Returns an int id for the given data type or TYPE_UNDEFINED if unknown.

Returns:
an int id for the given data type or TYPE_UNDEFINED if unknown

convert

public static java.lang.Object convert(int javaDataType,
                                       java.lang.Object value)
                                throws UnsupportedConversionException,
                                       UnsupportedDataTypeException
Returns an object of the type indicated by javaDataType set from the value of the given object. This effectively converts the given object to another type of object. There must be a reasonable expectation of conversion, otherwise an Exception ("Unsupported Data Type Conversion") will be thrown. A change of types can also cause rounding or truncation.

Throws:
UnsupportedConversionException
UnsupportedDataTypeException

parse

public static java.lang.Object parse(int javaDataType,
                                     java.lang.String value)
                              throws java.text.ParseException,
                                     UnsupportedDataTypeException
Returns a new object of type indicated by javaDataType with parsed given value.

Parameters:
javaDataType - indicates data type of value (see TYPE_xxx constants).
Returns:
Object representing parsed value of given String.
Throws:
UnsupportedDataTypeException - if unknown javaDataType given.
java.text.ParseException - if given value cannot be parsed.

format

public static java.lang.String format(int javaDataType,
                                      java.lang.Object value)
                               throws UnsupportedDataTypeException
Returns a default formatted String for the given object. If the type is TYPE_UNDEFINED, the toString() method is used.

Parameters:
javaDataType - indicates data type of value (see TYPE_xxx constants).
value - is the object to format as a String
Returns:
formatted String using default format for Object type.
Throws:
UnsupportedDataTypeException - if unknown javaDataType given.


Copyright © 2007 Martin T Phelan. All Rights Reserved.