public class DateConverter extends AbstractConverter<Date>
Converter
implementation for the
java.util.Date
type.DatePattern
,
DateStyle
,
ConverterFactory.forDate(String)
,
ConverterFactory.forDate(int, int)
Modifier and Type | Field and Description |
---|---|
protected int |
dateStyle
java.text.DateFormat date style. |
static DateConverter |
DEFAULT
DateConverter default instance. |
protected String |
pattern
java.text.SimpleDateFormat date/time pattern. |
protected int |
timeStyle
java.text.DateFormat time style. |
Modifier | Constructor and Description |
---|---|
protected |
DateConverter()
Constructs default
DateConverter . |
protected |
DateConverter(DatePattern annotation)
Constructs a new
DateConverter from the specified
annotation. |
protected |
DateConverter(DateStyle annotation)
Constructs a new
DateConverter from the specified
annotation. |
protected |
DateConverter(int dateStyle,
int timeStyle)
Constructs a new
DateConverter with the specified date and
time styles. |
protected |
DateConverter(String pattern)
Constructs a new
DateConverter with the specified date/time
pattern. |
Modifier and Type | Method and Description |
---|---|
boolean |
appendMessageArguments(ValidationContext<?> context,
Map<String,Object> arguments)
In case of localized conversion appends
pattern argument
that contains localized date/time pattern. |
protected <T> Date |
doDecode(String value,
ValidationContext<T> context)
Converts string representation of date/time into
java.util.Date object. |
protected Date |
doDecodeDefault(String value)
Converts default string representation of date/time into
java.util.Date object. |
protected <T> String |
doEncode(Date value,
ValidationContext<T> context)
Converts
java.util.Date object into string representation. |
protected String |
doEncodeDefault(Date value)
Converts
java.util.Date object into default string
representation. |
protected DateFormat |
getFormat(ValidationContext<?> context)
Returns date/time format for the specified context and this converter
configuration.
|
Class<Date> |
getType()
Returns
java.util.Date type. |
decode, encode
getMessageTemplate
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
getMessageTemplate
public static final DateConverter DEFAULT
DateConverter
default instance.protected final String pattern
java.text.SimpleDateFormat
date/time pattern.protected final int dateStyle
java.text.DateFormat
date style.protected final int timeStyle
java.text.DateFormat
time style.protected DateConverter()
DateConverter
.protected DateConverter(String pattern)
DateConverter
with the specified date/time
pattern.pattern
- java.text.SimpleDateFormat
date/time
pattern.IllegalArgumentException
- if the specified pattern is
null
or invalid.protected DateConverter(DatePattern annotation)
DateConverter
from the specified
annotation.annotation
- Converter annotation.IllegalArgumentException
- if the specified annotation defines
invalid pattern.protected DateConverter(int dateStyle, int timeStyle)
DateConverter
with the specified date and
time styles.dateStyle
- java.text.DateFormat
date style.timeStyle
- java.text.DateFormat
time style.IllegalArgumentException
- if the specified date or time style
is invalid.protected DateConverter(DateStyle annotation)
DateConverter
from the specified
annotation.annotation
- Converter annotation.IllegalArgumentException
- if the specified annotation defines
invalid date/time style.public final Class<Date> getType()
java.util.Date
type.java.util.Date
type.public boolean appendMessageArguments(ValidationContext<?> context, Map<String,Object> arguments)
pattern
argument
that contains localized date/time pattern.appendMessageArguments
in interface Converter<Date>
appendMessageArguments
in interface Validation<Date>
appendMessageArguments
in class AbstractValidation<Date>
context
- Validation context.arguments
- Arguments to be substituted into the error message
template.true
.protected <T> Date doDecode(String value, ValidationContext<T> context)
java.util.Date
object.doDecode
in class AbstractConverter<Date>
T
- The type of validated entity.value
- String representation of date/time.context
- Validation context.java.util.Date
object.MalformedValueException
- if the specified string could not be
parsed as a date/time.protected Date doDecodeDefault(String value)
java.util.Date
object.value
- Default string representation of date/time.java.util.Date
object.IllegalArgumentException
- if the specified string could not be
parsed as a date/time.protected <T> String doEncode(Date value, ValidationContext<T> context)
java.util.Date
object into string representation.doEncode
in class AbstractConverter<Date>
T
- The type of validated entity.value
- java.util.Date
object to be encoded.context
- Validation context.protected String doEncodeDefault(Date value)
java.util.Date
object into default string
representation.value
- java.util.Date
object to be encoded.protected DateFormat getFormat(ValidationContext<?> context)
context
- Validation context.Copyright © 2011–2020 FoxLabs. All rights reserved.