I have the followind definition in my xsd file
<xsd:schema xmlns:xsd="
http://www.w3.org/2001/XMLSchema"
xmlns:jxb="
http://java.sun.com/xml/ns/jaxb"
jxb:version="1.0">
<xsd:simpleType name="Date_CCYYMMDD">
<xsd:annotation>
<xsd:appinfo>
<jxb:javaType name="java.util.Calendar"
parseMethod="XMLDataConvertor.parseDateToCalendar"
printMethod="XMLDataConvertor.parseCalendarToDate" />
</xsd:appinfo>
</xsd:annotation>
<xsd:restriction base="xsd:date">
</xsd:restriction>
</xsd:simpleType>
The two methods to convert are also defined...
public static java.util.Calendar parseDateToCalendar(String inDate)
throws ParseException {
SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
sdf.setLenient(false);
Date dt = sdf.parse(inDate);
Calendar cal = Calendar.getInstance();
cal.setTime(dt);
return cal;
}
public static String parseCalendarToDate(Calendar inCalendar) {
SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
sdf.setLenient(false);
Date dt = inCalendar.getTime();
String outDate = sdf.format(dt);
return outDate;
}
I have set Validation to true during unmarshalling and have my own event
handler to catch events
//Set the validation to true
_unMarshaller.setValidating(true);
When I have a date in the format yyyyyMMDD, the event handler gets an event
that the date does not fit in the format (CCYY-MM-DD, the default)..
Looks like the conversion is first attempted with the default format and
then with my conversion methods...
Am I doing something wrong here ? Why would the Event Handler be invoked
for when the data is valid when it goes though my implementation of the
DataConverter ? Also If I turn the validtion during unmarshalling to false,
it works...
All I am trying to do here is to accept dates in YYYYYMMDD (without the
'-'s) Is there any other easier way to accept date in different format ?
Thanks,
Sriram