Problem solved..

As you maybe noticed I also upgraded my Axis toolkit to 1.2 Final
and someone has changed CastorSerializer from using StringWriter
to AxisContentHandler.

Changing the code to use StringWriter in the Axis 1.2 Final version
of CastorSerializer made marshaller.setNamespaceMapping to work again.

Any idea why StringWriter and AxisContentHandler works differently
regarding
setNamespaceMapping !?

Cheers,
Are T. Tysnes

Ps. I will close the JIRA I did create.. :o)

-----Original Message-----
From: Tysnes Are Thobias 
Sent: 7. juni 2005 09:38
To: dev@castor.codehaus.org; user@castor.codehaus.org
Subject: [castor-dev] [castor-user][XML] marshaller.setNamespaceMapping
is not working in 0.9.6 !?



Hello again groups.. found one more strange feature in 0.9.6

This code DID work in 0.9.5.3:

        try {
            writer = new StringWriter();

            // Create a Castor Marshaller initialized with the output
stream
            Marshaller marshaller = new Marshaller(writer);

            // Don't include the DOCTYPE, otherwise an exception occurs
due to
            //2 DOCTYPE defined in the document. The XML fragment is
included in
            //an XML document containing already a DOCTYPE
            marshaller.setMarshalAsDocument(false);
            
            if
(value.getClass().getName().equalsIgnoreCase("qualified.class.name.one")
) {
 
marshaller.setNamespaceMapping("mynammespace","http://www.test.com/test/
webservices/one");
            } else if
(value.getClass().getName().equalsIgnoreCase("qualified.class.name.two")
) {
 
marshaller.setNamespaceMapping("mynammespace","http://www.test.com/test/
webservices/two");
            } /*else if (etc etc...) {
                
            }*/
            
            // Marshall the Castor object into the stream (sink)
            marshaller.marshal(value);
                        
            context.writeString(writer.toString());
                        
        } catch (MarshalException me) {

This code DOES NOT work in 0.9.6:

        try {
            AxisContentHandler hand = new AxisContentHandler(context);
            Marshaller marshaller = new Marshaller(hand);

            // Don't include the DOCTYPE, otherwise an exception occurs
due to
            //2 DOCTYPE defined in the document. The XML fragment is
included in
            //an XML document containing already a DOCTYPE
            marshaller.setMarshalAsDocument(false);
            marshaller.setRootElement(name.getLocalPart());
            marshaller.setSuppressXSIType(true);

            // Set namespace declarations
            if
(value.getClass().getName().equalsIgnoreCase("qualified.class.name.one")
) {
 
marshaller.setNamespaceMapping("mynammespace","http://www.test.com/test/
webservices/one");
            } else if
(value.getClass().getName().equalsIgnoreCase("qualified.class.name.two")
) {
 
marshaller.setNamespaceMapping("mynammespace","http://www.test.com/test/
webservices/two");
            } /*else if (etc etc...) {
                
            }*/

            // Marshall the Castor object into the stream (sink)
            marshaller.marshal(value);
        } catch (MarshalException me) {

Any suggestion !?

I want the namespace declaration to appear in top of the
qualified.class.name.one and qualified.class.name.two "objects" in the
response xml. I managed to achieve this in 0.9.5.3 with the code above..
but I'm not able to get this to work in 0.9.6.

Cheers,
Are T. Tysnes

-------------------------------------------------
If you wish to unsubscribe from this list, please 
send an empty message to the following address:

[EMAIL PROTECTED]
-------------------------------------------------

-------------------------------------------------
If you wish to unsubscribe from this list, please
send an empty message to the following address:

[EMAIL PROTECTED]
-------------------------------------------------

Reply via email to