Author: gdaniels
Date: Sun Mar 25 06:13:03 2007
New Revision: 522259
URL: http://svn.apache.org/viewvc?view=rev&rev=522259
Log:
Fix logic in OMChildrenQNameIterator to match on both namespace and localName.
Toss exceptions upwards in tests as per usual.
Modified:
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/OMContainer.java
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/traverse/OMChildrenQNameIterator.java
webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/om/IteratorTest.java
Modified:
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/OMContainer.java
URL:
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/OMContainer.java?view=diff&rev=522259&r1=522258&r2=522259
==============================================================================
---
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/OMContainer.java
(original)
+++
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/OMContainer.java
Sun Mar 25 06:13:03 2007
@@ -35,27 +35,16 @@
void addChild(OMNode omNode);
/**
- * Returns an iterator for child nodes matching the criteria indicated by
the given QName.
+ * Returns an iterator for child nodes matching the given QName.
* <p/>
- * <p>This function searches in three ways: <ul> <li>Exact match - Both
parts of the passed
- * QName are non-null. Only children with the same namespace and local
name will be returned.
- * </li> <li>Namespace match - The local name of the passed QName is null.
All children
- * matching the namespace will be returned by the iterator. </li>
<li>Local name match - The
- * namespace of the passed QName is null. All children with the matching
local name will be
- * returned by the iterator. </li> </ul>
- * <p/>
- * <p/>
- * <b>Example:</b> <code>header.getChildrenWithName( new
QName(ADDRESSING_NAMESPACE,
- * null));</code> will return all of the "addressing" headers. </p>
*
* @param elementQName The QName specifying namespace and local name to
match.
* @return Returns an iterator of [EMAIL PROTECTED] OMElement} items that
match the given QName
- * appropriately.
*/
Iterator getChildrenWithName(QName elementQName);
/**
- * Returns the first child in document order that matches the given QName
criteria.
+ * Returns the first child in document order that matches the given QName
* <p/>
* <p>The QName filter is applied as in the function [EMAIL PROTECTED]
#getChildrenWithName}.</p>
*
Modified:
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/traverse/OMChildrenQNameIterator.java
URL:
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/traverse/OMChildrenQNameIterator.java?view=diff&rev=522259&r1=522258&r2=522259
==============================================================================
---
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/traverse/OMChildrenQNameIterator.java
(original)
+++
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/traverse/OMChildrenQNameIterator.java
Sun Mar 25 06:13:03 2007
@@ -52,21 +52,19 @@
public boolean hasNext() {
while (needToMoveForward) {
if (currentChild != null) {
-
// check the current node for the criteria
- if ((currentChild instanceof OMElement)
- && (isQNamesMatch(
- ((OMElement) currentChild).getQName(),
- this.givenQName))) {
- isMatchingNodeFound = true;
- needToMoveForward = false;
- } else {
-
- // get the next named node
- currentChild = currentChild.getNextOMSibling();
- isMatchingNodeFound = needToMoveForward = !(currentChild
- == null);
+ if (currentChild instanceof OMElement) {
+ QName thisQName = ((OMElement)currentChild).getQName();
+ if (thisQName.equals(givenQName)) {
+ isMatchingNodeFound = true;
+ needToMoveForward = false;
+ break;
+ }
}
+
+ // get the next named node
+ currentChild = currentChild.getNextOMSibling();
+ isMatchingNodeFound = needToMoveForward = !(currentChild ==
null);
} else {
needToMoveForward = false;
}
@@ -91,41 +89,5 @@
lastChild = currentChild;
currentChild = currentChild.getNextOMSibling();
return lastChild;
- }
-
- /**
- * Cannot use the overridden equals method of QName, as one might want to
get some element just
- * by giving the localname, even though a matching element has a namespace
uri as well. This is
- * not supported in the equals method of the QName.
- *
- * @param elementQName
- * @param qNameToBeMatched
- * @return Returns boolean.
- */
- private boolean isQNamesMatch(QName elementQName, QName qNameToBeMatched) {
-
- // if no QName was given, that means user is asking for all
- if (qNameToBeMatched == null) {
- return true;
- }
-
- // if the given localname is null, whatever value this.qname has, its
a match. But can one give a QName without a localName ??
- String localPart = qNameToBeMatched.getLocalPart();
- boolean localNameMatch =
- (localPart == null)
- || (localPart.equals(""))
- ||
- ((elementQName != null)
- &&
- elementQName.getLocalPart().equals(localPart));
- String namespaceURI = qNameToBeMatched.getNamespaceURI();
- boolean namespaceURIMatch =
- (namespaceURI == null)
- || (namespaceURI.equals(""))
- ||
- ((elementQName != null)
- &&
-
elementQName.getNamespaceURI().equals(namespaceURI));
- return localNameMatch && namespaceURIMatch;
}
}
Modified:
webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/om/IteratorTest.java
URL:
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/om/IteratorTest.java?view=diff&rev=522259&r1=522258&r2=522259
==============================================================================
---
webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/om/IteratorTest.java
(original)
+++
webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/om/IteratorTest.java
Sun Mar 25 06:13:03 2007
@@ -176,44 +176,31 @@
}
/** This will test the errrors mentioned in @link
http://issues.apache.org/jira/browse/WSCOMMONS-12 */
- public void testScenariosInJIRA() {
- try {
- OMElement mtomSampleElement = createSampleXMLForTesting();
- testScenarioOne(mtomSampleElement);
- testScenarioTwo(mtomSampleElement);
-
-
- } catch (Exception e) {
- fail("Exception occurred whilst running the test " + e);
- }
-
+ public void testScenariosInJIRA() throws Exception {
+ OMElement mtomSampleElement = createSampleXMLForTesting();
+ testScenarioOne(mtomSampleElement);
+ testScenarioTwo(mtomSampleElement);
}
private OMElement createSampleXMLForTesting() throws Exception {
- try {
- File imageSource = new File("test-resources/mtom/img/test.jpg");
- OMFactory fac = OMAbstractFactory.getOMFactory();
- OMNamespace omNs = fac.createOMNamespace("http://localhost/my",
"my");
-
- OMElement data = fac.createOMElement("mtomSample", omNs);
- OMElement image = fac.createOMElement("image", omNs);
-
- FileDataSource dataSource = new FileDataSource(imageSource);
- DataHandler expectedDH = new DataHandler(dataSource);
- OMText textData = fac.createOMText(expectedDH, true);
- image.addChild(textData);
-
- OMElement imageName = fac.createOMElement("fileName", omNs);
- imageName.setText(imageSource.getAbsolutePath());
- data.addChild(image);
- data.addChild(imageName);
-
- return data;
- } catch (Exception e) {
- e.printStackTrace();
- }
+ File imageSource = new File("test-resources/mtom/img/test.jpg");
+ OMFactory fac = OMAbstractFactory.getOMFactory();
+ OMNamespace omNs = fac.createOMNamespace("http://localhost/my", "my");
+
+ OMElement data = fac.createOMElement("mtomSample", omNs);
+ OMElement image = fac.createOMElement("image", omNs);
+
+ FileDataSource dataSource = new FileDataSource(imageSource);
+ DataHandler expectedDH = new DataHandler(dataSource);
+ OMText textData = fac.createOMText(expectedDH, true);
+ image.addChild(textData);
+
+ OMElement imageName = fac.createOMElement("fileName", omNs);
+ imageName.setText(imageSource.getAbsolutePath());
+ data.addChild(image);
+ data.addChild(imageName);
- return null;
+ return data;
}
private void testScenarioOne(OMElement mtomSampleElement) {
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]