Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > XStream vs XMLGregorianCalendar

Reply
Thread Tools

XStream vs XMLGregorianCalendar

 
 
bw
Guest
Posts: n/a
 
      01-30-2011
Friends tell me the way out!

There xsd-diagram, with the help of her made JAXB java-class.
The class is filled with data, among other things, there are element
dateTo of the type javax.xml.datatype.XMLGregorianCalendar.
After this class does XStream XML, I get description of this item:
<dateTo
class="com.sun.org.apache.xerces.internal.jaxp.dat atype.XMLGregorianCalendarImpl">
<year>2011</year>
<month>1</month>
<day>30</day>
<timezone>180</timezone>
<hour>12</hour>
<minute>13</minute>
<second>34</second>
<fractionalSecond>0.315</fractionalSecond>
</ dateTo>

I do not like such a description, tell me, you can use XStream to get
out of the XML this form:
<dateTo>2011-01-30T09:13:34.356 Z</dateTo>?
 
Reply With Quote
 
 
 
 
Arne Vajhűj
Guest
Posts: n/a
 
      01-30-2011
On 30-01-2011 04:18, bw wrote:
> There xsd-diagram, with the help of her made JAXB java-class.
> The class is filled with data, among other things, there are element
> dateTo of the type javax.xml.datatype.XMLGregorianCalendar.
> After this class does XStream XML, I get description of this item:
> <dateTo
> class="com.sun.org.apache.xerces.internal.jaxp.dat atype.XMLGregorianCalendarImpl">
> <year>2011</year>
> <month>1</month>
> <day>30</day>
> <timezone>180</timezone>
> <hour>12</hour>
> <minute>13</minute>
> <second>34</second>
> <fractionalSecond>0.315</fractionalSecond>
> </ dateTo>
>
> I do not like such a description, tell me, you can use XStream to get
> out of the XML this form:
> <dateTo>2011-01-30T09:13:34.356 Z</dateTo>?


Are you using JAXB or XStream?

Arne
 
Reply With Quote
 
 
 
 
Lew
Guest
Posts: n/a
 
      01-30-2011
On 01/30/2011 04:18 AM, bw wrote:
> Friends tell me the way out!
>
> There xsd-diagram, with the help of her made JAXB java-class.
> The class is filled with data, among other things, there are element
> dateTo of the type javax.xml.datatype.XMLGregorianCalendar.
> After this class does XStream XML, I get description of this item:
> <dateTo
> class="com.sun.org.apache.xerces.internal.jaxp.dat atype.XMLGregorianCalendarImpl">
> <year>2011</year>
> <month>1</month>
> <day>30</day>
> <timezone>180</timezone>
> <hour>12</hour>
> <minute>13</minute>
> <second>34</second>
> <fractionalSecond>0.315</fractionalSecond>
> </ dateTo>
>
> I do not like such a description, tell me, you can use XStream to get
> out of the XML this form:
> <dateTo>2011-01-30T09:13:34.356 Z</dateTo>?


I am certain one can, but why would you want to?

What is it that you do not like about the standard JAXB output, exactly?

I assume the "XStream" to which you refer is http://xstream.codehaus.org/, yes?

Some folks might prefer a solution without a third-party library dependency.

The main advantage of JAXB is that it handles the boilerplate mechanics of XML
translation for you. It also has the advantage of coming standard with the JDK.

It isn't perfect, but it's awfully good.

There are a couple of strategies to integrate JAXB-generated classes with your
code. Broadly, it's adapt or modify, that is, write cover classes to use the
schema classes, or directly modify the generated code. The work for schema
changes is roughly the same either way, but the adapter strategy is somewhat
more potent for deployment and enhancement.

(Another question is whether to version-control the generated .java files or
depend on the build to create them each time. A schema and its associated
JAXB classes make a nice JAR.) [1]

Either way, you have to integrate the schema classes with your domain model.
Domain objects can have muncher methods for schema graphs, or you can have
translation layer - perhaps that very adapter layer aforementioned - that
understands the schemas on one side and the domain on the other.

In the case of 'XMLGregorianCalendar', the Java language's official API
thoughtfully defines the 'toGregorianCalendar()' and various 'setX()' methods
that will help that effort. Overall that effort should not exceed that of
coding it using XStream's API, not accounting for JAXB's labor savings from
the translation to 'XMLGregorianCalendar' in the first place. Factor in the
schema-aware methods like 'XMLGregorianCalendar#toXMLFormat()', 'compare()',
and 'getXMLSchemaType()', and the JAXB type is a winner hands-down.

http://download.oracle.com/javase/6/...nCalendar.html

--
Lew
Ceci n'est pas une fenĂȘtre.
..___________.
|###] | [###|
|##/ | *\##|
|#/ * | \#|
|#----|----#|
|| | * ||
|o | o|
|_____|_____|
|===========|
 
Reply With Quote
 
Lew
Guest
Posts: n/a
 
      01-30-2011
Lew wrote:
> (Another question is whether to version-control the generated .java files or
> depend on the build to create them each time. A schema and its associated JAXB
> classes make a nice JAR.) [1]


