You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ws.apache.org by ve...@apache.org on 2011/12/16 00:22:17 UTC

svn commit: r1214989 - in /webservices/commons/trunk/modules/axiom/modules: axiom-common-impl/src/main/java/org/apache/axiom/soap/ axiom-common-impl/src/main/java/org/apache/axiom/soap/impl/ axiom-common-impl/src/main/java/org/apache/axiom/soap/impl/co...

Author: veithen
Date: Thu Dec 15 23:22:16 2011
New Revision: 1214989

URL: http://svn.apache.org/viewvc?rev=1214989&view=rev
Log:
Some duplicate code reduction.

Added:
    webservices/commons/trunk/modules/axiom/modules/axiom-common-impl/src/main/java/org/apache/axiom/soap/
    webservices/commons/trunk/modules/axiom/modules/axiom-common-impl/src/main/java/org/apache/axiom/soap/impl/
    webservices/commons/trunk/modules/axiom/modules/axiom-common-impl/src/main/java/org/apache/axiom/soap/impl/common/
    webservices/commons/trunk/modules/axiom/modules/axiom-common-impl/src/main/java/org/apache/axiom/soap/impl/common/Checker.java   (with props)
    webservices/commons/trunk/modules/axiom/modules/axiom-common-impl/src/main/java/org/apache/axiom/soap/impl/common/HeaderIterator.java   (with props)
    webservices/commons/trunk/modules/axiom/modules/axiom-common-impl/src/main/java/org/apache/axiom/soap/impl/common/MURoleChecker.java   (with props)
    webservices/commons/trunk/modules/axiom/modules/axiom-common-impl/src/main/java/org/apache/axiom/soap/impl/common/RoleChecker.java   (with props)
    webservices/commons/trunk/modules/axiom/modules/axiom-common-impl/src/main/java/org/apache/axiom/soap/impl/common/RolePlayerChecker.java   (with props)
Modified:
    webservices/commons/trunk/modules/axiom/modules/axiom-dom/pom.xml
    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-impl/pom.xml
    webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/soap/impl/llom/SOAPHeaderImpl.java

Added: webservices/commons/trunk/modules/axiom/modules/axiom-common-impl/src/main/java/org/apache/axiom/soap/impl/common/Checker.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-common-impl/src/main/java/org/apache/axiom/soap/impl/common/Checker.java?rev=1214989&view=auto
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-common-impl/src/main/java/org/apache/axiom/soap/impl/common/Checker.java (added)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-common-impl/src/main/java/org/apache/axiom/soap/impl/common/Checker.java Thu Dec 15 23:22:16 2011
@@ -0,0 +1,43 @@
+/*
+ * 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.axiom.soap.impl.common;
+
+import org.apache.axiom.soap.SOAPHeaderBlock;
+
+/**
+ * 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).
+ */
+public interface Checker {
+    boolean checkHeader(SOAPHeaderBlock header);
+}

Propchange: webservices/commons/trunk/modules/axiom/modules/axiom-common-impl/src/main/java/org/apache/axiom/soap/impl/common/Checker.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: webservices/commons/trunk/modules/axiom/modules/axiom-common-impl/src/main/java/org/apache/axiom/soap/impl/common/HeaderIterator.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-common-impl/src/main/java/org/apache/axiom/soap/impl/common/HeaderIterator.java?rev=1214989&view=auto
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-common-impl/src/main/java/org/apache/axiom/soap/impl/common/HeaderIterator.java (added)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-common-impl/src/main/java/org/apache/axiom/soap/impl/common/HeaderIterator.java Thu Dec 15 23:22:16 2011
@@ -0,0 +1,87 @@
+/*
+ * 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.axiom.soap.impl.common;
+
+import java.util.Iterator;
+
+import org.apache.axiom.om.OMNode;
+import org.apache.axiom.soap.SOAPHeader;
+import org.apache.axiom.soap.SOAPHeaderBlock;
+
+/** An Iterator which walks the header list as needed, potentially filtering as we traverse. */
+public class HeaderIterator implements Iterator {
+    SOAPHeaderBlock current;
+    boolean advance = false;
+    Checker checker;
+
+    public HeaderIterator(SOAPHeader header) {
+        this(header, null);
+    }
+
+    public HeaderIterator(SOAPHeader header, Checker checker) {
+        this.checker = checker;
+        current = (SOAPHeaderBlock) header.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;
+    }
+}
\ No newline at end of file

