ws-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From veit...@apache.org
Subject svn commit: r1144866 - in /webservices/commons/trunk/modules/axiom/modules: axiom-api/src/main/java/org/apache/axiom/om/ axiom-dom/src/main/java/org/apache/axiom/soap/impl/dom/ axiom-dom/src/test/java/org/apache/axiom/om/impl/dom/ axiom-impl/src/main/j...
Date Sun, 10 Jul 2011 14:37:42 GMT
Author: veithen
Date: Sun Jul 10 14:37:41 2011
New Revision: 1144866

URL: http://svn.apache.org/viewvc?rev=1144866&view=rev
Log:
Partially resynchronized the code in the LLOM and DOOM implementations of SOAPHeader, so that
they support the same set of methods. In particular, this should fix AXIOM-368.

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-dom/src/main/java/org/apache/axiom/soap/impl/dom/SOAPHeaderImpl.java
    webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/test/java/org/apache/axiom/om/impl/dom/SOAPImplementationTest.java
    webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/soap/impl/llom/SOAPHeaderImpl.java
    webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/test/java/org/apache/axiom/om/impl/llom/SOAPImplementationTest.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?rev=1144866&r1=1144865&r2=1144866&view=diff
==============================================================================
--- 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 Jul 10 14:37:41 2011
@@ -57,6 +57,7 @@ public interface OMContainer extends OMS
      * @param elementQName The QName specifying namespace and local name to match.
      * @return Returns an iterator of {@link OMElement} items that match the given QName
      */
