axis-java-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ga...@apache.org
Subject svn commit: r751964 - in /webservices/axis2/branches/java/1_5/modules/saaj: src/org/apache/axis2/saaj/ test/org/apache/axis2/saaj/
Date Tue, 10 Mar 2009 02:19:01 GMT
Author: gawor
Date: Tue Mar 10 02:19:00 2009
New Revision: 751964

URL: http://svn.apache.org/viewvc?rev=751964&view=rev
Log:
handle Comment nodes better (AXIS2-4266)

Added:
    webservices/axis2/branches/java/1_5/modules/saaj/src/org/apache/axis2/saaj/CommentImpl.java
  (with props)
Modified:
    webservices/axis2/branches/java/1_5/modules/saaj/src/org/apache/axis2/saaj/NodeImplEx.java
    webservices/axis2/branches/java/1_5/modules/saaj/src/org/apache/axis2/saaj/SOAPBodyImpl.java
    webservices/axis2/branches/java/1_5/modules/saaj/test/org/apache/axis2/saaj/SOAPEnvelopeTest.java
    webservices/axis2/branches/java/1_5/modules/saaj/test/org/apache/axis2/saaj/TextTest.java

Added: webservices/axis2/branches/java/1_5/modules/saaj/src/org/apache/axis2/saaj/CommentImpl.java
URL: http://svn.apache.org/viewvc/webservices/axis2/branches/java/1_5/modules/saaj/src/org/apache/axis2/saaj/CommentImpl.java?rev=751964&view=auto
==============================================================================
--- webservices/axis2/branches/java/1_5/modules/saaj/src/org/apache/axis2/saaj/CommentImpl.java
(added)
+++ webservices/axis2/branches/java/1_5/modules/saaj/src/org/apache/axis2/saaj/CommentImpl.java
Tue Mar 10 02:19:00 2009
@@ -0,0 +1,48 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.axis2.saaj;
+
+import javax.xml.soap.SOAPElement;
+import javax.xml.soap.Text;
+
+import org.w3c.dom.Comment;
+
+public class CommentImpl extends TextImplEx implements Comment {
+
+    public CommentImpl(String data, SOAPElement parent) {
+        super(data, parent);
+    }
+
+    public CommentImpl(String data, SOAPElement parent,
+                       org.w3c.dom.Node prevSibling, org.w3c.dom.Node nextSibling) {
+        super(data, parent, prevSibling, nextSibling);
+    }
+
+    public boolean isComment() {
+        return true;
+    }
+
+    public String getNodeName() {
+        return "#comment";
+    }
+
+    public short getNodeType() {
+        return Text.COMMENT_NODE;
+    }
+}

Propchange: webservices/axis2/branches/java/1_5/modules/saaj/src/org/apache/axis2/saaj/CommentImpl.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: webservices/axis2/branches/java/1_5/modules/saaj/src/org/apache/axis2/saaj/CommentImpl.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: webservices/axis2/branches/java/1_5/modules/saaj/src/org/apache/axis2/saaj/CommentImpl.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: webservices/axis2/branches/java/1_5/modules/saaj/src/org/apache/axis2/saaj/NodeImplEx.java
URL: http://svn.apache.org/viewvc/webservices/axis2/branches/java/1_5/modules/saaj/src/org/apache/axis2/saaj/NodeImplEx.java?rev=751964&r1=751963&r2=751964&view=diff
==============================================================================
--- webservices/axis2/branches/java/1_5/modules/saaj/src/org/apache/axis2/saaj/NodeImplEx.java
(original)
+++ webservices/axis2/branches/java/1_5/modules/saaj/src/org/apache/axis2/saaj/NodeImplEx.java
Tue Mar 10 02:19:00 2009
@@ -209,9 +209,7 @@
             org.w3c.dom.Node prevSiblingDOMNode = comment.getPreviousSibling();
             org.w3c.dom.Node nextSiblingDOMNode = comment.getNextSibling();
             SOAPElementImpl parent = new SOAPElementImpl((ElementImpl)domNode.getParentNode());
