You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@xmlbeans.apache.org by Dennis Sherman <De...@exlibrisgroup.com> on 2008/04/04 22:30:49 UTC

Date format manipulations

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
Dennis.Sherman@exlibrisgroup.com
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: user-unsubscribe@xmlbeans.apache.org
For additional commands, e-mail: user-help@xmlbeans.apache.org


RE: Date format manipulations

Posted by Dennis Sherman <De...@exlibrisgroup.com>.
Thanks for the suggestion, Radu.  I've gotten in such a rut using
*.Factory.newInstance(...) that I'd overlooked the
*.Factory.newValue(...) option, which is a bit better than what I had
done.

I thought I understood why I was having the issue (java Calendar mapping
to both types in the union, xmlbeans using the first that matches), but
its good to have it confirmed.  

--
Dennis R. Sherman
Ex Libris Group
847-227-2976
Dennis.Sherman@exlibrisgroup.com
http://www.exlibrisgroup.com 


 

> -----Original Message-----
> From: Radu Preotiuc-Pietro [mailto:radup@bea.com] 
> Sent: Friday, April 18, 2008 6:23 PM
> To: user@xmlbeans.apache.org
> Subject: Re: Date format manipulations
> 
> 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
> > Dennis.Sherman@exlibrisgroup.com
> > 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: user-unsubscribe@xmlbeans.apache.org
> > For additional commands, e-mail: user-help@xmlbeans.apache.org
> > 
> > 
> > 
> 
> 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: user-unsubscribe@xmlbeans.apache.org
> For additional commands, e-mail: user-help@xmlbeans.apache.org
> 

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@xmlbeans.apache.org
For additional commands, e-mail: user-help@xmlbeans.apache.org


Re: Date format manipulations

Posted by Radu Preotiuc-Pietro <ra...@bea.com>.
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
> Dennis.Sherman@exlibrisgroup.com
> 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: user-unsubscribe@xmlbeans.apache.org
> For additional commands, e-mail: user-help@xmlbeans.apache.org
> 
> 
> 

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: user-unsubscribe@xmlbeans.apache.org
For additional commands, e-mail: user-help@xmlbeans.apache.org