Author: ruchithf
Date: Mon Nov  6 05:21:44 2006
New Revision: 471720

URL: http://svn.apache.org/viewvc?view=rev&rev=471720
Log:
- Fixed WSCOMMONS-119, and added a test scenario - Stopped writing xmlns="" in 
the case of unqualified attrs
- Fixed a bug in DOOM where we were not able to add the same child twice to the 
same parent element - in such a case we should first remove the child and then 
add it.


Added:
    
webservices/commons/trunk/modules/axiom/modules/axiom-tests/test-resources/xml/original.xml
Modified:
    
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/serialize/StreamingOMSerializer.java
    
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/util/OMSerializerUtil.java
    
webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/ParentNode.java
    
webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/om/impl/serializer/OMSerializerTest.java

Modified: 
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/serialize/StreamingOMSerializer.java
URL: 
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/serialize/StreamingOMSerializer.java?view=diff&rev=471720&r1=471719&r2=471720
==============================================================================
--- 
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/serialize/StreamingOMSerializer.java
 (original)
+++ 
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/serialize/StreamingOMSerializer.java
 Mon Nov  6 05:21:44 2006
@@ -159,7 +159,7 @@
                String namespace = reader.getNamespaceURI(i);
                namespace = (namespace != null && namespace.length() == 0) ? 
null : namespace;
                
-               String newPrefix = generateSetPrefix(prefix, namespace, writer);
+               String newPrefix = OMSerializerUtil.generateSetPrefix(prefix, 
namespace, writer, false);
                // If this is a new association, remember it so that it can 
