users@jaxb.java.net

RE: Re: Re: Issue with types that refer to themselves, and arrays

From: Reif, Benjamin <benjamin.reif_at_cgi.com>
Date: Wed, 17 Sep 2008 04:13:25 -0700

Yes, I think this would work if you wanted an unwrapped array
definition. So you just have type=Group.class in your @XmlElement, or no
type attribute in the annotation at all? We're looking for wrapped array
definitions in the schema. So, I'm curious, if you add the
@XmlElementWrapper annotation, to try to define a wrapped array, how
does it come out? It definitely seems like there's a difference between
the code that comes with JDK 1.6 and the separate jar files that you
download and use with JDK 1.5.

 

I'm currently using JAXB-RI 2.1.6, but it seems to be the same in 2.1.8.
To get rid of the exception, for now I've changed this method on the
com.sun.xml.bind.v2.model.impl.ModelBuilder

 

    /**

     * Checks the uniqueness of the type name.

     */

    private void addTypeName(NonElement<T, C> r) {

        QName t = r.getTypeName();

        if(t==null) return;

 

        TypeInfo old = typeNames.put(t,r);

//Old code

// if(old!=null) {

// // collision

// reportError(new IllegalAnnotationException(

//
Messages.CONFLICTING_XML_TYPE_MAPPING.format(r.getTypeName()),

// old, r ));

// }

//

//Just added logic to only throw error if the old Class type and QName
does not match the passed in one

//

        if(old!=null &&

            !old.getType().equals(r.getType()) &&

            NonElement.class.isAssignableFrom(old.getClass()) &&

            !((NonElement)old).getTypeName().equals(r.getTypeName())) {

            // collision

            reportError(new IllegalAnnotationException(

 
Messages.CONFLICTING_XML_TYPE_MAPPING.format(r.getTypeName()),

                    old, r ));

        }

    }

 

I'm not sure that just checking for null, as the old code did, is
sufficient. I think this seems correct, because all you're doing is just
allowing the same Value to be re-written to the typeNames Map for a
given Key, instead of throwing an error just because the Value existed
in the Map already. Does anyone have any thoughts on if this is a defect
in the JAXB-RI code, and if this fix seems reasonable?

 

Ben

________________________________

From: Wolfgang Laun [mailto:wolfgang.laun_at_gmail.com]
Sent: Wednesday, September 17, 2008 2:22 AM
To: users_at_jaxb.dev.java.net
Subject: Re: Re: Issue with types that refer to themselves, and arrays

 

On Tue, Sep 16, 2008 at 9:56 PM, Reif, Benjamin <benjamin.reif_at_cgi.com>
wrote:

         

        I think you get more re-use because I can reference use type="
tns:GroupArray" in other elements. Otherwise it comes out looking
something like:

         

                           <xs:element form="qualified" minOccurs="0"
name="groups" nillable="true">

                                <xs:complexType>

                                    <xs:sequence>

                                        <xs:element form="qualified"
maxOccurs="unbounded" minOccurs="0" name="Group" nillable="true"
type="ns0:Group"/>

                                    </xs:sequence>

                                </xs:complexType>

                            </xs:element>
         

I wouldn't like this either. - I have annotated the xxxGroups properties
the way you
wrote except for the type=Group[].class, and I get
   <xs:complexType name="Group">
     <xs:sequence>
        <xs:element name="groupGroups" type="tns:Group" ...
minOccurs="0" maxOccurs="unbounded"/>
    </..>
  </...>
Since this is the way I use to write the XML schemas, I'm perfectly
happy with that.
Is this also something your "other tools" don't like?
 

        Unfortunately we also have to use JDK 1.5, so using 1.6 isn't an
option.

You'd only need the schemagen from 1.6 - that shouldn't be a problem.

Cheers
Wolfgang