BeanIO 2.0.4

org.beanio.types
Class DateTypeHandler

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

public class DateTypeHandler
extends Object
implements ConfigurableTypeHandler

This type handler uses a SimpleDateFormat class to parse and format java.util.Date objects. If no pattern is set, DateFormat.getInstance() is used to create a default date format. By default, lenient is false.

Since:
1.0
Author:
Kevin Seim
See Also:
Date, DateFormat, SimpleDateFormat

Field Summary
 
Fields inherited from interface org.beanio.types.ConfigurableTypeHandler
FORMAT_SETTING
 
Fields inherited from interface org.beanio.types.TypeHandler
NIL
 
Constructor Summary
DateTypeHandler()
          Constructs a new DateTypeHandler.
DateTypeHandler(String pattern)
          Constructs a new DateTypeHandler.
 
Method Summary
protected  DateFormat createDateFormat()
          Creates the DateFormat to use to parse and format the field value.
protected  DateFormat createDefaultDateFormat()
          Creates a default date format when no pattern is set.
 String format(Object value)
          Formats a Java object into field text.
 String getPattern()
          Returns the date pattern used by the SimpleDateFormat.
 Class<?> getType()
          Returns the class type supported by this handler.
 boolean isLenient()
          Returns whether the SimpleDateFormat is lenient.
 DateTypeHandler newInstance(Properties properties)
          Creates a customized instance of this type handler.
 Date parse(String text)
          Parses field text into a Java object.
 void setLenient(boolean lenient)
          Sets whether the SimpleDateFormat is lenient.
 void setPattern(String pattern)
          Sets the date pattern used by the SimpleDateFormat.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DateTypeHandler

public DateTypeHandler()
Constructs a new DateTypeHandler.


DateTypeHandler

public DateTypeHandler(String pattern)
Constructs a new DateTypeHandler.

Parameters:
pattern - the SimpleDateFormat pattern
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
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 String format(Object value)
Description copied from interface: TypeHandler
Formats a Java object into field text.

Specified by:
format in interface TypeHandler
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

newInstance

public DateTypeHandler newInstance(Properties properties)
                            throws IllegalArgumentException
Description copied from interface: ConfigurableTypeHandler
Creates a customized instance of this type handler.

Specified by:
newInstance in interface ConfigurableTypeHandler
Parameters:
properties - the properties for customizing the instance
Returns:
the new TypeHandler
Throws:
IllegalArgumentException - if a property value is invalid

createDateFormat

protected DateFormat createDateFormat()
Creates the DateFormat to use to parse and format the field value.

Returns:
the DateFormat for type conversion

createDefaultDateFormat

protected DateFormat createDefaultDateFormat()
Creates a default date format when no pattern is set.

Returns:
the default date format

getType

public Class<?> getType()
Description copied from interface: TypeHandler
Returns the class type supported by this handler. Primitive types should not be returned by this method- use the object equivalent instead.

Specified by:
getType in interface TypeHandler
Returns:
the class type supported by this handler

getPattern

public String getPattern()
Returns the date pattern used by the SimpleDateFormat.

Returns:
the date pattern

setPattern

public void setPattern(String pattern)
                throws IllegalArgumentException
Sets the date pattern used by the SimpleDateFormat.

Parameters:
pattern - the date pattern
Throws:
IllegalArgumentException - if the date pattern is invalid

isLenient

public boolean isLenient()
Returns whether the SimpleDateFormat is lenient.

Returns:
true if lenient, false otherwise

setLenient

public void setLenient(boolean lenient)
Sets whether the SimpleDateFormat is lenient.

Parameters:
lenient - true if lenient, false otherwise

BeanIO 2.0.4

Copyright © 2010-2013 Kevin Seim