You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tuscany.apache.org by Simon Laws <si...@googlemail.com> on 2009/09/08 15:09:38 UTC

[1.5.1/1.x] problem writing namespaces

I'm looking at TUSCANY-3264 where namespaces are missing from some
elements when a composite is written out. I don't have specific proof
but it seems to be realted in some way to TUSCANY-3212. Debugging the
code into the BaseStAXArtifactProcessor I note that the problem arises
when writing out <t:binding.http/> in this code

    protected void writeStart(XMLStreamWriter writer, String uri,
String name, XAttr... attrs) throws XMLStreamException {
        String prefix = writeElementPrefix(writer, uri);
        writer.writeStartElement(uri, name);
        if (prefix != null){
            writer.writeNamespace(prefix,uri);
        }
        writeAttributePrefixes(writer, attrs);
        writeAttributes(writer, attrs);
    }

writeElementPrefix returns non-null and hence writeNamespace() is not
called. This, I think, means that the stream thinks that it has
already written out this namespace. The written xml is as follows...

<?xml version="1.0" encoding="UTF-8"?>
<composite xmlns="http://www.osoa.org/xmlns/sca/1.0"
                 xmlns:ns1="http://www.osoa.org/xmlns/sca/1.0"
                 targetNamespace="http://store"name="store-supplier">
<component name="StoreSupplier" uri="StoreSupplier">
  <wstxns1:implementation.widget
xmlns:wstxns1="http://tuscany.apache.org/xmlns/sca/1.0"

xmlns:widget="http://tuscany.apache.org/xmlns/sca/1.0"

location="uiservices/store.html" />
  <service name="Widget">
    <interface.java
interface="org.apache.tuscany.sca.implementation.widget.Widget" />
    <wstxns1:binding.http name="Widget" uri="http://localhost:8103/ui" />
    <callback />
  </service>
...

So it has already written out wstxns1 but not in a scope that contains
binding.http.

Now I'm a bit reluctant to dive in and start fixing this as there's a
good chance I'll mess us something else by doing so. I'd like to walk
though this with someone who knows how the writers are supposed to
work. Raymond?

Simon

Re: [1.5.1/1.x] problem writing namespaces

Posted by Raymond Feng <en...@gmail.com>.
Hi,

Can you try to change the sequence of the code by reversing 1 and 2?

    protected void writeStart(XMLStreamWriter writer, String uri, String 
name, XAttr... attrs) throws XMLStreamException {
        String prefix = writeElementPrefix(writer, uri); // 1
        writer.writeStartElement(uri, name); // 2
        if (prefix != null){
            writer.writeNamespace(prefix,uri);
        }
...

By the StAX spec, when 1 is called, it is NOT in the scope of 
<binding.http>.

Thanks,
Raymond
--------------------------------------------------
From: "Simon Laws" <si...@googlemail.com>
Sent: Tuesday, September 08, 2009 6:09 AM
To: "tuscany-dev" <de...@tuscany.apache.org>
Subject: [1.5.1/1.x] problem writing namespaces

> I'm looking at TUSCANY-3264 where namespaces are missing from some
> elements when a composite is written out. I don't have specific proof
> but it seems to be realted in some way to TUSCANY-3212. Debugging the
> code into the BaseStAXArtifactProcessor I note that the problem arises
> when writing out <t:binding.http/> in this code
>
>    protected void writeStart(XMLStreamWriter writer, String uri,
> String name, XAttr... attrs) throws XMLStreamException {
>        String prefix = writeElementPrefix(writer, uri);
>        writer.writeStartElement(uri, name);
>        if (prefix != null){
>            writer.writeNamespace(prefix,uri);
>        }
>        writeAttributePrefixes(writer, attrs);
>        writeAttributes(writer, attrs);
>    }
>
> writeElementPrefix returns non-null and hence writeNamespace() is not
> called. This, I think, means that the stream thinks that it has
> already written out this namespace. The written xml is as follows...
>
> <?xml version="1.0" encoding="UTF-8"?>
> <composite xmlns="http://www.osoa.org/xmlns/sca/1.0"
>                 xmlns:ns1="http://www.osoa.org/xmlns/sca/1.0"
>                 targetNamespace="http://store"name="store-supplier">
> <component name="StoreSupplier" uri="StoreSupplier">
>  <wstxns1:implementation.widget
> xmlns:wstxns1="http://tuscany.apache.org/xmlns/sca/1.0"
>
> xmlns:widget="http://tuscany.apache.org/xmlns/sca/1.0"
>
> location="uiservices/store.html" />
>  <service name="Widget">
>    <interface.java
> interface="org.apache.tuscany.sca.implementation.widget.Widget" />
>    <wstxns1:binding.http name="Widget" uri="http://localhost:8103/ui" />
>    <callback />
>  </service>
> ...
>
> So it has already written out wstxns1 but not in a scope that contains
> binding.http.
>
> Now I'm a bit reluctant to dive in and start fixing this as there's a
> good chance I'll mess us something else by doing so. I'd like to walk
> though this with someone who knows how the writers are supposed to
> work. Raymond?
>
> Simon