written out later
                if (newPrefix != null) {
                        if (writePrefixList == null) {
@@ -176,7 +176,7 @@
         // Generate setPrefix for the element
         // If the prefix is not associated with a namespace yet, remember it 
so that we can
        // write out a namespace declaration
-       String newPrefix = generateSetPrefix(ePrefix, eNamespace, writer);
+       String newPrefix = OMSerializerUtil.generateSetPrefix(ePrefix, 
eNamespace, writer, false);
        // If this is a new association, remember it so that it can written out 
later
        if (newPrefix != null) {
                if (writePrefixList == null) {
@@ -205,7 +205,7 @@
                                writerPrefix :
                        generateUniquePrefix(writer.getNamespaceContext());
             }
-            newPrefix = generateSetPrefix(prefix, namespace, writer);
+            newPrefix = OMSerializerUtil.generateSetPrefix(prefix, namespace, 
writer, true);
             // If the prefix is not associated with a namespace yet, remember 
it so that we can
                // write out a namespace declaration
                if (newPrefix != null) {
@@ -280,17 +280,6 @@
         }
     }
 
-    /**
-     * Generate setPrefix/setDefaultNamespace if the prefix is not associated
-     * @param prefix
-     * @param namespace
-     * @param writer
-     * @return prefix name if a setPrefix/setDefaultNamespace is performed
-     */
-    private String generateSetPrefix(String prefix, String namespace, 
XMLStreamWriter writer) throws XMLStreamException {
-       return OMSerializerUtil.generateSetPrefix(prefix, namespace, writer);
-    }
-    
     /**
      * Method serializeEndElement.
      *

Modified: 
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/util/OMSerializerUtil.java
URL: 
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/util/OMSerializerUtil.java?view=diff&rev=471720&r1=471719&r2=471720
==============================================================================
--- 
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/util/OMSerializerUtil.java
 (original)
+++ 
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/util/OMSerializerUtil.java
 Mon Nov  6 05:21:44 2006
@@ -241,7 +241,7 @@
                namespace = (namespace != null && namespace.length() == 0) ? 
null : namespace;
                
                
-               String newPrefix = generateSetPrefix(prefix, namespace, writer);
+               String newPrefix = generateSetPrefix(prefix, namespace, writer, 
false);
                // If this is a new association, remember it so that it can 
written out later
                if (newPrefix != null) {
                        if (writePrefixList == null) {
@@ -257,7 +257,7 @@
        
        // Generate setPrefix for the element
        // Get the prefix and namespace of the element.  "" and null are 
identical.
-       String newPrefix = generateSetPrefix(ePrefix, eNamespace, writer);
+       String newPrefix = generateSetPrefix(ePrefix, eNamespace, writer, 
false);
        // If this is a new association, remember it so that it can written out 
later
        if (newPrefix != null) {
                if (writePrefixList == null) {
@@ -291,7 +291,7 @@
                prefix = (writerPrefix != null) ? 
                                writerPrefix : getNextNSPrefix();
             }
-            newPrefix = generateSetPrefix(prefix, namespace, writer);
+            newPrefix = generateSetPrefix(prefix, namespace, writer, true);
             // If the prefix is not associated with a namespace yet, remember 
it so that we can
                // write out a namespace declaration
                if (newPrefix != null) {
@@ -489,9 +489,10 @@
      * @param prefix
      * @param namespace
      * @param writer
+     * @param attr 
      * @return prefix name if a setPrefix/setDefaultNamespace is performed
      */
-    public static String generateSetPrefix(String prefix, String namespace, 
XMLStreamWriter writer) throws XMLStreamException {
+    public static String generateSetPrefix(String prefix, String namespace, 
XMLStreamWriter writer, boolean attr) throws XMLStreamException {
        // Generate setPrefix/setDefaultNamespace if the prefix is not 
associated.
        String newPrefix = null;
         if (namespace != null) {
@@ -518,7 +519,7 @@
                
                // Make sure the default namespace is either not used or 
disabled (set to "")
                String writerNS = 
writer.getNamespaceContext().getNamespaceURI("");
-               if (writerNS != null && writerNS.length() > 0) {
+               if (writerNS != null && writerNS.length() > 0 && !attr) {
                        // Disable the default namespace
                        writer.setDefaultNamespace("");
                        newPrefix = "";

Modified: 
webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/ParentNode.java
URL: 
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/ParentNode.java?view=diff&rev=471720&r1=471719&r2=471720
==============================================================================
--- 
webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/ParentNode.java
 (original)
+++ 
webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/ParentNode.java
 Mon Nov  6 05:21:44 2006
@@ -173,11 +173,9 @@
                             "HIERARCHY_REQUEST_ERR", null));
         }
         
-        if(newDomChild.parentNode == this) {
-            throw new DOMException(DOMException.HIERARCHY_REQUEST_ERR,
-                    DOMMessageFormatter.formatMessage(
-                            DOMMessageFormatter.DOM_DOMAIN,
-                            "HIERARCHY_REQUEST_ERR", null));
+        if(newDomChild.parentNode != null && newDomChild.ownerNode == 
this.ownerNode) {
+            //If the newChild is already in the tree remove it
+            newDomChild.parentNode.removeChild(newDomChild);
         }
 
         if (!(this instanceof Document)

Modified: 
webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/om/impl/serializer/OMSerializerTest.java
URL: 
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/om/impl/serializer/OMSerializerTest.java?view=diff&rev=471720&r1=471719&r2=471720
==============================================================================
--- 
webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/om/impl/serializer/OMSerializerTest.java
 (original)
+++ 
webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/om/impl/serializer/OMSerializerTest.java
 Mon Nov  6 05:21:44 2006
@@ -19,6 +19,7 @@
 import org.apache.axiom.om.AbstractTestCase;
 import org.apache.axiom.om.OMAbstractFactory;
 import org.apache.axiom.om.OMXMLParserWrapper;
+import org.apache.axiom.om.impl.builder.StAXOMBuilder;
 import org.apache.axiom.om.impl.llom.factory.OMXMLBuilderFactory;
 import org.apache.axiom.om.impl.serialize.StreamingOMSerializer;
 import org.apache.axiom.soap.SOAPBody;
@@ -26,6 +27,7 @@
 import org.apache.axiom.soap.impl.builder.StAXSOAPModelBuilder;
 
 import javax.xml.stream.*;
+
 import java.io.*;
 
 public class OMSerializerTest extends AbstractTestCase {
@@ -136,6 +138,17 @@
 
         String outputString = new String(byteArrayOutputStream.toByteArray());
         assertTrue(outputString != null && !"".equals(outputString) && 
outputString.length() > 1);
+    }
+    
+    public void testDefaultNsSerialization() {
+        try {
+            StAXOMBuilder builder = new 
StAXOMBuilder("test-resources/xml/original.xml");
+            String xml = builder.getDocumentElement().toString();
+            assertEquals("There shouldn't be any xmlns=\"\"", -1, 
xml.indexOf("xmlns=\"\""));
+        } catch (Exception e) {
+            e.printStackTrace();
+            fail(e.getMessage());
+        }
     }
 
     protected void tearDown() throws Exception {

Added: 
webservices/commons/trunk/modules/axiom/modules/axiom-tests/test-resources/xml/original.xml
URL: 
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-tests/test-resources/xml/original.xml?view=auto&rev=471720
==============================================================================
--- 
webservices/commons/trunk/modules/axiom/modules/axiom-tests/test-resources/xml/original.xml
 (added)
+++ 
webservices/commons/trunk/modules/axiom/modules/axiom-tests/test-resources/xml/original.xml
 Mon Nov  6 05:21:44 2006
@@ -0,0 +1,41 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<connector xmlns="http://geronimo.apache.org/xml/ns/j2ee/connector-1.1";>
+    <dep:environment 
xmlns:dep="http://geronimo.apache.org/xml/ns/deployment-1.1";>
+        <dep:moduleId>
+            <dep:groupId>tungsten</dep:groupId>
+            <dep:artifactId>tungsten_db</dep:artifactId>
+            <dep:version>1.0</dep:version>
+            <dep:type>rar</dep:type>
+        </dep:moduleId>
+        <dep:dependencies>
+            <dep:dependency>
+                <dep:groupId>org.apache.derby</dep:groupId>
+                <dep:artifactId>derby</dep:artifactId>
+                <dep:version>10.1.1.0</dep:version>
+                <dep:type>jar</dep:type>
+            </dep:dependency>
+        </dep:dependencies>
+    </dep:environment>
+    <resourceadapter>
+        <outbound-resourceadapter>
+            <connection-definition>
+                
<connectionfactory-interface>javax.sql.DataSource</connectionfactory-interface>
+                <connectiondefinition-instance>
+                    <name>tungsten_db</name>
+                    <config-property-setting 
name="Password">tungsten</config-property-setting>
+                    <config-property-setting 
name="Driver">org.apache.derby.jdbc.EmbeddedDriver</config-property-setting>
+                    <config-property-setting 
name="UserName">tungsten</config-property-setting>
+                    <config-property-setting 
name="ConnectionURL">jdbc:derby:@tungsten_home@/database/TUNGSTEN_DB</config-property-setting>
+                    <connectionmanager>
+                        <local-transaction/>
+                        <single-pool>
+                            <max-size>50</max-size>
+                            <min-size>1</min-size>
+                            <match-one/>
+                        </single-pool>
+                    </connectionmanager>
+                </connectiondefinition-instance>
+            </connection-definition>
+        </outbound-resourceadapter>
+    </resourceadapter>
+</connector>
\ No newline at end of file



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

Reply via email to