XStream vs XMLGregorianCalendar

B

bw

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.datatype.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>?
 
A

Arne Vajhøj

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.datatype.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
 
L

Lew

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.datatype.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/docs/api/javax/xml/datatype/XMLGregorianCalendar.html

--
Lew
Ceci n'est pas une fenêtre.
..___________.
|###] | [###|
|##/ | *\##|
|#/ * | \#|
|#----|----#|
|| | * ||
|o | o|
|_____|_____|
|===========|
 
L

Lew

Lew said:
(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|
|_____|_____|
|===========|
 
T

Tom Anderson

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
 
L

Lew

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|
|_____|_____|
|===========|
 
L

Lew

Tom said:

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...atype/XMLGregorianCalendar.html#toXMLFormat()

--
Lew
Ceci n'est pas une fenêtre.
..___________.
|###] | [###|
|##/ | *\##|
|#/ * | \#|
|#----|----#|
|| | * ||
|o * | o|
|_____|_____|
|===========|
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,048
Latest member
verona

Latest Threads

Top