Author: darran.lofthouse(a)jboss.com
Date: 2009-07-20 12:06:04 -0400 (Mon, 20 Jul 2009)
New Revision: 10362
Added:
stack/native/branches/jbossws-native-3.1.2/modules/testsuite/native-tests/src/test/resources/common/soap/jbws2704.xml
Modified:
stack/native/branches/jbossws-native-3.1.2/modules/core/src/main/java/org/jboss/ws/core/soap/SOAPElementImpl.java
stack/native/branches/jbossws-native-3.1.2/modules/testsuite/native-tests/src/test/java/org/jboss/test/ws/common/soap/SOAPElementTestCase.java
Log:
[JBPAPP-2280] Element.getElementsByTagNameNS should support wildcards for namespace, local
name or both.
Modified:
stack/native/branches/jbossws-native-3.1.2/modules/core/src/main/java/org/jboss/ws/core/soap/SOAPElementImpl.java
===================================================================
---
stack/native/branches/jbossws-native-3.1.2/modules/core/src/main/java/org/jboss/ws/core/soap/SOAPElementImpl.java 2009-07-20
15:30:59 UTC (rev 10361)
+++
stack/native/branches/jbossws-native-3.1.2/modules/core/src/main/java/org/jboss/ws/core/soap/SOAPElementImpl.java 2009-07-20
16:06:04 UTC (rev 10362)
@@ -25,6 +25,7 @@
import java.io.Writer;
import java.util.ArrayList;
import java.util.Iterator;
+import java.util.LinkedList;
import java.util.List;
import javax.xml.namespace.QName;
@@ -764,7 +765,32 @@
public NodeList getElementsByTagNameNS(String namespaceURI, String localName)
{
- return new NodeListImpl(DOMUtils.getChildElements(this, new QName(namespaceURI,
localName), true));
+ List<Element> nodes = DOMUtils.getChildElementsAsList(this, (QName)null,
true);
+
+ List filtered = new LinkedList();
+
+ for (Element current : nodes)
+ {
+ boolean namespaceMatch = false;
+ boolean localNameMatch = false;
+
+ if ("*".equals(namespaceURI) || ((namespaceURI != null) &&
namespaceURI.equals(current.getNamespaceURI())))
+ {
+ namespaceMatch = true;
+ }
+
+ if ("*".equals(localName) || ((localName != null) &&
localName.equals(current.getLocalName())))
+ {
+ localNameMatch = true;
+ }
+
+ if (namespaceMatch == true && localNameMatch == true)
+ {
+ filtered.add(current);
+ }
+ }
+
+ return new NodeListImpl(filtered.iterator());
}
public TypeInfo getSchemaTypeInfo()
Modified:
stack/native/branches/jbossws-native-3.1.2/modules/testsuite/native-tests/src/test/java/org/jboss/test/ws/common/soap/SOAPElementTestCase.java
===================================================================
---
stack/native/branches/jbossws-native-3.1.2/modules/testsuite/native-tests/src/test/java/org/jboss/test/ws/common/soap/SOAPElementTestCase.java 2009-07-20
15:30:59 UTC (rev 10361)
+++
stack/native/branches/jbossws-native-3.1.2/modules/testsuite/native-tests/src/test/java/org/jboss/test/ws/common/soap/SOAPElementTestCase.java 2009-07-20
16:06:04 UTC (rev 10362)
@@ -123,7 +123,45 @@
}
assertEquals("Strawberry Apple Banana Orange Raspberry ",
sb.toString());
}
+
+ // JBWS-2704
+ public void testGetElementByTagNameNS_Wildcard() throws Exception
+ {
+ InputStream is =
getResourceURL("common/soap/jbws2704.xml").openStream();
+ MessageFactory messageFactory = MessageFactory.newInstance();
+ SOAPMessage soapMessage = messageFactory.createMessage(null, is);
+ SOAPEnvelope envelope = soapMessage.getSOAPPart().getEnvelope();
+ NodeList nodes = envelope.getElementsByTagNameNS("*",
"String_1");
+ assertEquals("String_1 nodes", 2, nodes.getLength());
+ assertEquals("String_1(0) text content", "Value_1",
nodes.item(0).getTextContent());
+ assertEquals("String_1(1) text content", "Value_2",
nodes.item(1).getTextContent());
+
+ nodes = envelope.getElementsByTagNameNS("*", "String_2");
+ assertEquals("String_2 nodes", 2, nodes.getLength());
+ assertEquals("String_2(0) text content", "Value_3",
nodes.item(0).getTextContent());
+ assertEquals("String_2(1) text content", "Value_4",
nodes.item(1).getTextContent());
+
+ nodes = envelope.getElementsByTagNameNS("http://org.jboss.ws/testNS1",
"*");
+ assertEquals("http://org.jboss.ws/testNS1 nodes", 2, nodes.getLength());
+ assertEquals("http://org.jboss.ws/testNS1(0) text content",
"Value_1", nodes.item(0).getTextContent());
+ assertEquals("http://org.jboss.ws/testNS1(1) text content",
"Value_3", nodes.item(1).getTextContent());
+
+ nodes = envelope.getElementsByTagNameNS("http://org.jboss.ws/testNS2",
"*");
+ assertEquals("http://org.jboss.ws/testNS2 nodes", 2, nodes.getLength());
+ assertEquals("http://org.jboss.ws/testNS2(0) text content",
"Value_2", nodes.item(0).getTextContent());
+ assertEquals("http://org.jboss.ws/testNS2(1) text content",
"Value_4", nodes.item(1).getTextContent());
+
+ nodes = envelope.getElementsByTagNameNS("http://org.jboss.ws/testNS1",
"String_1");
+ assertEquals("http://org.jboss.ws/testNS1 String_1 nodes", 1,
nodes.getLength());
+ assertEquals("http://org.jboss.ws/testNS1 String_1(0) text content",
"Value_1", nodes.item(0).getTextContent());
+
+ nodes = envelope.getElementsByTagNameNS("http://org.jboss.ws/testNS2",
"String_1");
+ assertEquals("http://org.jboss.ws/testNS2 String_1 nodes", 1,
nodes.getLength());
+ assertEquals("http://org.jboss.ws/testNS2 String_1(0) text content",
"Value_2", nodes.item(0).getTextContent());
+ }
+
+
//
http://jira.jboss.com/jira/browse/JBWS-773
public void testGetNamespaceURI() throws Exception
{
Copied:
stack/native/branches/jbossws-native-3.1.2/modules/testsuite/native-tests/src/test/resources/common/soap/jbws2704.xml
(from rev 10360,
stack/native/trunk/modules/testsuite/native-tests/src/test/resources/common/soap/jbws2704.xml)
===================================================================
---
stack/native/branches/jbossws-native-3.1.2/modules/testsuite/native-tests/src/test/resources/common/soap/jbws2704.xml
(rev 0)
+++
stack/native/branches/jbossws-native-3.1.2/modules/testsuite/native-tests/src/test/resources/common/soap/jbws2704.xml 2009-07-20
16:06:04 UTC (rev 10362)
@@ -0,0 +1,11 @@
+<soapenv:Envelope
xmlns:soapenv='http://schemas.xmlsoap.org/soap/envelope/'
xmlns:jbw='http://ws.jboss.org/jbws2704'>
+ <soapenv:Header/>
+ <soapenv:Body>
+ <jbw:echo xmlns:ns1='http://org.jboss.ws/testNS1'
xmlns:ns2='http://org.jboss.ws/testNS2'>
+ <ns1:String_1>Value_1</ns1:String_1>
+ <ns2:String_1>Value_2</ns2:String_1>
+ <ns1:String_2>Value_3</ns1:String_2>
+ <ns2:String_2>Value_4</ns2:String_2>
+ </jbw:echo>
+ </soapenv:Body>
+</soapenv:Envelope>