users@jaxb.java.net

Re: mixed content - compiler bug?

From: Joe Fialli <joseph.fialli_at_sun.com>
Date: Fri, 13 Dec 2002 09:06:48 -0500

Magnus Bergman wrote:
> Hi, still got some problems with mixed content and "recursive
> structures", this time I think
> it is a xjc-compiler-bug!?
>
> this is my xsd:
> ...
> <xsd:complexType name="Cd" mixed="true">
> <xsd:sequence>
> <xsd:element name="artist" type="xsd:string"/>
> <xsd:element name="title" type="xsd:string"/>
> <xsd:element name="cd" type="Cd"/>
> </xsd:sequence>
> <xsd:attribute name="model" type="xsd:string"/>
> </xsd:complexType>

Magnus,

I noticed that the local element "cd" has the same name as the
complex type def name "Cd". 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


--