BeanIO 1.2.3

org.beanio.types.xml
Class AbstractXmlDateTypeHandler

java.lang.Object
  extended by org.beanio.types.DateTypeHandler
      extended by org.beanio.types.xml.AbstractXmlDateTypeHandler
All Implemented Interfaces:
ConfigurableTypeHandler, TypeHandler
Direct Known Subclasses:
XmlDateTimeTypeHandler, XmlDateTypeHandler, XmlTimeTypeHandler

public abstract class AbstractXmlDateTypeHandler
extends DateTypeHandler

Base class for java.util.Date type handlers based on the W3C XML Schema datatype specification.

Since:
1.1
Author:
Kevin Seim

Field Summary
protected static DatatypeFactory dataTypeFactory
           
 
Fields inherited from interface org.beanio.types.ConfigurableTypeHandler
FORMAT_SETTING
 
Fields inherited from interface org.beanio.types.TypeHandler
NIL
 
Constructor Summary
AbstractXmlDateTypeHandler()
          Constructs a new AbstractXmlDateTypeHandler.
 
Method Summary
abstract  String format(Object value)
          Formats a Java object into field text.
protected abstract  QName getDatatypeQName()
          Returns the expected XML Schema data type when parse is called.
 String getTimeZoneId()
          Returns the time zone used to interpret dates, or null if the default time zone will be used.
protected  int getTimeZoneOffset(Date date)
          Returns the time zone offset in minutes for the given date, or DatatypeConstants.FIELD_UNDEFINED if a time zone was not configured.
 boolean isLenientDatatype()
          Returns whether data type validation is skipped when parsing field text.
 boolean isTimeZoneAllowed()
          Returns whether time zone information is allowed when parsing field text.
protected  Calendar newCalendar()
          Creates a new calendar using the configured time zone (if set).
 Date parse(String text)
          Parses field text into a Java object.
 void setLenientDatatype(boolean lenientDatatype)
          Sets whether data type validation is skipped when parsing field text.
 void setTimeZoneAllowed(boolean timeZoneAllowed)
          Sets whether time zone information is allowed when parsing field text.
 void setTimeZoneId(String name)
          Sets the time zone for interpreting dates.
 
Methods inherited from class org.beanio.types.DateTypeHandler
createDateFormat, createDefaultDateFormat, getPattern, getType, isLenient, newInstance, setLenient, setPattern
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

dataTypeFactory

protected static final DatatypeFactory dataTypeFactory
Constructor Detail

AbstractXmlDateTypeHandler

public AbstractXmlDateTypeHandler()
Constructs a new AbstractXmlDateTypeHandler.

Method Detail

parse

public Date parse(String text)
           throws TypeConversionException
Description copied from interface: TypeHandler
Parses field text into a Java object.

Specified by:
parse in interface TypeHandler
Overrides:
parse in class DateTypeHandler
Parameters:
text - the field text to parse, which may be null if the field was not passed in the record
Returns:
the parsed Java object
Throws:
TypeConversionException - if the text cannot be parsed

format

public abstract String format(Object value)
Description copied from interface: TypeHandler
Formats a Java object into field text.

Specified by:
format in interface TypeHandler
Overrides:
format in class DateTypeHandler
Parameters:
value - the Java object to format, which may be null
Returns:
the formatted field text, or null to indicate the value is not present, or TypeHandler.NIL for XML formatted streams

getDatatypeQName

protected abstract QName getDatatypeQName()
Returns the expected XML Schema data type when parse is called.

Returns:
the expected XML schema data type QName

newCalendar

protected Calendar newCalendar()
Creates a new calendar using the configured time zone (if set).

Returns:
a new Calendar instance

getTimeZoneOffset

protected int getTimeZoneOffset(Date date)
Returns the time zone offset in minutes for the given date, or DatatypeConstants.FIELD_UNDEFINED if a time zone was not configured.

Parameters:
date - the date on which to determine the time zone offset
Returns:
the time zone offset in minutes, or DatatypeConstants.FIELD_UNDEFINED

setTimeZoneId

public void setTimeZoneId(String name)
Sets the time zone for interpreting dates. If not set, the system default time zone is used.

Parameters:
name - the time zone ID
See Also:
TimeZone

getTimeZoneId

public String getTimeZoneId()
Returns the time zone used to interpret dates, or null if the default time zone will be used.

Returns:
the time zone ID
See Also:
TimeZone

isTimeZoneAllowed

public boolean isTimeZoneAllowed()
Returns whether time zone information is allowed when parsing field text. Defaults to true.

Returns:
true if time zone information is allowed when parsing field text

setTimeZoneAllowed

public void setTimeZoneAllowed(boolean timeZoneAllowed)
Sets whether time zone information is allowed when parsing field text. Defaults to true.

Parameters:
timeZoneAllowed - true if time zone information is allowed when parsing field text

isLenientDatatype

public boolean isLenientDatatype()
Returns whether data type validation is skipped when parsing field text. Set to false by default, a TypeConversionException is thrown when a XML dateTime type handler is used to parse a XML date or XML time, or a XML date handler is used to parse a XML dateTime field, etc.

Returns:
true if data type validation is skipped

setLenientDatatype

public void setLenientDatatype(boolean lenientDatatype)
Sets whether data type validation is skipped when parsing field text. Set to false by default, a TypeConversionException is thrown when a XML dateTime type handler is used to parse a XML date or XML time, or a XML date handler is used to parse a XML dateTime field, etc.

Parameters:
lenientDatatype - true if data type validation is skipped

BeanIO 1.2.3

Copyright © 2010-2012 Kevin Seim