Class DateTypeHandlerSupport

  • All Implemented Interfaces:
    java.lang.Cloneable, ConfigurableTypeHandler, TypeHandler
    Direct Known Subclasses:
    CalendarTypeHandler, DateTypeHandler

    public abstract class DateTypeHandlerSupport
    extends LocaleSupport
    implements ConfigurableTypeHandler, java.lang.Cloneable
    This abstract 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:
    2.1.0
    See Also:
    Date, DateFormat, SimpleDateFormat
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      protected java.text.DateFormat createDateFormat()
      Creates the DateFormat to use to parse and format the field value.
      protected java.text.DateFormat createDefaultDateFormat()
      Creates a default date format when no pattern is set.
      protected java.lang.String formatDate​(java.util.Date date)
      Converts a Date to text.
      java.lang.String getPattern()
      Returns the date pattern used by the SimpleDateFormat.
      java.util.TimeZone getTimeZone()
      Returns the configured TimeZone or null if not set.
      java.lang.String getTimeZoneId()
      Returns the time zone used to interpret dates, or null if the default time zone will be used.
      boolean isLenient()
      Returns whether the SimpleDateFormat is lenient.
      DateTypeHandlerSupport newInstance​(java.util.Properties properties)
      Creates a customized instance of this type handler.
      protected java.util.Date parseDate​(java.lang.String text)
      Parses text into a Date.
      void setLenient​(boolean lenient)
      Sets whether the SimpleDateFormat is lenient.
      void setPattern​(java.lang.String pattern)
      Sets the date pattern used by the SimpleDateFormat.
      void setTimeZoneId​(java.lang.String name)
      Sets the time zone for interpreting dates.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • pattern

        protected java.lang.String pattern
      • lenient

        protected boolean lenient
      • timeZone

        protected java.util.TimeZone timeZone
    • Constructor Detail

      • DateTypeHandlerSupport

        public DateTypeHandlerSupport()
        Constructs a new AbstractDateTypeHandler.
      • DateTypeHandlerSupport

        public DateTypeHandlerSupport​(java.lang.String pattern)
        Constructs a new AbstractDateTypeHandler.
        Parameters:
        pattern - the SimpleDateFormat pattern
    • Method Detail

      • formatDate

        protected java.lang.String formatDate​(java.util.Date date)
        Converts a Date to text.
        Parameters:
        date - the Date to convert
        Returns:
        the formatted text
      • createDateFormat

        protected java.text.DateFormat createDateFormat()
        Creates the DateFormat to use to parse and format the field value.
        Returns:
        the DateFormat for type conversion
      • createDefaultDateFormat

        protected java.text.DateFormat createDefaultDateFormat()
        Creates a default date format when no pattern is set.
        Returns:
        the default date format
      • newInstance

        public DateTypeHandlerSupport newInstance​(java.util.Properties properties)
                                           throws java.lang.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:
        java.lang.IllegalArgumentException - if a property value is invalid
      • getPattern

        public java.lang.String getPattern()
        Returns the date pattern used by the SimpleDateFormat.
        Returns:
        the date pattern
      • setPattern

        public void setPattern​(java.lang.String pattern)
                        throws java.lang.IllegalArgumentException
        Sets the date pattern used by the SimpleDateFormat.
        Parameters:
        pattern - the date pattern
        Throws:
        java.lang.IllegalArgumentException - if the date pattern is invalid
      • setTimeZoneId

        public void setTimeZoneId​(java.lang.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 java.lang.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
      • getTimeZone

        public java.util.TimeZone getTimeZone()
        Returns the configured TimeZone or null if not set.
        Returns:
        the TimeZone
      • 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