users@jaxb.java.net

RE: Restricting xs:anyType

From: Thomson, Martin <Martin.Thomson_at_andrew.com>
Date: Wed, 23 Apr 2008 02:29:57 -0500

[I'm ashamed to admit that the "solution" below was a red herring; a combination of hope and tiredness. I've changed the subject to reflect the actual problem. My code was working because I had forgotten to move my element definitions out of the global scope.] After more reading of the JSR, I conclude that local elements that don't use 'ref' should appear in the ObjectFactory like so: JAXBElement<String> createExtendingTypeOne(String value); However, it seems that the shortcut taken for restrictions with xs:anyType (i.e. don't generate any code) also skips the creation of the necessary ObjectFactory methods. I'm still investigating possible workarounds - I am loathe to change the schema to address this issue. Regards, Martin > -----Original Message----- > From: Thomson, Martin > Sent: Tuesday, 22 April 2008 6:16 PM > To: 'users_at_jaxb.dev.java.net' > Subject: RE: Restricting xs:anyType > > It seems that I found the answer to my own question in the end. > > Adding "<globalBindings localScoping="toplevel" />" to the bindings > file makes this work a little more like I expected. > > Cheers, > Martin > > > -----Original Message----- > > From: Thomson, Martin > > Sent: Tuesday, 22 April 2008 3:42 PM > > To: 'users_at_jaxb.dev.java.net' > > Subject: Restricting xs:anyType > > > > Hi all, > > > > I've got an issue with a set of schema that use restrictions of > > xs:anyType to mark extension points. JAXB is unmarshalling instance > > documents to DOM elements, rather than the classes that it has > > generated. > > > > XJC generates empty classes for the extending class, which means that > > JAXB does not find the generated classes for any local elements > > declared by the extending type. > > > > It's probably best to illustrate by example: > > > > I have a simple base schema (A): > > > > <complexType name="baseType"> > > <complexContent> > > <restriction base="anyType"> > > <sequence> > > <any minOccurs="0" maxOccurs="unbounded" > > processContents="lax" /> > > </sequence> > > </restriction> > > </complexContent> > > </complexType> > > > > And in the extending schema (B), this base type is extended to > include > > a concrete definition of its content: > > > > <element name="ext" type="b:extendingType" /> > > <complexType name="extendingType"> > > <complexContent> > > <restriction base="a:baseType"> > > <sequence> > > <element name="one" type="token" /> > > <element name="two" type="token" /> > > </sequence> > > </restriction> > > </complexContent> > > </complexType> > > > > I then unmarshal the following instance document: > > > > <ext> > > <one>string</one> > > <two>string</two> > > </ext> > > > > JAXB produces the following model: > > > > JAXBElement<ExtendingType> > > value = ExtendingType > > any = List<Object> > > [1] = org.w3c.dom.Element ("one", "string") > > [2] = org.w3c.dom.Element ("one", "string") > > > > The problem seems to arise from the fact that the extending class is > > generated as a completely empty class and no annotations are added > that > > would enable the use of the generated classes. Since the elements > are > > local, they don't appear in the ObjectFactory. > > > > Making the elements global ensures that JAXB sees the elements > (because > > the elements are put in the ObjectFactory). > > > > I am looking for a work-around that doesn't involve changing schema. > > Has anyone got a suggestion for me? > > > > Cheers, > > Martin ------------------------------------------------------------------------------------------------ This message is for the designated recipient only and may contain privileged, proprietary, or otherwise private information. If you have received it in error, please notify the sender immediately and delete the original. Any unauthorized use of this email is prohibited. ------------------------------------------------------------------------------------------------ [mf2]