users@jaxb.java.net

Re: mixed content - compiler bug?

From: Magnus Bergman <magnus.bergman_at_voiceprovider.com>
Date: Fri, 13 Dec 2002 17:25:08 +0100

Hi, thanks for your response!
I'm not sure that this is what you ment but I changed
the name on the complex type to CdX, like this:
...
<xsd:complexType name="CdX" mixed="true">
  <xsd:sequence>
    <xsd:element name="artist" type="xsd:string"/>
    <xsd:element name="title" type="xsd:string"/>
    <xsd:element name="cd" minOccurs="0" maxOccurs="unbounded" type="CdX"/>
  </xsd:sequence>
  <xsd:attribute name="model" type="xsd:string"/>
</xsd:complexType>
...

and it seems to work!
the generated code is:

public interface CdX {
    String getModel();
    void setModel(String value);
    java.util.List getContent();
    public interface Artist {
        String getValue();
        void setValue(String value);
    }
    public interface Cd
        extends test.CdX
    {
    }
    public interface Title {
        String getValue();
        void setValue(String value);
    }
}

Was this the way you ment?
/magnus

> When JAXB is processing a mixed
> content list, it creates a element interfaces for all local
> elements in the content model, that is probably
> the nested interface "Cd" that you are seeing.
>
>
> Could you try changing the name of the local element "cd" to
> any other name and send in the generated code. I fear that this
> problem has no real good solution
> because no matter what you will end up with a recursive reference
> to the java interface you are still defining, I am not sure if that
> is allowed by Java.Here is what I expect to see generated.
>
> /** for complex type def */
> interface Cd {
>
> /** for element interface, assume local element "cd" is
> changed to "bonusCd".
> interface bonusCd implements javax.xml.bind.Element, Cd { }
> }
>
> I don't know if the java compiler will like the recursive reference
> from nested interface bonusCd implements to top-level class "Cd".
>
> I fear you probably will need to remove the recursive reference to
> workaround
> this problem.
>
> -Joe Fialli, Sun Microsystems
>
>
>> ...
>>
>> the corresponding xml could look like this:
>> ...
>> <cd model="double">This is my favourite
>> <artist>Red hot chili peppers</artist>
>> <title>By the way</title>
>> <cd model="bonus cd">
>> <artist>Red hot chili peppers</artist>
>> <title>californication</title>
>> </cd>
>> </cd>
>> ...
>>
>> From this the xjc will generate an interface Cd with an inner interface
>> also called Cd which
>> ofcourse will result in javac-compiler-error!
>>
>> Does anybody know how to fix this with a workaround or have I made a
>> misstake somewhere?
>> I can't change the xml-structure, it's not in my hands...
>>
>> Any help would be great.
>> /magnus
>
>
>
> --