Package io.guise.framework.converter
Class AbstractDateStringLiteralConverter<V>
- java.lang.Object
-
- com.globalmentor.beans.BoundPropertyObject
-
- io.guise.framework.event.GuiseBoundPropertyObject
-
- io.guise.framework.converter.AbstractConverter<V,java.lang.String>
-
- io.guise.framework.converter.AbstractDateStringLiteralConverter<V>
-
- Type Parameters:
V
- The value type this converter supports.
- All Implemented Interfaces:
com.globalmentor.beans.PropertyBindable
,com.globalmentor.beans.PropertyConstrainable
,Converter<V,java.lang.String>
- Direct Known Subclasses:
CalendarStringLiteralConverter
,DateStringLiteralConverter
public abstract class AbstractDateStringLiteralConverter<V> extends AbstractConverter<V,java.lang.String>
An object that can convert a date object from and to a string. This implementation caches a date format and only creates a new one if the locale has changed. This implementation synchronizes all conversions on theDateFormat
object. This implementation ensures that all date formats use the "yyyy" rather than "yy" year format if possible.- Author:
- Garret Wilson
-
-
Field Summary
-
Fields inherited from class com.globalmentor.beans.BoundPropertyObject
NO_PROPERTY_CHANGE_LISTENERS, NO_VETOABLE_CHANGE_LISTENERS
-
Fields inherited from interface io.guise.framework.converter.Converter
INVALID_VALUE_MESSAGE_PROPERTY
-
-
Constructor Summary
Constructors Constructor Description AbstractDateStringLiteralConverter(DateStringLiteralStyle dateStyle, TimeStringLiteralStyle timeStyle)
Date style and time style constructor.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected java.util.Date
convertDateLiteral(java.lang.String literal)
Converts a literal representation of a value from the lexical space into a date value in the date value space.protected java.lang.String
convertDateValue(java.util.Date value)
Converts a value from a date value space to a literal value in the lexical space.static java.text.DateFormat
createDateFormat(DateStringLiteralStyle dateStyle, TimeStringLiteralStyle timeStyle, java.util.Locale locale, java.util.TimeZone timeZone)
Creates a new date format object for the indicated styles and locale.protected java.text.DateFormat
getDateFormat()
Determines a date format object appropriate for the session's current locale and time zone.DateStringLiteralStyle
getDateStyle()
TimeStringLiteralStyle
getTimeStyle()
-
Methods inherited from class io.guise.framework.converter.AbstractConverter
getInvalidValueMessage, isEquivalent, isValidLiteral, setInvalidValueMessage
-
Methods inherited from class io.guise.framework.event.GuiseBoundPropertyObject
getSession
-
Methods inherited from class com.globalmentor.beans.BoundPropertyObject
addPropertyChangeListener, addPropertyChangeListener, addVetoableChangeListener, addVetoableChangeListener, createPostponedPropertyChangeEvent, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, fireVetoableChange, fireVetoableChange, fireVetoableChange, getForwardPropertyChangeListener, getPropertyChangeListeners, getPropertyChangeListeners, getPropertyChangeSupport, getRepeatPropertyChangeListener, getRepeatVetoableChangeListener, getVetoableChangeListeners, getVetoableChangeListeners, getVetoableChangeSupport, hasPropertyChangeListeners, hasVetoableChangeListeners, removePropertyChangeListener, removePropertyChangeListener, removeVetoableChangeListener, removeVetoableChangeListener
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface io.guise.framework.converter.Converter
convertLiteral, convertValue, getSession
-
-
-
-
Constructor Detail
-
AbstractDateStringLiteralConverter
public AbstractDateStringLiteralConverter(DateStringLiteralStyle dateStyle, TimeStringLiteralStyle timeStyle)
Date style and time style constructor.- Parameters:
dateStyle
- The date representation style, ornull
if the date should not be represented.timeStyle
- The time representation style, ornull
if the time should not be represented.- Throws:
java.lang.NullPointerException
- if both the given date style and time style arenull
.
-
-
Method Detail
-
getDateStyle
public DateStringLiteralStyle getDateStyle()
- Returns:
- The date representation style, or
null
if the date should not be represented.
-
getTimeStyle
public TimeStringLiteralStyle getTimeStyle()
- Returns:
- The time representation style, or
null
if the time should not be represented.
-
getDateFormat
protected java.text.DateFormat getDateFormat()
Determines a date format object appropriate for the session's current locale and time zone.- Returns:
- A date format object appropriate for the session's current locale.
- See Also:
GuiseSession.getLocale()
,GuiseSession.getTimeZone()
-
createDateFormat
public static java.text.DateFormat createDateFormat(DateStringLiteralStyle dateStyle, TimeStringLiteralStyle timeStyle, java.util.Locale locale, java.util.TimeZone timeZone)
Creates a new date format object for the indicated styles and locale. This implementation does not allow both date and time styles to be specified if one of the styles specifies other than short/medium/long/full format.- Parameters:
dateStyle
- The date representation style, ornull
if the date should not be represented.timeStyle
- The date representation style, ornull
if the date should not be represented.locale
- The locale for which a date format should be created.timeZone
- The time zone for which a date format should be created.- Returns:
- A date format object appropriate for the given locale.
- Throws:
java.lang.NullPointerException
- if the both the date style and time style isnull
, or if the locale and/or time zone isnull
.java.lang.IllegalArgumentException
- if both date style and time style is given and one of the styles specifies other than short/medium/long/full format.
-
convertDateValue
protected java.lang.String convertDateValue(java.util.Date value) throws ConversionException
Converts a value from a date value space to a literal value in the lexical space. This implementation converts the value using the date format object. This implementation synchronizes on theDateFormat
instance.- Parameters:
value
- The value in the value space to convert.- Returns:
- The converted value in the lexical space, or
null
if the given literal isnull
.. - Throws:
ConversionException
- if the value cannot be converted.- See Also:
getDateFormat()
-
convertDateLiteral
protected java.util.Date convertDateLiteral(java.lang.String literal) throws ConversionException
Converts a literal representation of a value from the lexical space into a date value in the date value space. This implementation converts the empty string to anull
value.- Parameters:
literal
- The literal value in the lexical space to convert.- Returns:
- The converted value in the value space, or
null
if the given literal isnull
. - Throws:
ConversionException
- if the literal value cannot be converted.
-
-