Class DateFieldHandler

    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      (package private) static class  DateFieldHandler.ParseOptions
      A class for controlling the parse options.
    • Constructor Summary

      Constructors 
      Constructor Description
      DateFieldHandler​(FieldHandler fieldHandler)
      Creates a new DateFieldHandler using the given FieldHandler for delegation.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      boolean equals​(java.lang.Object obj)
      Returns true if the given object is an XMLFieldHandler that is equivalent to the delegated handler.
      protected static java.lang.String format​(java.util.Date date)
      Returns the given date in a String format, using the ISO8601 format as specified in the W3C XML Schema 1.0 Recommendation (Part 2: Datatypes) for dateTime.
      java.lang.Object getValue​(java.lang.Object target)
      Returns the value of the field associated with this descriptor from the given target object.
      java.lang.Object newInstance​(java.lang.Object parent)
      Creates a new instance of the object described by this field.
      protected static java.util.Date parse​(java.lang.String dateTime)
      Parses the given string, which must be in the following format: CCYY-MM-DDThh:mm:ss or CCYY-MM-DDThh:mm:ss.sss where "CC" represents the century, "YY" the year, "MM" the month and "DD" the day.
      protected static java.util.Date parse​(java.lang.String dateTime, DateFieldHandler.ParseOptions options)
      Parses the given string, which must be in the following format: CCYY-MM-DDThh:mm:ss or CCYY-MM-DDThh:mm:ss.sss where "CC" represents the century, "YY" the year, "MM" the month and "DD" the day.
      void resetValue​(java.lang.Object target)
      Sets the value of the field to a default value.
      static void setAllowTimeZoneSuppression​(boolean allowTimeZoneSuppression)
      Sets whether or not the time zone should always be displayed when marshaling xsd:dateTime values.
      static void setDefaultTimeZone​(java.util.TimeZone timeZone)
      Sets the default TimeZone used for comparing dates when marshaling xsd:dateTime values using this handler.
      static void setSuppressMillis​(boolean suppressMillis)
      Sets a flag indicating whether or not Milliseconds should be suppressed upon formatting a dateTime as a String.
      void setUseSQLDate​(boolean useSQLDate)
      Specifies that this DateFieldHandler should use java.sql.Date when creating new Date instances.
      void setValue​(java.lang.Object target, java.lang.Object value)
      Sets the value of the field associated with this descriptor.
      • Methods inherited from class java.lang.Object

        clone, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • DateFieldHandler

        public DateFieldHandler​(FieldHandler fieldHandler)
        Creates a new DateFieldHandler using the given FieldHandler for delegation.
        Parameters:
        fieldHandler - the fieldHandler for delegation.
    • Method Detail

      • getValue

        public java.lang.Object getValue​(java.lang.Object target)
        Returns the value of the field associated with this descriptor from the given target object.
        Specified by:
        getValue in interface FieldHandler
        Overrides:
        getValue in class XMLFieldHandler
        Parameters:
        target - the object to get the value from
        Returns:
        the value of the field associated with this descriptor from the given target object.
      • setValue

        public void setValue​(java.lang.Object target,
                             java.lang.Object value)
                      throws java.lang.IllegalStateException
        Sets the value of the field associated with this descriptor.
        Specified by:
        setValue in interface FieldHandler
        Overrides:
        setValue in class XMLFieldHandler
        Parameters:
        target - the object in which to set the value
        value - the value of the field
        Throws:
        java.lang.IllegalStateException - if the value provided cannot be parsed into a legal date/time.
      • resetValue

        public void resetValue​(java.lang.Object target)
                        throws java.lang.IllegalStateException
        Sets the value of the field to a default value.
        Specified by:
        resetValue in interface FieldHandler
        Overrides:
        resetValue in class XMLFieldHandler
        Parameters:
        target - The object
        Throws:
        java.lang.IllegalStateException - The Java object has changed and is no longer supported by this handler, or the handler is not compatiable with the Java object
      • newInstance

        public java.lang.Object newInstance​(java.lang.Object parent)
                                     throws java.lang.IllegalStateException
        Creates a new instance of the object described by this field.
        Specified by:
        newInstance in interface FieldHandler
        Overrides:
        newInstance in class XMLFieldHandler
        Parameters:
        parent - The object for which the field is created
        Returns:
        A new instance of the field's value
        Throws:
        java.lang.IllegalStateException - This field is a simple type and cannot be instantiated
      • equals

        public boolean equals​(java.lang.Object obj)
        Returns true if the given object is an XMLFieldHandler that is equivalent to the delegated handler. An equivalent XMLFieldHandler is an XMLFieldHandler that is an instances of the same class.
        Overrides:
        equals in class XMLFieldHandler
        Parameters:
        obj - The object to compare against this
        Returns:
        true if the given object is an XMLFieldHandler that is equivalent to this one.
      • setAllowTimeZoneSuppression

        public static void setAllowTimeZoneSuppression​(boolean allowTimeZoneSuppression)
        Sets whether or not the time zone should always be displayed when marshaling xsd:dateTime values. If true, then the time zone will not be displayed if the time zone is the current local time zone.
        Parameters:
        allowTimeZoneSuppression - if true, the time zone will not be displayed if it is the current local time zone.
      • setDefaultTimeZone

        public static void setDefaultTimeZone​(java.util.TimeZone timeZone)
        Sets the default TimeZone used for comparing dates when marshaling xsd:dateTime values using this handler. This is used when determining if the timezone can be omitted when marshaling. Default is JVM default returned by TimeZone.getDefault()
        Parameters:
        timeZone - TimeZone to use instead of JVM default
        See Also:
        setAllowTimeZoneSuppression(boolean)
      • setSuppressMillis

        public static void setSuppressMillis​(boolean suppressMillis)
        Sets a flag indicating whether or not Milliseconds should be suppressed upon formatting a dateTime as a String.
        Parameters:
        suppressMillis - a boolean when true indicates that millis should be suppressed during conversion of a dateTime to a String
      • setUseSQLDate

        public void setUseSQLDate​(boolean useSQLDate)
        Specifies that this DateFieldHandler should use java.sql.Date when creating new Date instances.
        Parameters:
        useSQLDate - a boolean that when true indicates that java.sql.Date should be used instead of java.util.Date.
      • parse

        protected static java.util.Date parse​(java.lang.String dateTime)
                                       throws java.text.ParseException
        Parses the given string, which must be in the following format: CCYY-MM-DDThh:mm:ss or CCYY-MM-DDThh:mm:ss.sss where "CC" represents the century, "YY" the year, "MM" the month and "DD" the day. The letter "T" is the date/time separator and "hh", "mm", "ss" represent hour, minute and second respectively.

        CCYY represents the Year and each 'C' and 'Y' must be a digit from 0-9. A minimum of 4 digits must be present.

        MM represents the month and each 'M' must be a digit from 0-9, but together "MM" must not represent a value greater than 12. "MM" must be 2 digits, use of leading zero is required for all values less than 10.

        DD represents the day of the month and each 'D' must be a digit from 0-9. DD must be 2 digits (use a leading zero if necessary) and must not be greater than 31.

        'T' is the date/time separator and must exist!

        hh represents the hour using 0-23. mm represents the minute using 0-59. ss represents the second using 0-60. (60 for leap second) sss represents the millisecond using 0-999.

        Parameters:
        dateTime - the string to convert to a Date
        Returns:
        a new Date that represents the given string.
        Throws:
        java.text.ParseException - when the given string does not conform to the above string.
      • parse

        protected static java.util.Date parse​(java.lang.String dateTime,
                                              DateFieldHandler.ParseOptions options)
                                       throws java.text.ParseException
        Parses the given string, which must be in the following format: CCYY-MM-DDThh:mm:ss or CCYY-MM-DDThh:mm:ss.sss where "CC" represents the century, "YY" the year, "MM" the month and "DD" the day. The letter "T" is the date/time separator and "hh", "mm", "ss" represent hour, minute and second respectively.

        CCYY represents the Year and each 'C' and 'Y' must be a digit from 0-9. A minimum of 4 digits must be present.

        MM represents the month and each 'M' must be a digit from 0-9, but together "MM" must not represent a value greater than 12. "MM" must be 2 digits, use of leading zero is required for all values less than 10.

        DD represents the day of the month and each 'D' must be a digit from 0-9. DD must be 2 digits (use a leading zero if necessary) and must not be greater than 31.

        'T' is the date/time separator and must exist!

        hh represents the hour using 0-23. mm represents the minute using 0-59. ss represents the second using 0-60. (60 for leap second) sss represents the millisecond using 0-999.

        Parameters:
        dateTime - the string to convert to a Date
        options - the parsing options to use
        Returns:
        a new Date that represents the given string.
        Throws:
        java.text.ParseException - when the given string does not conform to the above string.
      • format

        protected static java.lang.String format​(java.util.Date date)
        Returns the given date in a String format, using the ISO8601 format as specified in the W3C XML Schema 1.0 Recommendation (Part 2: Datatypes) for dateTime.
        Parameters:
        date - the Date to format
        Returns:
        the formatted string