org.quartz.xml
public final class: JobSchedulingDataProcessor.DateConverter [javadoc |
source]
java.lang.Object
org.quartz.xml.JobSchedulingDataProcessor$DateConverter
All Implemented Interfaces:
org.apache.commons.beanutils.Converter
Standard Converter implementation that converts an incoming
String into a java.util.Date object, optionally using a
default value or throwing a ConversionException if a conversion
error occurs.
| Method from org.quartz.xml.JobSchedulingDataProcessor$DateConverter Summary: |
|---|
|
convert, parseDate |
| Method from org.quartz.xml.JobSchedulingDataProcessor$DateConverter Detail: |
public Object convert(Class type,
Object value) {
// --------------------------------------------------------- Public Methods
if (value == null) {
if (useDefault) {
return (defaultValue);
} else {
return (null);
}
}
if (String.class.equals(type)) {
if ((value instanceof Date) && (dateFormats != null)) {
return (dateFormats[0].format((Date) value));
} else {
return (value.toString());
}
}
if (value instanceof Date) {
return (value);
}
try {
if (Date.class.isAssignableFrom(type) && dateFormats != null) {
return parseDate(value);
} else {
return (value.toString());
}
} catch (Exception e) {
if (useDefault) {
return (defaultValue);
} else {
throw new ConversionException(e);
}
}
}
Convert the specified input object into an output object of the
specified type. |
protected Date parseDate(Object value) throws ParseException {
Date date = null;
int len = dateFormats.length;
for (int i = 0; i < len; i++) {
try {
date = (dateFormats[i].parse(value.toString()));
break;
} catch (ParseException e) {
// if this is the last format, throw the exception
if (i == (len - 1)) {
throw e;
}
}
}
return date;
}
|