Propchange: webservices/commons/trunk/modules/axiom/modules/axiom-common-impl/src/main/java/org/apache/axiom/soap/impl/common/HeaderIterator.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: webservices/commons/trunk/modules/axiom/modules/axiom-common-impl/src/main/java/org/apache/axiom/soap/impl/common/MURoleChecker.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-common-impl/src/main/java/org/apache/axiom/soap/impl/common/MURoleChecker.java?rev=1214989&view=auto
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-common-impl/src/main/java/org/apache/axiom/soap/impl/common/MURoleChecker.java (added)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-common-impl/src/main/java/org/apache/axiom/soap/impl/common/MURoleChecker.java Thu Dec 15 23:22:16 2011
@@ -0,0 +1,34 @@
+/*
+ * 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.axiom.soap.impl.common;
+
+import org.apache.axiom.soap.SOAPHeaderBlock;
+
+/** A Checker to see that we both match a given role AND are mustUnderstand=true */
+public class MURoleChecker extends RoleChecker {
+    public MURoleChecker(String role) {
+        super(role);
+    }
+
+    public boolean checkHeader(SOAPHeaderBlock header) {
+        if (header.getMustUnderstand())
+            return super.checkHeader(header);
+        return false;
+    }
+}

Propchange: webservices/commons/trunk/modules/axiom/modules/axiom-common-impl/src/main/java/org/apache/axiom/soap/impl/common/MURoleChecker.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: webservices/commons/trunk/modules/axiom/modules/axiom-common-impl/src/main/java/org/apache/axiom/soap/impl/common/RoleChecker.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-common-impl/src/main/java/org/apache/axiom/soap/impl/common/RoleChecker.java?rev=1214989&view=auto
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-common-impl/src/main/java/org/apache/axiom/soap/impl/common/RoleChecker.java (added)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-common-impl/src/main/java/org/apache/axiom/soap/impl/common/RoleChecker.java Thu Dec 15 23:22:16 2011
@@ -0,0 +1,41 @@
+/*
+ * 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.axiom.soap.impl.common;
+
+import org.apache.axiom.soap.SOAPHeaderBlock;
+
+/**
+ * A Checker to make sure headers match a given role.  If the role we're looking for is null, then
+ * everything matches.
+ */
+public 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));
+    }
+}

Propchange: webservices/commons/trunk/modules/axiom/modules/axiom-common-impl/src/main/java/org/apache/axiom/soap/impl/common/RoleChecker.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: webservices/commons/trunk/modules/axiom/modules/axiom-common-impl/src/main/java/org/apache/axiom/soap/impl/common/RolePlayerChecker.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-common-impl/src/main/java/org/apache/axiom/soap/impl/common/RolePlayerChecker.java?rev=1214989&view=auto
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-common-impl/src/main/java/org/apache/axiom/soap/impl/common/RolePlayerChecker.java (added)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-common-impl/src/main/java/org/apache/axiom/soap/impl/common/RolePlayerChecker.java Thu Dec 15 23:22:16 2011
@@ -0,0 +1,95 @@
+/*
+ * 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.axiom.soap.impl.common;
+
+import java.util.Iterator;
+import java.util.List;
+
+import org.apache.axiom.om.OMNamespace;
+import org.apache.axiom.soap.RolePlayer;
+import org.apache.axiom.soap.SOAP12Constants;
+import org.apache.axiom.soap.SOAP12Version;
+import org.apache.axiom.soap.SOAPHeaderBlock;
+import org.apache.axiom.soap.SOAPVersion;
+
+/**
+ * This Checker uses a RolePlayer to return the appropriate headers for that RolePlayer to process.
+ * Ignore "none", always "next", etc.
+ */
+public 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;
+    }
+}