-            TextImplEx saajTextNode = new TextImplEx("<!--" +
-                    comment.getData() +
-                    "-->",
+            CommentImpl saajTextNode = new CommentImpl(comment.getData(),
                                                      parent, prevSiblingDOMNode,
                                                      nextSiblingDOMNode);
             ((NodeImpl)domNode).setUserData(SAAJ_NODE, saajTextNode, null);

Modified: webservices/axis2/branches/java/1_5/modules/saaj/src/org/apache/axis2/saaj/SOAPBodyImpl.java
URL: http://svn.apache.org/viewvc/webservices/axis2/branches/java/1_5/modules/saaj/src/org/apache/axis2/saaj/SOAPBodyImpl.java?rev=751964&r1=751963&r2=751964&view=diff
==============================================================================
--- webservices/axis2/branches/java/1_5/modules/saaj/src/org/apache/axis2/saaj/SOAPBodyImpl.java
(original)
+++ webservices/axis2/branches/java/1_5/modules/saaj/src/org/apache/axis2/saaj/SOAPBodyImpl.java
Tue Mar 10 02:19:00 2009
@@ -102,12 +102,12 @@
         String namespaceURI = child.getNamespaceURI();
         String prefix = child.getPrefix();
 
-        element.declareNamespace(namespaceURI, prefix);
-        
         SOAPBodyElementImpl childEle = new SOAPBodyElementImpl(child);
 
         childEle.element.setUserData(SAAJ_NODE, childEle, null);
-        childEle.element.setNamespace(childEle.element.declareNamespace(namespaceURI, prefix));
+        if (namespaceURI != null && namespaceURI.trim().length() > 0) {
+            childEle.element.setNamespace(childEle.element.declareNamespace(namespaceURI,
prefix));
+        }
         element.appendChild(childEle.element);
         ((NodeImpl)childEle.element.getParentNode()).setUserData(SAAJ_NODE, this, null);
         childEle.setParentElement(this);
@@ -432,7 +432,7 @@
         }
         if (node instanceof org.w3c.dom.Comment) {
             org.w3c.dom.Comment domText = (org.w3c.dom.Comment)node;
-            return new TextImplEx("<!--" + domText.getData() + "-->", parent);
+            return new CommentImpl(domText.getData(), parent);
         }
         Element domEle = ((Element)node);
         int indexOfColon = domEle.getTagName().indexOf(":");

Modified: webservices/axis2/branches/java/1_5/modules/saaj/test/org/apache/axis2/saaj/SOAPEnvelopeTest.java
URL: http://svn.apache.org/viewvc/webservices/axis2/branches/java/1_5/modules/saaj/test/org/apache/axis2/saaj/SOAPEnvelopeTest.java?rev=751964&r1=751963&r2=751964&view=diff
==============================================================================
--- webservices/axis2/branches/java/1_5/modules/saaj/test/org/apache/axis2/saaj/SOAPEnvelopeTest.java
(original)
+++ webservices/axis2/branches/java/1_5/modules/saaj/test/org/apache/axis2/saaj/SOAPEnvelopeTest.java
Tue Mar 10 02:19:00 2009
@@ -47,11 +47,15 @@
 import javax.xml.transform.TransformerFactory;
 import javax.xml.transform.dom.DOMResult;
 import javax.xml.transform.dom.DOMSource;
+import javax.xml.transform.sax.SAXSource;
 
+import org.w3c.dom.Comment;  
 import org.w3c.dom.Document;
 import org.w3c.dom.Element;
+import org.xml.sax.InputSource; 
 
 import java.io.ByteArrayInputStream;
