users@jaxb.java.net

Re: JAXB 2.0 union

From: Joe Fialli <Joseph.Fialli_at_Sun.COM>
Date: Tue, 19 Jul 2005 15:05:37 -0400

Scott Allan wrote:

>Thank you for the quick response. Just to make sure I understand what
>you are saying, all unions will be treated as a string and I would use
>something like this:
>
>
>
>myObject.setMyField(mySqlDate.toString());
>
>
As long as the toString() for sql data outputs a date format that is
compatible with
XML Schema xs:date format. I have no idea if it is or not. JAXB provides
javax.xml.bind.DatatypeConverter.parseDate()/printDate to assist in
converting between
traditional Java datatypes and XML Schema builtin datatypes.

>mySqlDate.valueOf(myObject.getMyField());
>
>
As long as the xs:date format is compatible with the input format that
SqlDate.valueOf() is expecting. Otherwise, try
javax.xml.bind.DataTypeConverter.parseDate()
to get a Java Calendar object.

You also might want to look at javax.xml.datatypes.XMLGregorianCalendar.
It is a JAXP 1.3 addition to assist JAXB 2.0 with more comprehensive
date handling and functionality.

>
>
>Would I be using JAXB verification now to determine if the input/output
>matches my schema for union, restrictions, etc?
>
>
>
JAXB validation at unmarshal and marshal time is provided by JAXP 1.3
validation.
(using the setSchema(Schema) method). Full XML Schema validation is run
during unmarshal and marshal time.

-Joe

>
>Scott Allan
>
>Integrated Benefit Solutions, Inc.
>
>Work: (205) 439-4521
>
>Email: scott_at_ibs2.com
>
>EFax: (928) 832-1509
>
>AIM: ibsscott
>
>Yahoo IM: ibsscott
>
>
>
>
>
>
>
>-----Original Message-----
>
>From: Joe Fialli [mailto:Joseph.Fialli_at_Sun.COM]
>
>Sent: Tuesday, July 19, 2005 12:46 PM
>
>To: users_at_jaxb.dev.java.net
>
>Subject: Re: JAXB 2.0 union
>
>
>
>
>
>Scott Allan wrote:
>
>
>
>
>
>>I'm testing out the early access JAXB 2.0. I have this datatype
>>
>>
>
>
>
>>defined in my schema which currently works in 1.0 but I am getting a
>>
>>
>
>
>
>>different result in 2.0. I would expect that if a have an element
>>
>>
>
>
>
>>assigned to this "dateType" that I could put in either java sql.Date
>>
>>
>
>
>
>>value or a java.lang.String value such as:
>>
>>
>
>
>
>
>Handling for union has changed between JAXB 1.0 and JAXB 2.0.
>
>
>
> From ChangeLog in JAXB 2.0 Early Draft 2:
>
>
>
> XSD to Java Binding
>
>
>
> Simplified following bindings:
>
> - union by binding to String rather than Object.
>
>
>
>Rationale for change is that it is quite complex computation to take an
>
>XML data value and compute
>
>which union membertype it matches and then convert that string to that
>
>data type. JAXB 1.0
>
>generated specialized code to do this for each union. A goal in JAXB
>
>2.0 was to reduce
>
>the large amounts of generated specialized code. While there is an
>
>observable reduction in functionality,
>
>it was judged that the benefits of lower complexity in generated code
>
>and faster unmarshal/marshal times when
>
>the data was not even accessed were worth the change.
>
>
>
>-Joe Fialli, Sun Microsystems
>
>
>
>
>
>>myObject.setMyField(mySqlDate);
>>
>>
>
>
>
>
>
>
>>I'm getting this error
>>
>>
>
>
>
>>Error(196): setMyField(java.lang.String) in myPackage.TestType cannot
>>
>>
>
>
>
>>be applied to (java.sql.Date)
>>
>>
>
>
>
>
>
>
>><xs:simpleType name="dateType">
>>
>>
>
>
>
>> <xs:union>
>>
>>
>
>
>
>> <xs:simpleType>
>>
>>
>
>
>
>> <xs:annotation>
>>
>>
>
>
>
>> <xs:appinfo>
>>
>>
>
>
>
>> <jaxb:javaType name="java.sql.Date"
>>
>>
>
>
>
>> parseMethod="valueOf"
>>
>>
>
>
>
>> printMethod="toString"/>
>>
>>
>
>
>
>> <!-- sample format 2003-10-13 -->
>>
>>
>
>
>
>> </xs:appinfo>
>>
>>
>
>
>
>> </xs:annotation>
>>
>>
>
>
>
>> <xs:restriction base="xs:date"/>
>>
>>
>
>
>
>> </xs:simpleType>
>>
>>
>
>
>
>> <xs:simpleType>
>>
>>
>
>
>
>> <xs:restriction base="xs:string">
>>
>>
>
>
>
>> </xs:restriction>
>>
>>
>
>
>
>> </xs:simpleType>
>>
>>
>
>
>
>> </xs:union>
>>
>>
>
>
>
>> </xs:simpleType>
>>
>>
>
>
>
>
>
>
>
>
>---------------------------------------------------------------------
>
>To unsubscribe, e-mail: users-unsubscribe_at_jaxb.dev.java.net
>
>For additional commands, e-mail: users-help_at_jaxb.dev.java.net
>
>
>
>
>
>
> _____
>
><< ella for Spam Control >> has removed 23543 Spam messages and set
>aside 2 Newsletters for me
>You can use it too - and it's FREE! www.ellaforspam.com
>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: users-unsubscribe_at_jaxb.dev.java.net
>For additional commands, e-mail: users-help_at_jaxb.dev.java.net
>
>
>