users@jaxb.java.net

problem with jaxb and abstract schema types

From: Neville Peter <p_nevilleuk_at_yahoo.co.uk>
Date: Wed, 21 Jul 2004 14:37:37 +0100 (BST)

I have generated java classes from the schema below
using xjc (jaxb version 1.0.3). My test code below
generates an error when I try and marshall the objects
to XML. The error shows that the
SubDExtendsImpl.serializeBody() is being called when I
was expecting it to use
SubDExtends.SubCRestrictsImpl.serializeBody(), which
allows mixed elements where as the former doesn't.

Can anyone else using this schema generate the
following valid XML using jaxb and then marshalling
it:

<Interaction
xmlns:gsd="http://aurora.regenstrief.org/GenericXMLSchema"
xmlns:hl7="urn::hl7.org"
xmlns:sch="http://www.ascc.net/xml/schematron"
xmlns:xlink="http://www.w3.org/TR/WD-xlink"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="C:\eclipse
projects\jaxb\jaxb\schema\pds\abstractanonymous.xsd">
        <value>Text<subCRestricts>Text</subCRestricts>
        </value>
</Interaction>

Is this an error with my code or a bug in jaxb?


Thanks,
Peter Neville






<xsd:schema
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:hl7="urn::hl7.org"
xmlns:xlink="http://www.w3.org/TR/WD-xlink"
xmlns:gsd="http://aurora.regenstrief.org/GenericXMLSchema"
xmlns:sch="http://www.ascc.net/xml/schematron"
elementFormDefault="qualified">
        <xsd:complexType name="baseAbstract" abstract="true"
mixed="true"/>
        <xsd:element name="Interaction"
type="Interaction.A"/>
        <xsd:complexType name="Interaction.A">
                <xsd:sequence>
                        <xsd:element name="value" type="subDExtends"/>
                </xsd:sequence>
        </xsd:complexType>
        <xsd:complexType name="subDExtends" mixed="true">
                <xsd:complexContent mixed="true">
                        <xsd:extension base="baseAbstract">
                                <xsd:sequence>
                                        <xsd:choice minOccurs="0" maxOccurs="unbounded">
                                                <xsd:element name="subCRestricts">
                                                        <xsd:complexType mixed="true">
                                                                <xsd:complexContent mixed="true">
                                                                        <xsd:restriction base="subBExtends"/>
                                                                </xsd:complexContent>
                                                        </xsd:complexType>
                                                </xsd:element>
                                        </xsd:choice>
                                </xsd:sequence>
                        </xsd:extension>
                </xsd:complexContent>
        </xsd:complexType>
        <xsd:complexType name="subBExtends" mixed="true">
                <xsd:complexContent mixed="true">
                        <xsd:extension base="subAExtends"/>
                </xsd:complexContent>
        </xsd:complexType>
        <xsd:complexType name="subAExtends" mixed="true">
                <xsd:complexContent mixed="true">
                        <xsd:extension base="baseAbstract"/>
                </xsd:complexContent>
        </xsd:complexType>
</xsd:schema>




import java.io.FileInputStream;
import java.io.IOException;
import java.util.Iterator;
import java.util.List;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Unmarshaller;


import javax.xml.bind.Marshaller;
import javax.xml.bind.util.ValidationEventCollector;
import javax.xml.bind.ValidationEvent;
import javax.xml.bind.ValidationEventLocator;
import org.w3c.dom.Node;





public class AbstractTest
{
        public static void main(String[] args)
        {
        

                try
                {
                
                        JAXBContext jc = JAXBContext.newInstance(
"nhs.nhsia.test.anonymous" );
                        ObjectFactory objFactory = new ObjectFactory();
                        
                        Interaction msg = objFactory.createInteraction();
                        
                        SubDExtends value = objFactory.createSubDExtends();
        
                        
                        
                        SubDExtends.SubCRestricts subCRestricts =
objFactory.createSubDExtendsSubCRestricts();
                        subCRestricts.getContent().add("test");
                        
                        value.getContent().add(subCRestricts);
                        
                        msg.setValue(value);




                        ValidationEventCollector vce = new
ValidationEventCollector();
                        Marshaller m = jc.createMarshaller();
                        
                        m.setEventHandler(vce);
                        m.setProperty(
Marshaller.JAXB_FORMATTED_OUTPUT,Boolean.TRUE );
                        m.marshal( msg, System.out );
                        
                        ValidationEvent[] validationEventsArray =
vce.getEvents();
                        System.out.println("No. of errors:" +
validationEventsArray.length);
                        
                        
                        for (int loop = 0; loop <
validationEventsArray.length; loop++)
                        {
                                ValidationEvent validationEvent =
validationEventsArray[loop];
                                System.out.println(validationEvent.getMessage());
                                StackTraceElement[] stack =
validationEvent.getLinkedException().getStackTrace();
                                for (int c = 0 ; c < stack.length; c++)
                                {
                                        System.out.println(stack[c]);
                                }
                        }
                        
                }
                catch (JAXBException e)
                {
                        System.out.println(e);
                }

                
        }


}




error output:


<?xml version="1.0" encoding="UTF-8"
standalone="yes"?>
<Interaction>
    <value/>
</Interaction>

No. of errors:1
null
nhs.nhsia.test.anonymous.impl.BaseAbstractImpl.serializeBody(BaseAbstractImpl.java:44)
nhs.nhsia.test.anonymous.impl.SubDExtendsImpl.serializeBody(SubDExtendsImpl.java:30)
nhs.nhsia.test.anonymous.impl.runtime.SAXMarshaller.childAsBody(SAXMarshaller.java:391)
nhs.nhsia.test.anonymous.impl.InteractionAImpl.serializeBody(InteractionAImpl.java:44)
nhs.nhsia.test.anonymous.impl.InteractionImpl.serializeBody(InteractionImpl.java:43)
nhs.nhsia.test.anonymous.impl.runtime.MarshallerImpl.write(MarshallerImpl.java:171)
nhs.nhsia.test.anonymous.impl.runtime.MarshallerImpl.marshal(MarshallerImpl.java:144)
javax.xml.bind.helpers.AbstractMarshallerImpl.marshal(AbstractMarshallerImpl.java:66)
nhs.nhsia.test.anonymous.AbstractTest.main(AbstractTest.java:54)



        
        
                
___________________________________________________________ALL-NEW Yahoo! Messenger - sooooo many all-new ways to express yourself http://uk.messenger.yahoo.com

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe_at_jaxb.dev.java.net
For additional commands, e-mail: users-help_at_jaxb.dev.java.net