Package org.beanio.types.xml
Class AbstractXmlDateTypeHandler
- java.lang.Object
-
- org.beanio.types.LocaleSupport
-
- org.beanio.types.DateTypeHandlerSupport
-
- org.beanio.types.DateTypeHandler
-
- org.beanio.types.xml.AbstractXmlDateTypeHandler
-
- All Implemented Interfaces:
java.lang.Cloneable,ConfigurableTypeHandler,TypeHandler
- Direct Known Subclasses:
XmlDateTimeTypeHandler,XmlDateTypeHandler,XmlTimeTypeHandler
public abstract class AbstractXmlDateTypeHandler extends DateTypeHandler
Base class forjava.util.Datetype handlers based on the W3C XML Schema datatype specification.- Since:
- 1.1
-
-
Field Summary
Fields Modifier and Type Field Description protected static javax.xml.datatype.DatatypeFactorydataTypeFactory-
Fields inherited from class org.beanio.types.DateTypeHandlerSupport
lenient, pattern, timeZone
-
Fields inherited from class org.beanio.types.LocaleSupport
locale
-
Fields inherited from interface org.beanio.types.ConfigurableTypeHandler
FORMAT_SETTING
-
Fields inherited from interface org.beanio.types.TypeHandler
NIL
-
-
Constructor Summary
Constructors Constructor Description AbstractXmlDateTypeHandler()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description abstract java.lang.Stringformat(java.lang.Object value)Formats a Java object into field text.protected abstract javax.xml.namespace.QNamegetDatatypeQName()Returns the expected XML Schema data type whenparseis called.protected intgetTimeZoneOffset(java.util.Date date)Returns the time zone offset in minutes for the given date, orDatatypeConstants.FIELD_UNDEFINEDif a time zone was not configured.booleanisLenientDatatype()Returns whether data type validation is skipped when parsing field text.booleanisTimeZoneAllowed()Returns whether time zone information is allowed when parsing field text.protected java.util.CalendarnewCalendar()Creates a new calendar using the configured time zone (if set).java.util.Dateparse(java.lang.String text)Parses field text into a Java object.voidsetLenientDatatype(boolean lenientDatatype)Sets whether data type validation is skipped when parsing field text.voidsetTimeZoneAllowed(boolean timeZoneAllowed)Sets whether time zone information is allowed when parsing field text.-
Methods inherited from class org.beanio.types.DateTypeHandler
getType
-
Methods inherited from class org.beanio.types.DateTypeHandlerSupport
createDateFormat, createDefaultDateFormat, formatDate, getPattern, getTimeZone, getTimeZoneId, isLenient, newInstance, parseDate, setLenient, setPattern, setTimeZoneId
-
Methods inherited from class org.beanio.types.LocaleSupport
getLocale, setLocale
-
-
-
-
Method Detail
-
parse
public java.util.Date parse(java.lang.String text) throws TypeConversionExceptionDescription copied from interface:TypeHandlerParses field text into a Java object.- Specified by:
parsein interfaceTypeHandler- Overrides:
parsein classDateTypeHandler- 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 java.lang.String format(java.lang.Object value)
Description copied from interface:TypeHandlerFormats a Java object into field text.- Specified by:
formatin interfaceTypeHandler- Overrides:
formatin classDateTypeHandler- Parameters:
value- the Java object to format, which may be null- Returns:
- the formatted field text, or
nullto indicate the value is not present, orTypeHandler.NILfor XML formatted streams
-
getDatatypeQName
protected abstract javax.xml.namespace.QName getDatatypeQName()
Returns the expected XML Schema data type whenparseis called.- Returns:
- the expected XML schema data type
QName
-
newCalendar
protected java.util.Calendar newCalendar()
Creates a new calendar using the configured time zone (if set).- Returns:
- a new
Calendarinstance
-
getTimeZoneOffset
protected int getTimeZoneOffset(java.util.Date date)
Returns the time zone offset in minutes for the given date, orDatatypeConstants.FIELD_UNDEFINEDif 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
-
isTimeZoneAllowed
public boolean isTimeZoneAllowed()
Returns whether time zone information is allowed when parsing field text. Defaults totrue.- Returns:
trueif 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 totrue.- Parameters:
timeZoneAllowed-trueif 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 tofalseby default, aTypeConversionExceptionis 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:
trueif data type validation is skipped
-
setLenientDatatype
public void setLenientDatatype(boolean lenientDatatype)
Sets whether data type validation is skipped when parsing field text. Set tofalseby default, aTypeConversionExceptionis 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-trueif data type validation is skipped
-
-