[ 
http://issues.apache.org/jira/browse/WSCOMMONS-74?page=comments#action_12429710 
] 
            
Rich Scheuerle commented on WSCOMMONS-74:
-----------------------------------------

Eran thanks for the clarification. 

Everyone, let me try to clarify the rule for createOMElement("foo", null).  I 
don't believe there is any breakage here.

---------------------------
Model Rule for createOMElement("name", null):

The element "name" uses the default namespace.  If the default namespace is not 
set on "name" then then default namespace in scope is used.  If the default 
namespace is not set in the scope, then "name" is an unqualified name.  This is 
way the model works today (ignore the OMSerializerUtils code...look at the 
object model).  If you ask for the namespace of nameElem in Ruchith's code 
above it will be null, because the default namespace is never set.

----------------------------
Serialization Rule for createOMElement("name", null);

The serialization rule must be consistent with the model rule.  Ruchith's 
sample serialization above is consistent with the model.  I don't see anything 
the prior OMSerializerUtils that would have changed this.  In the old 
OMSerializerUtils, the abridged logic of serializeStartPart is:

A) Get the namespace of the element. For the example above this will be null 
for "name".
B) Drop into  the section where the startElement is written...plus a rather 
obscure comment:

writer.writeStartElement(element.getLocalName());

            /** // we need to check whether there's a default namespace visible 
at this point because
             // otherwise this element will go into that namespace 
unintentionally. So we check
             // whether there is a default NS visible and if so turn it off.
             if (writer.getNamespaceContext().getNamespaceURI("") != null) {
             writer.writeDefaultNamespace("");
             }   */

C) Call serializeNamespaces....There are no declared namespaces on "name" so 
nothing will be done.

So the outcome is the same for both the old and new code....and the model is 
consistent with the serialization logic.  Please let me know if you believe 
that I 
am mistaken in my analysis.

Aside:  I don't disagree with the commented out code, but it is more than a 
serialization issue.  It could also be an issue with exposing the OM as a 
XMLStreamReader if this part of the OM is a fragment of another OM...  A 
possible (untested) solution is to change OMElement.getNamespace() 
from:
public OMNamespace getNamespace() throws OMException {
        return ns != null ? ns : getDefaultNamespace();
    }
to;
public OMNamespace getNamespace() throws OMException {
        OMNamespace resultNS = ns != null ? ns : getDefaultNamespace();
         // If attached and there is no namespace, this must be an unqualified 
namespace
         if (resultNS  == null && getParent() != null) {
                 resultNS = declareDefaultNamespace("\"\"");
          }
          return resultNS;
    }

-------------------------------------------
Eran,

Yes I got the hint.  I am the one that removed the comments when I refactored 
the code.  The code was refactored because it did not comply with the
StaX specification with regards to the timing of the setPrefix and writePrefix 
methods.  It is unfortunate that the STaX specfication did not do a better job 
with this important concern.  Now we have the situation where different StaX 
implementations have different interpretations.  sigh

-------------------------------------------




> Incorrect namespace serialization
> ---------------------------------
>
>                 Key: WSCOMMONS-74
>                 URL: http://issues.apache.org/jira/browse/WSCOMMONS-74
>             Project: WS-Commons
>          Issue Type: Bug
>          Components: AXIOM
>            Reporter: Ruchith Udayanga Fernando
>         Assigned To: Rich Scheuerle
>            Priority: Blocker
>         Attachments: axiom_api_patch.txt, axiom_impl_patch.txt, 
> axiom_test_patch.txt, jaxsw_test_patch.txt, SerializationTest.java
>
>
> Hi All,
> I noticed that axiom doesn't serialize namespaces correctly. 
> 1.) Namespaces in qualified elements
> For example we should be able to produce the following xml with the code that 
> follows:
> <person1 xmlns="http://ws.apache.org/axis2/apacheconasia/06";>
>   <name>John</name>
>   <name>John12</name>
>   <age>34</age>
> </person1>
>         OMFactory fac = OMAbstractFactory.getOMFactory();
>         
>         OMNamespace ns = 
> fac.createOMNamespace("http://ws.apache.org/axis2/apacheconasia/06";, "");
>         OMElement personElem = fac.createOMElement("person", ns);
>         OMElement nameElem = fac.createOMElement("name", ns);
>         nameElem.setText("John");
>         
>         OMElement ageElem = fac.createOMElement("age", ns);
>         ageElem.setText("34");
>         
>         OMElement weightElem = fac.createOMElement("weight", ns);
>         weightElem.setText("50");
>         
>         
>         //Add children to the person element
>         personElem.addChild(nameElem);
>         personElem.addChild(ageElem);
>         personElem.addChild(weightElem);
>         
>         String xml = personElem.toString();
> But right now this produces the following :
> <person xmlns="http://ws.apache.org/axis2/apacheconasia/06";><name 
> xmlns="http://ws.apache.org/axis2/apacheconasia/06";>John</name><age 
> xmlns="http://ws.apache.org/axis2/apacheconasia/06";>34</age><weight 
> xmlns="http://ws.apache.org/axis2/apacheconasia/06";>50</weight></person>
> The repetition of the default namespace should be avoided.
> This is the same even if we used a prefixed namespace.
> 2.) Unqualified elements among qualified elements
>         
>         OMFactory fac = OMAbstractFactory.getOMFactory();
>         OMNamespace ns = 
> fac.createOMNamespace("http://ws.apache.org/axis2/apacheconasia/06";, "");
>         OMElement personElem = fac.createOMElement("person", ns);
>         //Create and add an unqualified element
>         OMElement nameElem = fac.createOMElement("name", null);
>         nameElem.setText("John");
>         personElem.addChild(nameElem);
>         OMElement ageElem = fac.createOMElement("age", ns);
>         ageElem.setText("34");
>         
>         OMElement weightElem = fac.createOMElement("weight", ns);
>         weightElem.setText("50");
>         personElem.addChild(ageElem);
>         personElem.addChild(weightElem);
>         System.out.println(personElem);
> The above should produce the following :
> <person xmlns="http://ws.apache.org/axis2/apacheconasia/06";><name 
> xmlns="">John</name><age>34</age><weight>50</weight></person>
> But AXIOM right now produces :
> <person 
> xmlns="http://ws.apache.org/axis2/apacheconasia/06";><name>John</name><age 
> xmlns="http://ws.apache.org/axis2/apacheconasia/06";>34</age><weight 
> xmlns="http://ws.apache.org/axis2/apacheconasia/06";>50</weight></person>
> What do u folks think?
> Thanks,
> Ruchith
> p.s. Added a test case

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: 
http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to