aspose file tools*
The moose likes XML and Related Technologies and the fly likes getting royally SCREWED by xjc (twice!) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "getting royally SCREWED by xjc (twice!)" Watch "getting royally SCREWED by xjc (twice!)" New topic
Author

getting royally SCREWED by xjc (twice!)

Elhanan Maayan
Ranch Hand

Joined: May 04, 2009
Posts: 115
hi...

the task as i've been chosen to implement it, is to receive an xml schema from someone, jave jaxb generate files from it (using what ever customization i need) then using websphere, re-generate wsdl (which will contain generated xsd schema's (from the generated classes).

almost everything went ok, except when it came to an element defined using a simpleType called 'ourTime' which was derived from xs:dateTime.


if i were to directly use the xs:dateTime on the element in question instead of the simpleType ourTime like so:

<xsd:element name="ValidityTime" type="xs:dateTime" minOccurs="0">

, then the jaxb classes would be generated with XMLGregorianCalender which would have the annotation @XMLSchemaType(name='dateTime') thus allowing re-generation of the schema correctly with the definition xs:dateTime.

however, if i would use "ourTime' for the definition as specified , i'd XMLGregorianCalender WITHOUT the annotation @XMLSchemaType which cause the element to be defined as xs:anySimpleType in the re-generated schema.

since java.util.Date can be translated by default to xsateTime i tried another approach using jxb:javaType with java.util.Date as the name customization like so:
<jaxb:javaType name="java.util.Date" xmlType="ourTime"
parseMethod="com.fnx.security.services.auth.Authorizer.parseDate"
printMethod="com.fnx.security.services.auth.Authorizer.printDate"
/>

where the print and parse method would use XMLGregorianCalender internally to output xsd complient date string.
however this does not work, as the annotated attribute in the class is generated with @XMLElement(type=String.class) which causes the generated element in the schema to be typed as xs:String.

changing the type manually to Date.class works fine, but the main point here is not change the original schema, generated classes and generated schema.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: getting royally SCREWED by xjc (twice!)