Propchange: webservices/commons/trunk/modules/axiom/modules/axiom-common-impl/src/main/java/org/apache/axiom/soap/impl/common/RolePlayerChecker.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: webservices/commons/trunk/modules/axiom/modules/axiom-dom/pom.xml
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-dom/pom.xml?rev=1214989&r1=1214988&r2=1214989&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-dom/pom.xml (original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-dom/pom.xml Thu Dec 15 23:22:16 2011
@@ -168,6 +168,10 @@
                                     <pattern>org.apache.axiom.om.impl.common</pattern>
                                     <shadedPattern>org.apache.axiom.om.impl.dom</shadedPattern>
                                 </relocation>
+                                <relocation>
+                                    <pattern>org.apache.axiom.soap.impl.common</pattern>
+                                    <shadedPattern>org.apache.axiom.soap.impl.dom</shadedPattern>
+                                </relocation>
                             </relocations>
                             <transformers>
                                 <transformer implementation="org.apache.axiom.buildutils.OSGiManifestResourceTransformer" />

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=1214989&r1=1214988&r2=1214989&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 Thu Dec 15 23:22:16 2011
@@ -26,206 +26,22 @@ import org.apache.axiom.om.OMNode;
 import org.apache.axiom.om.OMXMLParserWrapper;
 import org.apache.axiom.om.impl.OMNodeEx;
 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.SOAPVersion;
+import org.apache.axiom.soap.impl.common.HeaderIterator;
+import org.apache.axiom.soap.impl.common.MURoleChecker;
+import org.apache.axiom.soap.impl.common.RoleChecker;
+import org.apache.axiom.soap.impl.common.RolePlayerChecker;
 
 import java.util.ArrayList;
 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  */
     public SOAPHeaderImpl(SOAPEnvelope envelope, SOAPFactory factory)
             throws SOAPProcessingException {
@@ -270,21 +86,21 @@ public abstract class SOAPHeaderImpl ext
     protected abstract SOAPHeaderBlock createHeaderBlock(String localname, OMNamespace ns);
     
     public Iterator getHeadersToProcess(RolePlayer rolePlayer) {
-        return new HeaderIterator(new RolePlayerChecker(rolePlayer));
+        return new HeaderIterator(this, new RolePlayerChecker(rolePlayer));
     }
 
     public Iterator getHeadersToProcess(RolePlayer rolePlayer, String namespace) {
-        return new HeaderIterator(new RolePlayerChecker(rolePlayer, namespace));
+        return new HeaderIterator(this, new RolePlayerChecker(rolePlayer, namespace));
     }
 
     public Iterator examineHeaderBlocks(String role) {
-        return new HeaderIterator(new RoleChecker(role));
+        return new HeaderIterator(this, new RoleChecker(role));
     }
 
     public abstract Iterator extractHeaderBlocks(String role);
 
     public Iterator examineMustUnderstandHeaderBlocks(String actor) {
-        return new HeaderIterator(new MURoleChecker(actor));
+        return new HeaderIterator(this, new MURoleChecker(actor));
     }
 
     public Iterator examineAllHeaderBlocks() {

Modified: webservices/commons/trunk/modules/axiom/modules/axiom-impl/pom.xml
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-impl/pom.xml?rev=1214989&r1=1214988&r2=1214989&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-impl/pom.xml (original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-impl/pom.xml Thu Dec 15 23:22:16 2011
@@ -152,6 +152,12 @@
                                     <shadedPattern>org.apache.axiom.om.impl.llom</shadedPattern>
                                 </relocation>
                             </relocations>
+                            <relocations>
+                                <relocation>
+                                    <pattern>org.apache.axiom.soap.impl.common</pattern>
+                                    <shadedPattern>org.apache.axiom.soap.impl.llom</shadedPattern>
+                                </relocation>
+                            </relocations>
                             <transformers>
                                 <transformer implementation="org.apache.axiom.buildutils.OSGiManifestResourceTransformer" />
                             </transformers>

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=1214989&r1=1214988&r2=1214989&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 Thu Dec 15 23:22:16 2011
@@ -26,15 +26,17 @@ import org.apache.axiom.om.OMNode;
 import org.apache.axiom.om.OMXMLParserWrapper;
 import org.apache.axiom.om.impl.OMNodeEx;
 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.SOAPVersion;
+import org.apache.axiom.soap.impl.common.Checker;
+import org.apache.axiom.soap.impl.common.HeaderIterator;
+import org.apache.axiom.soap.impl.common.MURoleChecker;
+import org.apache.axiom.soap.impl.common.RoleChecker;
+import org.apache.axiom.soap.impl.common.RolePlayerChecker;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 
@@ -42,194 +44,10 @@ import java.util.ArrayList;
 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;
-    }
-}
-
 /** A class representing the SOAP Header, primarily allowing access to the contained HeaderBlocks. */
 public abstract class SOAPHeaderImpl extends SOAPElement implements SOAPHeader {
     
     static Log log = LogFactory.getLog(SOAPHeaderImpl.class);
-    /** 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;
-        }
-    }
-
-
     protected SOAPHeaderImpl(OMNamespace ns, SOAPFactory factory) {
         super(SOAPConstants.HEADER_LOCAL_NAME, ns, factory);
     }
@@ -277,21 +95,21 @@ public abstract class SOAPHeaderImpl ext
     protected abstract SOAPHeaderBlock createHeaderBlock(String localname, OMNamespace ns);
     
     public Iterator getHeadersToProcess(RolePlayer rolePlayer) {
-        return new HeaderIterator(new RolePlayerChecker(rolePlayer));
+        return new HeaderIterator(this, new RolePlayerChecker(rolePlayer));
     }
 
     public Iterator getHeadersToProcess(RolePlayer rolePlayer, String namespace) {
-        return new HeaderIterator(new RolePlayerChecker(rolePlayer, namespace));
+        return new HeaderIterator(this, new RolePlayerChecker(rolePlayer, namespace));
     }
 
     public Iterator examineHeaderBlocks(String role) {
-        return new HeaderIterator(new RoleChecker(role));
+        return new HeaderIterator(this, new RoleChecker(role));
     }
 
     public abstract Iterator extractHeaderBlocks(String role);
 
     public Iterator examineMustUnderstandHeaderBlocks(String actor) {
-        return new HeaderIterator(new MURoleChecker(actor));
+        return new HeaderIterator(this, new MURoleChecker(actor));
     }
 
     public Iterator examineAllHeaderBlocks() {
@@ -301,7 +119,7 @@ public abstract class SOAPHeaderImpl ext
             }
         }
 
-        return new HeaderIterator(new DefaultChecker());
+        return new HeaderIterator(this, new DefaultChecker());
     }
 
     public Iterator extractAllHeaderBlocks() {