users@jaxb.java.net

Re: xs:ID constructor issue

From: nicolas de loof <nicolas.deloof_at_gmail.com>
Date: Tue, 12 May 2009 14:48:50 +0200

I just found the <xjc:simple> to solve this.
I don't understand your note about minOccurs="0",
my <xs:element name="listElements"> is exepected to be a collection of
MyElement, but to avoid nesting them I'd like to use IDREF. Seems my schema
is not well designed.

Any suuggestion ?



2009/5/12 nicolas de loof <nicolas.deloof_at_gmail.com>

> Thanks a lot, this looks far better
> I still have an issue during marshalling :
> unable to marshal type "...MyElement" as an element because it is missing
> an @XmlRootElement annotation]
>
> As this code is generated from WSDL, I wonder how I can control the types
> that get annotated @XmlRootElement
>
> Best regards,
> Nicolas
>
> 2009/5/11 Wolfgang Laun <wolfgang.laun_at_gmail.com>
>
> 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
>>>
>>
>>
>