users@jaxb.java.net

Missing cast when generating from relaxng schema?

From: Ian Carr <ian.carr_at_focus-solutions.co.uk>
Date: Mon, 10 Nov 2003 18:59:32 -0000

I have been trying out the JAXB compiler XJC with the -relaxng option to
generate classes initially for the relaxng.rng schema. The generated code
appears to be missing some class casts when dealing with serializing of
namespaces. The generated code looks like:

protected java.lang.Object _Content;

...

public void serializeBody(generated.impl.runtime.XMLSerializer context)
    throws org.xml.sax.SAXException
{
    context.startElement("http://relaxng.org/ns/structure/1.0", "element");
    if (_Content instanceof javax.xml.namespace.QName) {
        try {
            context.getNamespaceContext().declareNamespace(
>> _Content.getNamespaceURI(),
>> _Content.getPrefix(),
                        false);
        } catch (java.lang.Exception e) {
            generated.impl.runtime.Util.handlePrintConversionException(this,
e, context);
        }
    } else {
        if (_Content instanceof generated.OpenNameClass) {
            context.childAsURIs(((com.sun.xml.bind.JAXBObject) _Content),
"Content");

...

which yields compile errors at the locations marked '>>' "The method
getNamespaceURI() is undefined for the type Object"

I believe the correct code should be:

...

    public void serializeBody(generated.impl.runtime.XMLSerializer context)
        throws org.xml.sax.SAXException
    {
        context.startElement("http://relaxng.org/ns/structure/1.0",
"element");
        if (_Content instanceof javax.xml.namespace.QName) {
            try {
                context.getNamespaceContext().declareNamespace(
>>
((javax.xml.namespace.QName)_Content).getNamespaceURI(),
>>
((javax.xml.namespace.QName)_Content).getPrefix(),
                                false);
            } catch (java.lang.Exception e) {
 
generated.impl.runtime.Util.handlePrintConversionException(this, e,
context);
            }
        } else {
            if (_Content instanceof generated.OpenNameClass) {
                context.childAsURIs(((com.sun.xml.bind.JAXBObject)
_Content), "Content");

...

Or am I missing something in the use of the generator?

Many thanks in advance for any help.

Ian Carr

Head of Technical Architecture
Focus Business Solutions



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