+    // TODO: specify whether a null elementQName is allowed; LLOM and DOOM seem to have different
behavior
     Iterator getChildrenWithName(QName elementQName);
     
     /**

Modified: webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/soap/impl/dom/SOAPHeaderImpl.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/soap/impl/dom/SOAPHeaderImpl.java?rev=1144866&r1=1144865&r2=1144866&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/soap/impl/dom/SOAPHeaderImpl.java
(original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/soap/impl/dom/SOAPHeaderImpl.java
Sun Jul 10 14:37:41 2011
@@ -25,20 +25,205 @@ import org.apache.axiom.om.OMNamespace;
 import org.apache.axiom.om.OMNode;
 import org.apache.axiom.om.OMXMLParserWrapper;
 import org.apache.axiom.om.impl.OMNodeEx;
-import org.apache.axiom.om.impl.dom.ElementImpl;
+import org.apache.axiom.soap.RolePlayer;
+import org.apache.axiom.soap.SOAP12Constants;
+import org.apache.axiom.soap.SOAP12Version;
 import org.apache.axiom.soap.SOAPConstants;
 import org.apache.axiom.soap.SOAPEnvelope;
 import org.apache.axiom.soap.SOAPFactory;
 import org.apache.axiom.soap.SOAPHeader;
 import org.apache.axiom.soap.SOAPHeaderBlock;
 import org.apache.axiom.soap.SOAPProcessingException;
-import org.apache.axiom.soap.RolePlayer;
+import org.apache.axiom.soap.SOAPVersion;
 
 import java.util.ArrayList;
-import java.util.Collection;
 import java.util.Iterator;
+import java.util.List;
+
+/**
+ * A local interface we can use to make "header checker" objects which can be used by
+ * HeaderIterators to filter results.  This really SHOULD be done with anonymous classes:
+ * <p/>
+ * public void getHeadersByRole(final String role) {
+ *     return new HeaderIterator() {
+ *         public boolean checkHeader(SOAPHeaderBlock header) {
+ *             ...
+ *             if (role.equals(headerRole)) return true;
+ *             return false;
+ *         }
+ *     }
+ * }
+ * <p/>
+ * ...but there appears to be some kind of weird problem with the JVM not correctly scoping
the
+ * passed "role" value in a situation like the above.  As such, we have to make Checker objects
+ * instead (sigh).
+ */
+interface Checker {
+    boolean checkHeader(SOAPHeaderBlock header);
+}
+
+/**
+ * A Checker to make sure headers match a given role.  If the role we're looking for is null,
then
+ * everything matches.
+ */
+class RoleChecker implements Checker {
+    String role;
+
+    public RoleChecker(String role) {
+        this.role = role;
+    }
+
+    public boolean checkHeader(SOAPHeaderBlock header) {
+        if (role == null) {
+            return true;
+        }
+        String thisRole = header.getRole();
+        return (role.equals(thisRole));
+    }
+}
+
+/**
+ * This Checker uses a RolePlayer to return the appropriate headers for that RolePlayer to
process.
+ * Ignore "none", always "next", etc.
+ */
+class RolePlayerChecker implements Checker {
+    RolePlayer rolePlayer;
+
+    /** Optional namespace - if non-null we'll only return headers that match */
+    String namespace;
+
+    /**
+     * Constructor.
+     *
+     * @param rolePlayer the RolePlayer to check against.  This can be null, in which
+     *                   case we assume we're the ultimate destination.
+     */
+    public RolePlayerChecker(RolePlayer rolePlayer) {
+        this.rolePlayer = rolePlayer;
+    }
+
+    public RolePlayerChecker(RolePlayer rolePlayer, String namespace) {
+        this.rolePlayer = rolePlayer;
+        this.namespace = namespace;
+    }
+
+    public boolean checkHeader(SOAPHeaderBlock header) {
+        // If we're filtering on namespace, check that first since the compare is simpler.
+        if (namespace != null) {
+            OMNamespace headerNamespace = header.getNamespace();
+            if (headerNamespace == null || !namespace.equals(headerNamespace.getNamespaceURI()))
{
+                return false;
+            }
+        }
+
+        String role = header.getRole();
+        SOAPVersion version = header.getVersion();
+
+        // 1. If role is ultimatedest, go by what the rolePlayer says
+        if (role == null || role.equals("") ||
+                (version instanceof SOAP12Version &&
+                        role.equals(SOAP12Constants.SOAP_ROLE_ULTIMATE_RECEIVER))) {
+            return (rolePlayer == null || rolePlayer.isUltimateDestination());
+        }
+
+        // 2. If role is next, always return true
+        if (role.equals(version.getNextRoleURI())) return true;
+
+        // 3. If role is none, always return false
+        if (version instanceof SOAP12Version &&
+                role.equals(SOAP12Constants.SOAP_ROLE_NONE)) {
+            return false;
+        }
+
+        // 4. Return t/f depending on match
+        List roles = (rolePlayer == null) ? null : rolePlayer.getRoles();
+        if (roles != null) {
+            for (Iterator i = roles.iterator(); i.hasNext();) {
+                String thisRole = (String) i.next();
+                if (thisRole.equals(role)) return true;
+            }
+        }
+
+        return false;
+    }
+}
+
+/** A Checker to see that we both match a given role AND are mustUnderstand=true */
+class MURoleChecker extends RoleChecker {
+    public MURoleChecker(String role) {
+        super(role);
+    }
+
+    public boolean checkHeader(SOAPHeaderBlock header) {
+        if (header.getMustUnderstand())
+            return super.checkHeader(header);
+        return false;
+    }
+}
 
 public abstract class SOAPHeaderImpl extends SOAPElement implements SOAPHeader {
+    
+    /** An Iterator which walks the header list as needed, potentially filtering as we traverse.
*/
+    class HeaderIterator implements Iterator {
+        SOAPHeaderBlock current;
+        boolean advance = false;
+        Checker checker;
+
+        public HeaderIterator() {
+            this(null);
+        }
+
+        public HeaderIterator(Checker checker) {
+            this.checker = checker;
+            current = (SOAPHeaderBlock) getFirstElement();
+            if (current != null) {
+                if (!checkHeader(current)) {
+                    advance = true;
+                    hasNext();
+                }
+            }
+        }
+
+        public void remove() {
+        }
+
+        public boolean checkHeader(SOAPHeaderBlock header) {
+            if (checker == null) return true;
+            return checker.checkHeader(header);
+        }
+
+        public boolean hasNext() {
+            if (!advance) {
+                return current != null;
+            }
+
+            advance = false;
+            OMNode sibling = current.getNextOMSibling();
+
+            while (sibling != null) {
+                if (sibling instanceof SOAPHeaderBlock) {
+                    SOAPHeaderBlock possible = (SOAPHeaderBlock) sibling;
+                    if (checkHeader(possible)) {
+                        current = (SOAPHeaderBlock) sibling;
+                        return true;
+                    }
+                }
+                sibling = sibling.getNextOMSibling();
+            }
+
+            current = null;
+            return false;
+        }
+
+        public Object next() {
+            SOAPHeaderBlock ret = current;
+            if (ret != null) {
+                advance = true;
+                hasNext();
+            }
+            return ret;
+        }
+    }
 
 
     /** @param envelope  */
@@ -85,86 +270,21 @@ public abstract class SOAPHeaderImpl ext
     protected abstract SOAPHeaderBlock createHeaderBlock(String localname, OMNamespace ns);
     
     public Iterator getHeadersToProcess(RolePlayer rolePlayer) {
-        return null; // TODO: Implement this!
+        return new HeaderIterator(new RolePlayerChecker(rolePlayer));
     }
 
     public Iterator getHeadersToProcess(RolePlayer rolePlayer, String namespace) {
-        return null; // TODO: Implement this!    
+        return new HeaderIterator(new RolePlayerChecker(rolePlayer, namespace));
     }
 
-    public Iterator examineHeaderBlocks(String paramRole) {
-        /* Iterator headerBlocksIter = this.getChildren();
-       ArrayList headersWithGivenActor = new ArrayList();
-
-       if (paramRole == null || "".equals(paramRole)) {
-           return returnAllSOAPHeaders(this.getChildren());
-       }
-
-       while (headerBlocksIter.hasNext()) {
-           Object o = headerBlocksIter.next();
-           if (o instanceof SOAPHeaderBlock) {
-               SOAPHeaderBlock soapHeaderBlock = (SOAPHeaderBlock) o;
-               String role = soapHeaderBlock.getRole();
-               if ((role != null) && role.equalsIgnoreCase(paramRole)) {
-                   headersWithGivenActor.add(soapHeaderBlock);
-               }
-           }
-       }
-       return headersWithGivenActor.iterator();*/
-
-        if (paramRole == null || paramRole.trim().length() == 0) {
-            return examineAllHeaderBlocks();
-        }
-        Collection elements = new ArrayList();
-        for (Iterator iter = examineAllHeaderBlocks(); iter.hasNext();) {
-            SOAPHeaderBlock headerBlock = (SOAPHeaderBlock) iter.next();
-            /*
-            if (headerBlock.getRole() == null ||
-                headerBlock.getRole().trim().length() == 0 ||
-                headerBlock.getRole().equals(paramRole)) {
-                elements.add(headerBlock);
-            }
-            */
-            if (headerBlock.getRole() != null &&
-                    headerBlock.getRole().trim().length() > 0 &&
-                    headerBlock.getRole().equals(paramRole)) {
-                elements.add(headerBlock);
-            }
-
-        }
-        return elements.iterator();
-    }
-
-//    private Iterator returnAllSOAPHeaders(Iterator children) {
-//        ArrayList headers = new ArrayList();
-//        while (children.hasNext()) {
-//            Object o = children.next();
-//            if (o instanceof SOAPHeaderBlock) {
-//                headers.add(o);
-//            }
-//        }
-//
-//        return headers.iterator();
-//
-//    }
+    public Iterator examineHeaderBlocks(String role) {
+        return new HeaderIterator(new RoleChecker(role));
+    }
 
     public abstract Iterator extractHeaderBlocks(String role);
 
     public Iterator examineMustUnderstandHeaderBlocks(String actor) {
-        Iterator headerBlocksIter = this.getChildren();
-        ArrayList mustUnderstandHeadersWithGivenActor = new ArrayList();
-        while (headerBlocksIter.hasNext()) {
-            Object o = headerBlocksIter.next();
-            if (o instanceof SOAPHeaderBlock) {
-                SOAPHeaderBlock soapHeaderBlock = (SOAPHeaderBlock) o;
-                String role = soapHeaderBlock.getRole();
-                boolean mustUnderstand = soapHeaderBlock.getMustUnderstand();
-                if ((role != null) && role.equals(actor) && mustUnderstand)
{
-                    mustUnderstandHeadersWithGivenActor.add(soapHeaderBlock);
-                }
-            }
-        }
-        return mustUnderstandHeadersWithGivenActor.iterator();
+        return new HeaderIterator(new MURoleChecker(actor));
     }
 
     public Iterator examineAllHeaderBlocks() {
@@ -172,9 +292,9 @@ public abstract class SOAPHeaderImpl ext
     }
 
     public Iterator extractAllHeaderBlocks() {
-        Collection result = new ArrayList();
-        for (Iterator iter = getChildrenWithName(null); iter.hasNext();) {
-            ElementImpl headerBlock = (ElementImpl) iter.next();
+        List result = new ArrayList();
+        for (Iterator iter = getChildElements(); iter.hasNext();) {
+            OMElement headerBlock = (OMElement) iter.next();
             iter.remove();
             result.add(headerBlock);
         }

Modified: webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/test/java/org/apache/axiom/om/impl/dom/SOAPImplementationTest.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/test/java/org/apache/axiom/om/impl/dom/SOAPImplementationTest.java?rev=1144866&r1=1144865&r2=1144866&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/test/java/org/apache/axiom/om/impl/dom/SOAPImplementationTest.java
(original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/test/java/org/apache/axiom/om/impl/dom/SOAPImplementationTest.java
Sun Jul 10 14:37:41 2011
@@ -26,7 +26,6 @@ import org.apache.axiom.ts.SOAPTestSuite
 import org.apache.axiom.ts.soap.factory.TestGetDefaultFaultEnvelope;
 import org.apache.axiom.ts.soap.faultdetail.TestWSCommons202;
 import org.apache.axiom.ts.soap.faulttext.TestSetLang;
-import org.apache.axiom.ts.soap.header.TestGetHeadersToProcessWithNamespace;
 import org.apache.axiom.ts.soap12.fault.TestMoreChildrenAddition;
 
 public class SOAPImplementationTest extends TestCase {
@@ -38,10 +37,6 @@ public class SOAPImplementationTest exte
         // TODO: not sure if this is an issue in DOOM or if the test case is wrong
         builder.exclude(TestMoreChildrenAddition.class);
         
-        builder.exclude(TestGetHeadersToProcessWithNamespace.class);
-        builder.exclude(org.apache.axiom.ts.soap11.header.TestGetHeadersToProcessWithParser.class);
-        builder.exclude(org.apache.axiom.ts.soap12.header.TestGetHeadersToProcessWithParser.class);
-        
         // SOAPFaultText is currently unsupported in DOOM
         builder.exclude(TestSetLang.class);
         

Modified: webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/soap/impl/llom/SOAPHeaderImpl.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/soap/impl/llom/SOAPHeaderImpl.java?rev=1144866&r1=1144865&r2=1144866&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/soap/impl/llom/SOAPHeaderImpl.java
(original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/soap/impl/llom/SOAPHeaderImpl.java
Sun Jul 10 14:37:41 2011
@@ -284,13 +284,13 @@ public abstract class SOAPHeaderImpl ext
         return new HeaderIterator(new RolePlayerChecker(rolePlayer, namespace));
     }
 
-    public Iterator examineHeaderBlocks(final String role) {
+    public Iterator examineHeaderBlocks(String role) {
         return new HeaderIterator(new RoleChecker(role));
     }
 
     public abstract Iterator extractHeaderBlocks(String role);
 
-    public Iterator examineMustUnderstandHeaderBlocks(final String actor) {
+    public Iterator examineMustUnderstandHeaderBlocks(String actor) {
         return new HeaderIterator(new MURoleChecker(actor));
     }
 
@@ -305,7 +305,13 @@ public abstract class SOAPHeaderImpl ext
     }
 
     public Iterator extractAllHeaderBlocks() {
-        throw new UnsupportedOperationException(); // TODO implement this
+        List result = new ArrayList();
+        for (Iterator iter = getChildElements(); iter.hasNext();) {
+            OMElement headerBlock = (OMElement) iter.next();
+            iter.remove();
+            result.add(headerBlock);
+        }
+        return result.iterator();
     }
 
     public ArrayList getHeaderBlocksWithNSURI(String nsURI) {

Modified: webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/test/java/org/apache/axiom/om/impl/llom/SOAPImplementationTest.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/test/java/org/apache/axiom/om/impl/llom/SOAPImplementationTest.java?rev=1144866&r1=1144865&r2=1144866&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/test/java/org/apache/axiom/om/impl/llom/SOAPImplementationTest.java
(original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/test/java/org/apache/axiom/om/impl/llom/SOAPImplementationTest.java
Sun Jul 10 14:37:41 2011
@@ -23,15 +23,10 @@ import junit.framework.TestSuite;
 
 import org.apache.axiom.om.impl.llom.factory.OMLinkedListMetaFactory;
 import org.apache.axiom.ts.SOAPTestSuiteBuilder;
-import org.apache.axiom.ts.soap.header.TestExtractAllHeaderBlocks;
 
 public class SOAPImplementationTest extends TestCase {
     public static TestSuite suite() {
         SOAPTestSuiteBuilder builder = new SOAPTestSuiteBuilder(new OMLinkedListMetaFactory());
-        
-        // TODO: unsupported in LLOM
-        builder.exclude(TestExtractAllHeaderBlocks.class);
-        
         return builder.build();
     }
 }



Mime
View raw message