In answer to your question, you can try
something like the following for converting your date to one of the types you
specify.
XmlDate d =
XmlDate.Factory.newInstance();
d.setCalendarValue(Calendar.getInstance());
From: Vineeth Varghese
[mailto:vineeth.varghese@xxxxxxxxxx]
Sent: Friday, January 28, 2005
5:19 AM
To: user@xxxxxxxxxxxxxxxxxxx
Subject: Time component lost from
Date
Hi,
We have type definitions in our schema like :-
-------------Basic Type Definition----------------------------
<xs:simpleType name="Date">
<xs:restriction base="xs:date">
<xs:pattern value="\d\d\d\d-\d\d-\d\d"/>
</xs:restriction>
</xs:simpleType>
<xs:simpleType name="DateTime">
<xs:restriction base="xs:dateTime">
<xs:pattern
value="\d\d\d\d-\d\d-\d\dT\d\d:\d\d:\d\d(Z|(\+|-)\d\d:\d\d)"/>
</xs:restriction>
</xs:simpleType>
<xs:simpleType name="DateTimeAny">
<xs:union memberTypes="Date DateTime"/>
</xs:simpleType>
------------BOD element definition-----------------------------
<xs:element name="CallBackDate" type="DateTimeAny"
minOccurs="0"/>
---------------------------------------------------------------
The getter for this element returns a Calendar Object. Things
are fine as long as a Date value is set but if we want the time component and
expect a DateTime, the time component seem to be lost from the Calendar's
toString() value.
By the current definition of DateTimeAny, Calendar object
will use the format of the first element in the union member
type list of DateTimeAny
which is Date in
this case so I am getting a Date string. If I change the type definition
to :-
<xs:simpleType name="DateTimeAny">
<xs:union memberTypes="DateTime Date"/>
</xs:simpleType>
Calendar object picks the format of DateTime and returns
timestamp string with the time.
So my question is, does XMLBean have any feature by which
instead of a Calendar Object from the bean getter I get an object which I
can type cast appropriately to org.apache.xmlbeans.XMLDate or
org.apache.xmlbeans.XMLDateTime. The actual type can depend on the availabilty
of the time component. Is this possible in XMLBean right now?
Thanks,
Vineeth.