users@jaxb.java.net

Re: xs:ID constructor issue

From: Wolfgang Laun <wolfgang.laun_at_gmail.com>
Date: Mon, 11 May 2009 18:56:05 +0200

For obtaining typed references you just use
   <jaxb:baseType name="MyElement"/>
(The javaType=<type> *substitutes* a different type, which is something else
altogether.)

Also, the minOccurs="0" on the referenced object's ID doesn't make sense,
the ID is required.

-W


On Mon, May 11, 2009 at 3:10 PM, nicolas de loof <nicolas_at_apache.org> wrote:

> Hello,
> My WSDL/XSD uses a ID-ref to avoid cycles in data structure.
>
> To keep strong-typed attributes in the generated java code I've added some
> jaxb binding elements :
>
> <xs:element name="listeElements" type="xs:IDREFS" minOccurs="1"
> maxOccurs="unbounded">
> <xs:annotation>
> <xs:appinfo>
> <jaxb:property>
> <jaxb:baseType>
> <jaxb:javaType name="MyElement"/>
> </jaxb:baseType>
> </jaxb:property>
> </xs:appinfo>
> </xs:annotation>
> </xs:element>
>
> And added an xs:ID attribut on the "MyElement" type :
>
> <xs:complexType name="MyElement">
> <xs:sequence>
> <xs:element name="id" type="xs:ID" minOccurs="0"/>
> ...
>
> The generated code is fine (I'm using apache CXF, that itself uses xjc) :
>
> @XmlElement(required = true, type = String.class)
> @XmlJavaTypeAdapter(Adapter1 .class)
> @XmlSchemaType(name = "IDREFS")
> protected List<MyElement> listeElements;
>
> BUT the generated Adapter1 expect the tager MyElement class to have an
> ID-constructor :
>
> public class Adapter1
> extends XmlAdapter<String, MyElement>
> {
> public MyElement unmarshal(String value) {
> return new MyElement(value);
> }
>
>
> There is no constructor generated in MyElement. Did I missed something ?
>
> Best regards,
> Nicolas
>