There is a slightly simpler/cleaner way:
Calendar datestamp = Calendar.getInstance();
datestamp.setTimeZone(TimeZone.getTimeZone("UTC"));
UTCdateTimeZType dtmz =
UTCdateTimeZType.Factory.newValue(datestamp);
UTCdatetimeType utcdtm =
UTCdatetimeType.Factory.newValue(dtmz);
hdr.xsetDatestamp(utcdtm);
But the main reason you have to work hard is that the same Java type
(Calendar) corresponds to both union members. So if you had say a union
of int and string and did hdr.setValue("string") then it would be
obvious which of the union members "matches" but in your case it's not,
because Calendar is the Java class for both "date" and "dateTime".
XMLBeans in this case picks the first union type that matches. If you
wanted the first union member, then doing
Calendar datestamp = Calendar.getInstance();
datestamp.setTimeZone(TimeZone.getTimeZone("UTC"));
hdr.setDatestamp(datestamp);
would produce the result you wanted. But you want the second union
member, so you have to use xsetDatestamp() and a specific type to convey
this information.
Hope this makes sense,
Radu
On Fri, 2008-04-04 at 13:30 -0700, Dennis Sherman wrote:
> Hi, all.
>
> I think I'm working too hard to get the end result I'm looking for.
> Is
> there a better way?
>
> Background: I'm working with a schema available at
> http://www.openarchives.org/OAI/2.0/OAI-PMH.xsd. The fragment in
> question is this:
>
> <simpleType name="UTCdatetimeType">
> <annotation>
> <documentation>Datestamps are to either day (type date)
> or to seconds granularity (type
> oai:UTCdateTimeZType)</documentation>
> </annotation>
> <union memberTypes="date oai:UTCdateTimeZType"/>
> </simpleType>
>
> <simpleType name="UTCdateTimeZType">
> <restriction base="dateTime">
> <pattern value=".*Z"/>
> </restriction>
> </simpleType>
>
> My task is to produce an XML document compliant with the schema. I
> need
> the datetime defined as UTCdatetimeType to be in UTC format, e.g.
> ...
> <header>
> <identifier>host:repository:1</identifier>
> <datestamp>2008-04-04T20:16:33.068Z</datestamp>
> </header>
> ...
>
> I'm doing it, but it feels like too much work to do it like this:
>
> Calendar datestamp = Calendar.getInstance();
> datestamp.setTimeZone(TimeZone.getTimeZone("UTC"));
> UTCdateTimeZType dtmz =
> UTCdateTimeZType.Factory.newInstance();
> dtmz.setCalendarValue(datestamp);
> UTCdatetimeType utcdtm = (UTCdatetimeType)
> dtmz.changeType(UTCdatetimeType.type);
> hdr.xsetDatestamp(utcdtm);
>
> Is there a simpler, more straightforward way that I'm just not
> finding?
>
> Thanks.
>
> --
> Dennis R. Sherman
> Ex Libris Group
> 847-227-2976
> [EMAIL PROTECTED]
> http://www.exlibrisgroup.com
>
>
>
> --
> This message has been scanned for viruses and
> dangerous content by MailScanner, and is
> believed to be clean.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>
>
Notice: This email message, together with any attachments, may contain
information of BEA Systems, Inc., its subsidiaries and affiliated
entities, that may be confidential, proprietary, copyrighted and/or legally
privileged, and is intended solely for the use of the individual or entity
named in this message. If you are not the intended recipient, and have received
this message in error, please immediately return this by email and then delete
it.
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]