[1] Too often, we programmers disregard deployment and operations issues.
It's a good exercise to figure out where to put your JAXB stuff in your
version-control repository, write and run the build scripts (Ant, for example)
that work off a clean export from that repository, accounting for code used on
both ends of the exchange. Then deploy that yourself on two instances - one
for each end - of whatever the target environments are (desktop app,
smartphone app, Java EE app, ...). Integrate that with a
continuous-integration platform like Hudson. For extra credit, put the
database on a different host.

That exercise tends to make you a fan of framework reduction - too many
programmers take all the latest Springs and Ajax of outrageous configuration
without regard for architecture, emergent interactions or transitive version
dependencies. One outcome is to undo all the type safety of the Java
language, substituting instead a mish-mosh of references by name whose
incompatibilities come forward only at runtime.

Injection has its place, but most of the time, what's wrong with just calling
a durn method?

--
Lew
Ceci n'est pas une fenĂȘtre.
..___________.
|###] | [###|
|##/ | *\##|
|#/ * | \#|
|#----|----#|
|| | * ||
|o * | o|
|_____|_____|
|===========|
 
Reply With Quote
 
Tom Anderson
Guest
Posts: n/a
 
      01-30-2011
On Sun, 30 Jan 2011, Lew wrote:

> Domain objects can have muncher methods for schema graphs


Is 'muncher method' a term with currency, or are you neologising? Either
way, what does it mean?

tom

--
Basically, at any given time, most people in the world are wasting time.
 
Reply With Quote
 
Tom Anderson
Guest
Posts: n/a
 
      01-30-2011
On Sun, 30 Jan 2011, bw wrote:

> I do not like such a description, tell me, you can use XStream to get
> out of the XML this form:
> <dateTo>2011-01-30T09:13:34.356 Z</dateTo>?


http://xstream.codehaus.org/converter-tutorial.html
http://download.oracle.com/javase/1....l#toXMLFormat()

tom

--
Basically, at any given time, most people in the world are wasting time.
 
Reply With Quote
 
Lew
Guest
Posts: n/a
 
      01-31-2011
On 01/30/2011 05:28 PM, Tom Anderson wrote:
> On Sun, 30 Jan 2011, Lew wrote:
>
>> Domain objects can have muncher methods for schema graphs

>
> Is 'muncher method' a term with currency, or are you neologising? Either way,
> what does it mean?


It's a method that take schema graphs as arguments. It "munches" a schema and
digests it into domain objects. No, it's not current - but it will be now!

--
Lew
Ceci n'est pas une fenĂȘtre.
..___________.
|###] | [###|
|##/ | *\##|
|#/ * | \#|
|#----|----#|
|| | * ||
|o * | o|
|_____|_____|
|===========|
 
Reply With Quote
 
Lew
Guest
Posts: n/a
 
      01-31-2011
bw wrote:
>> I do not like such a description, tell me, you can use XStream to get
>> out of the XML this form:
>> <dateTo>2011-01-30T09:13:34.356 Z</dateTo>?


Tom Anderson wrote:
> http://xstream.codehaus.org/converter-tutorial.html
> http://download.oracle.com/javase/1....l#toXMLFormat()


Absent a specific reason to do otherwise, it is best to avoid sending people
to the API docs for an obsolete version of Java.

http://download.oracle.com/javase/6/...l#toXMLFormat()

--
Lew
Ceci n'est pas une fenĂȘtre.
..___________.
|###] | [###|
|##/ | *\##|
|#/ * | \#|
|#----|----#|
|| | * ||
|o * | o|
|_____|_____|
|===========|
 
Reply With Quote
 
Tom Anderson
Guest
Posts: n/a
 
      01-31-2011
On Sun, 30 Jan 2011, Lew wrote:

> bw wrote:
>>> I do not like such a description, tell me, you can use XStream to get
>>> out of the XML this form:
>>> <dateTo>2011-01-30T09:13:34.356 Z</dateTo>?

>
> Tom Anderson wrote:
>> http://xstream.codehaus.org/converter-tutorial.html
>> http://download.oracle.com/javase/1....l#toXMLFormat()

>
> Absent a specific reason to do otherwise, it is best to avoid sending people
> to the API docs for an obsolete version of Java.
>
> http://download.oracle.com/javase/6/...l#toXMLFormat()


Whoops! Too many tabs, not enough attention paid. Thanks for the
correction.

tom

--
Remember when we said there was no future? Well, this is it.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Using XStream to write out/read in XML memory issues k3n85 Java 0 07-15-2009 07:16 PM
Using XStream to write out/read in XML memory issues k3n85 XML 0 07-15-2009 07:15 PM
Convert JAXB XMLGregorianCalendar to java.sql.Date puneet.maini@gmail.com Java 1 04-16-2009 04:10 PM
XStream: streaming XML transformations Alain Frisch XML 0 06-28-2006 04:18 PM
Lightyear XSTREAM VoIP digital phone service mukes@mail.com Computer Support 0 09-19-2004 12:51 AM



Advertisments