+import java.io.StringReader;
 import java.util.Iterator;
 
 public class SOAPEnvelopeTest extends TestCase {
@@ -72,6 +76,8 @@
                     "</shw:Address>\n" +
                     "</soapenv:Body>\n" +
                     "</soapenv:Envelope>";
+    
+    private static final String XML_INPUT_1 = "<root><a><!-- this is a test
with a comment node --></a></root>";
 
     public SOAPEnvelopeTest(String name) {
         super(name);
@@ -629,4 +635,55 @@
         document.appendChild(getLastTradePrice);
         return getLastTradePrice;
     }
-}
\ No newline at end of file
+    
+    public void testTransformWithComments() throws Exception {
+        MessageFactory fact = MessageFactory.newInstance();
+        SOAPMessage message = fact.createMessage();
+        SOAPBody body = message.getSOAPBody();
+        Source source = new SAXSource(new InputSource(new StringReader(XML_INPUT_1)));
+        DOMResult result = new DOMResult(body);
+        TransformerFactory transformerFactory = TransformerFactory.newInstance();
+        Transformer transformer = transformerFactory.newTransformer();
+        transformer.transform(source, result);
+        
+        // test DOM
+        org.w3c.dom.Node rootNode = result.getNode();
+        org.w3c.dom.Node node = rootNode.getFirstChild();
+        assertTrue(node instanceof Element);
+        assertEquals("root", node.getNodeName());
+        
+        node = node.getFirstChild();
+        assertTrue(node instanceof Element);
+        assertEquals("a", node.getNodeName());
+        
+        node = node.getFirstChild();
+        assertTrue(node instanceof Comment);
+        assertEquals("this is a test with a comment node", node.getNodeValue().trim());
+        
+        // test SAAJ
+        assertEquals(1, body.getChildNodes().getLength());
+        Iterator iter = body.getChildElements();
+        assertTrue(iter.hasNext()); 
+        Object obj = iter.next();
+        assertTrue(obj instanceof SOAPBodyElement);  
+        SOAPElement soapElement = (SOAPElement)obj;
+        assertEquals("root", soapElement.getLocalName());
+        
+        iter = soapElement.getChildElements();
+        assertTrue(iter.hasNext()); 
+        obj = iter.next();
+        assertTrue(obj instanceof SOAPElement);  
+        soapElement = (SOAPElement)obj;
+        assertEquals("a", soapElement.getLocalName());
+        assertFalse(iter.hasNext());
+        
+        iter = soapElement.getChildElements();
+        assertTrue(iter.hasNext()); 
+        obj = iter.next();
+        assertTrue(obj instanceof Text);  
+        Text text = (Text)obj;
+        assertTrue(text.isComment());
+        assertEquals("this is a test with a comment node", text.getData().trim());
+        assertFalse(iter.hasNext());        
+    }
+}

Modified: webservices/axis2/branches/java/1_5/modules/saaj/test/org/apache/axis2/saaj/TextTest.java
URL: http://svn.apache.org/viewvc/webservices/axis2/branches/java/1_5/modules/saaj/test/org/apache/axis2/saaj/TextTest.java?rev=751964&r1=751963&r2=751964&view=diff
==============================================================================
--- webservices/axis2/branches/java/1_5/modules/saaj/test/org/apache/axis2/saaj/TextTest.java
(original)
+++ webservices/axis2/branches/java/1_5/modules/saaj/test/org/apache/axis2/saaj/TextTest.java
Tue Mar 10 02:19:00 2009
@@ -20,6 +20,7 @@
 package org.apache.axis2.saaj;
 
 import junit.framework.TestCase;
+import org.w3c.dom.Comment;
 import org.w3c.dom.Node;
 import org.w3c.dom.NodeList;
 
@@ -179,8 +180,10 @@
             isComment = ((Text)node).isComment();
             if (i == 1 || i == 3) {
                 assertEquals(true, isComment);
+                assertTrue(node instanceof Comment);
             } else {
                 assertEquals(false, isComment);
+                assertFalse(node instanceof Comment);
             }
         }
     }



Mime
View raw message