users@jaxb.java.net

Re: Namespace Question

From: Wiedmann, Jochen <jochen.wiedmann_at_softwareag.com>
Date: Wed, 05 Feb 2003 21:15:10 +0100

> I'm curious how JaxMe handles when the schema is
>
> <xs:schema targetNamespace="fooNS">
> <xs:element name="foo" type="QName"/>
> </xs:schema>
>
> and I unmarshal
>
> <foo xmlns="fooNS">aname</foo>
>
> then modify it programatically to
>
> // the value is changed to no namespace
> fooObject.setValue( new QName("","anotherName") );
>
> and then marshal it out.

Good question. Honestly, the type QName is not yet implemented,
because of my lack of time. :-) However there is no problem.

First of all, that reminds me to a discussion that we had in the
past. You have the point, that the above doesn't have a satis-
fying solution, if the marshalling must be done by a method
like

    print()

without any context. In our discussion I proposed to give the
serializer access to such context.

In JaxMe 2 that "context" is the interface JMXmlSerializer.Data.
(JMXmlSerializer is the part of the Marshaller, which can be
shared by threads. JMXmlSerialzer.Data is the thread specific
part, which is passed through the marshalling methods.)

To marshal the QName, one would call

    JMXmlSerializer.Data.getNamespaceSupport().getPrefix(String uri)

which verifies whether the URI already has an associated prefix.
If that is not the case, it will call

    JMXmlSerializer.getPreferredPrefix(String uri)

(That's the method which you would overwrite.)


Jochen