Author: chinthaka
Date: Mon Apr 24 09:05:26 2006
New Revision: 396593

URL: http://svn.apache.org/viewcvs?rev=396593&view=rev
Log:
Fixing another issue with ns handling (seems this is another slippery slope). 
Thanks Ruchith for point this out even with a wrong test case ;).

Modified:
    
webservices/commons/trunk/modules/axiom/src/org/apache/axiom/om/impl/util/OMSerializerUtil.java
    
webservices/commons/trunk/modules/axiom/test/org/apache/axiom/om/DefaultNSHandlingTest.java

Modified: 
webservices/commons/trunk/modules/axiom/src/org/apache/axiom/om/impl/util/OMSerializerUtil.java
URL: 
http://svn.apache.org/viewcvs/webservices/commons/trunk/modules/axiom/src/org/apache/axiom/om/impl/util/OMSerializerUtil.java?rev=396593&r1=396592&r2=396593&view=diff
==============================================================================
--- 
webservices/commons/trunk/modules/axiom/src/org/apache/axiom/om/impl/util/OMSerializerUtil.java
 (original)
+++ 
webservices/commons/trunk/modules/axiom/src/org/apache/axiom/om/impl/util/OMSerializerUtil.java
 Mon Apr 24 09:05:26 2006
@@ -111,7 +111,8 @@
                 writer.setDefaultNamespace(uri);
             } else {
                 prefix = prefix == null ? getNextNSPrefix(writer) : prefix;
-                if (prefix != null && !prefix.equals(prefixFromWriter) && 
!checkForPrefixInTheCurrentContext(writer, uri, prefix)) {
+                if (prefix != null && !prefix.equals(prefixFromWriter) && 
!checkForPrefixInTheCurrentContext(writer, uri, prefix))
+                {
                     writer.writeNamespace(prefix, uri);
                     writer.setPrefix(prefix, uri);
                 }
@@ -192,6 +193,8 @@
                         // In both the above cases this xml may contain more 
than one prefix for the
                         // same URI. Check them all.
 
+                        // this flag will remember whether this ns is declared 
in the scope with the
+                        // given prefix or not
                         boolean found = 
checkForPrefixInTheCurrentContext(writer, nameSpaceName, prefix);
 
                         if (!found) {
@@ -200,8 +203,8 @@
                                     nameSpaceName);
                             writer.writeNamespace(prefix, nameSpaceName);
                             writer.setPrefix(prefix, nameSpaceName);
-                        }else {
-                            writer.writeStartElement(nameSpaceName, 
element.getLocalName());
+                        } else {
+                            writer.writeStartElement(prefix, 
element.getLocalName(), nameSpaceName);
                         }
 
                     }

Modified: 
webservices/commons/trunk/modules/axiom/test/org/apache/axiom/om/DefaultNSHandlingTest.java
URL: 
http://svn.apache.org/viewcvs/webservices/commons/trunk/modules/axiom/test/org/apache/axiom/om/DefaultNSHandlingTest.java?rev=396593&r1=396592&r2=396593&view=diff
==============================================================================
--- 
webservices/commons/trunk/modules/axiom/test/org/apache/axiom/om/DefaultNSHandlingTest.java
 (original)
+++ 
webservices/commons/trunk/modules/axiom/test/org/apache/axiom/om/DefaultNSHandlingTest.java
 Mon Apr 24 09:05:26 2006
@@ -1,5 +1,6 @@
 package org.apache.axiom.om;
 
+import junit.framework.TestCase;
 import org.apache.axiom.om.impl.builder.StAXOMBuilder;
 
 import javax.xml.namespace.QName;
@@ -8,11 +9,8 @@
 import javax.xml.stream.XMLStreamException;
 import javax.xml.stream.XMLStreamReader;
 import javax.xml.stream.XMLStreamWriter;
-
 import java.io.ByteArrayInputStream;
 import java.util.Iterator;
-
-import junit.framework.TestCase;
 /*
  * Copyright 2004,2005 The Apache Software Foundation.
  *
@@ -108,23 +106,24 @@
         }
     }
    
-//    public void testChildReDeclaringGrandParentsDefaultNSWithPrefix() {
-//        try {
-//            OMFactory fac = OMAbstractFactory.getOMFactory();
-//            OMElement elem = fac.createOMElement("RequestSecurityToken", 
null);
-//            
elem.declareDefaultNamespace("http://schemas.xmlsoap.org/ws/2005/02/trust";);
-//            fac.createOMElement(new QName("TokenType"), 
elem).setText("test");
-//            fac.createOMElement(new QName("RequestType"), 
elem).setText("test1");
-//
-//            OMElement entElem = fac.createOMElement(new 
QName("http://schemas.xmlsoap.org/ws/2005/02/trust","Entropy";, "wst"), elem);
-//            OMElement binSecElem = fac.createOMElement(new 
QName("http://schemas.xmlsoap.org/ws/2005/02/trust","Binarysecret";, "wst"), 
entElem);
-//            binSecElem.setText("secret value");
-//            String xml = elem.toString();
-//            assertTrue("Binarysecret element should have \'wst\' ns prefix", 
xml.indexOf("<wst:Binarysecret 
xmlns:wst=\"http://schemas.xmlsoap.org/ws/2005/02/trust\"; />") != -1);
-//        }catch (Exception e) {
-//            fail(e.getMessage());
-//        }
-//    }
+    public void testChildReDeclaringGrandParentsDefaultNSWithPrefix() {
+        try {
+            OMFactory fac = OMAbstractFactory.getOMFactory();
+            OMElement elem = fac.createOMElement("RequestSecurityToken", null);
+            
elem.declareDefaultNamespace("http://schemas.xmlsoap.org/ws/2005/02/trust";);
+            fac.createOMElement(new QName("TokenType"), elem).setText("test");
+            fac.createOMElement(new QName("RequestType"), 
elem).setText("test1");
+
+            OMElement entElem = fac.createOMElement(new 
QName("http://schemas.xmlsoap.org/ws/2005/02/trust","Entropy";, "wst"), elem);
+            OMElement binSecElem = fac.createOMElement(new 
QName("http://schemas.xmlsoap.org/ws/2005/02/trust","Binarysecret";, "wst"), 
entElem);
+            binSecElem.setText("secret value");
+            String xml = elem.toString();
+            System.out.println("xml = " + xml);
+            assertTrue("Binarysecret element should have \'wst\' ns prefix", 
xml.indexOf("<wst:Binarysecret") != -1);
+        }catch (Exception e) {
+            fail(e.getMessage());
+        }
+    }
     
     public static void main(String[] args) {
         try {


Reply via email to