Author: scheu
Date: Wed Dec 16 16:29:34 2009
New Revision: 891290

URL: http://svn.apache.org/viewvc?rev=891290&view=rev
Log:
WSCOMMONS-512
Contributor:Rich Scheuerle
Corrected code for the case where the parser switch occurs directly after the 
OMSourcedElement
Added a validation test.

Modified:
    
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/OMNavigator.java
    
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/SwitchingWrapper.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/OMNavigator.java
URL: 
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/OMNavigator.java?rev=891290&r1=891289&r2=891290&view=diff
==============================================================================
--- 
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/OMNavigator.java
 (original)
+++ 
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/OMNavigator.java
 Wed Dec 16 16:29:34 2009
@@ -153,12 +153,12 @@
      */
     private boolean isLeaf(OMNode n) {
         if (n instanceof OMElement) {
-            if (this.isDataSourceALeaf && (n instanceof OMSourcedElement)) {
+            if (this.isDataSourceALeaf && (n instanceof OMSourcedElement) && n 
!= root) {
                 OMDataSource ds = null;
                 try {
                     ds = ((OMSourcedElement) n).getDataSource();
                 } catch (UnsupportedOperationException e) {
-                    ; // Operation unsupported for DOM impl
+                    ; // Operation unsupported for some implementations
                 }
                 if (ds != null) {
                     return true;

Modified: 
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/SwitchingWrapper.java
URL: 
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/SwitchingWrapper.java?rev=891290&r1=891289&r2=891290&view=diff
==============================================================================
--- 
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/SwitchingWrapper.java
 (original)
+++ 
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/SwitchingWrapper.java
 Wed Dec 16 16:29:34 2009
@@ -1558,12 +1558,18 @@
      * @return OMDataSource associated with the current node or Null
      */
     public OMDataSource getDataSource() {
+        if (getEventType() != XMLStreamReader.START_ELEMENT ||
+                !(state == this.NAVIGABLE || 
+                  state == this.SWITCH_AT_NEXT)) {
+            return null;
+        }
         OMDataSource ds = null;
         if (lastNode != null &&
             lastNode instanceof OMSourcedElement) {
             try {
                 ds = ((OMSourcedElement) lastNode).getDataSource();
             } catch (UnsupportedOperationException e) {
+                // Some implementations throw an UnsupportedOperationException.
                 ds =null;
             }
             if (log.isDebugEnabled()) {

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?rev=891290&r1=891289&r2=891290&view=diff
==============================================================================
--- 
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
 Wed Dec 16 16:29:34 2009
@@ -297,9 +297,13 @@
         String outputString = new String(byteArrayOutputStream.toByteArray());
         assertTrue("Expected output was incorrect.  Received:" + outputString,
                 outputString != null && !"".equals(outputString) && 
outputString.length() > 1);
+        int indexHelloWorld = outputString.indexOf("Hello World");
         assertTrue("Expected output was incorrect.  Received:" + outputString,
-                outputString.contains("Hello World"));
-        
+                indexHelloWorld > 0);
+        int indexHelloWorld2 = outputString.indexOf("Hello World", 
indexHelloWorld+1);
+        assertTrue("Expected output was incorrect.  Received:" + outputString,
+                indexHelloWorld2 < 0);
+
         assertTrue("Expectation is that an OMSourcedElement was created for 
the payload", 
                 omse != null);
         assertTrue("Expectation is that the OMSourcedElement was not expanded 
by serialization ", 


Reply via email to