ws-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From veit...@apache.org
Subject svn commit: r1735163 - in /webservices/axiom/trunk: aspects/core-aspects/src/main/java/org/apache/axiom/core/ aspects/core-aspects/src/main/java/org/apache/axiom/core/impl/ aspects/core-aspects/src/main/java/org/apache/axiom/core/impl/mixin/ aspects/om...
Date Tue, 15 Mar 2016 20:29:08 GMT
Author: veithen
Date: Tue Mar 15 20:29:07 2016
New Revision: 1735163

URL: http://svn.apache.org/viewvc?rev=1735163&view=rev
Log:
AXIOM-362: Allow examineAllHeaderBlocks to convert plain OMElements to SOAPHeaderBlocks on
the fly. This is mostly relevant for elements added to a SOAPHeader using the DOM API.

Added:
    webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/soap/impl/common/SOAPHeaderBlockMapper.java
  (with props)
    webservices/axiom/trunk/testing/axiom-testsuite/src/main/java/org/apache/axiom/ts/soapdom/header/
    webservices/axiom/trunk/testing/axiom-testsuite/src/main/java/org/apache/axiom/ts/soapdom/header/TestExamineAllHeaderBlocks.java
  (with props)
Modified:
    webservices/axiom/trunk/aspects/core-aspects/src/main/java/org/apache/axiom/core/InputContext.java
    webservices/axiom/trunk/aspects/core-aspects/src/main/java/org/apache/axiom/core/impl/AbstractNodeIterator.java
    webservices/axiom/trunk/aspects/core-aspects/src/main/java/org/apache/axiom/core/impl/mixin/CoreElementSupport.aj
    webservices/axiom/trunk/aspects/core-aspects/src/main/java/org/apache/axiom/core/impl/mixin/CoreParentNodeSupport.aj
    webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/common/builder/BuildableContext.java
    webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/soap/impl/mixin/AxiomSOAPHeaderSupport.aj
    webservices/axiom/trunk/axiom-api/src/main/java/org/apache/axiom/soap/SOAPHeader.java
    webservices/axiom/trunk/implementations/axiom-dom/src/main/java/org/apache/axiom/soap/impl/dom/SOAPHeaderImpl.java
    webservices/axiom/trunk/implementations/axiom-impl/src/main/java/org/apache/axiom/soap/impl/llom/SOAPHeaderImpl.java
    webservices/axiom/trunk/testing/axiom-testsuite/src/main/java/org/apache/axiom/ts/soapdom/SOAPDOMTestSuiteBuilder.java

Modified: webservices/axiom/trunk/aspects/core-aspects/src/main/java/org/apache/axiom/core/InputContext.java
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/aspects/core-aspects/src/main/java/org/apache/axiom/core/InputContext.java?rev=1735163&r1=1735162&r2=1735163&view=diff
==============================================================================
--- webservices/axiom/trunk/aspects/core-aspects/src/main/java/org/apache/axiom/core/InputContext.java
(original)
+++ webservices/axiom/trunk/aspects/core-aspects/src/main/java/org/apache/axiom/core/InputContext.java
Tue Mar 15 20:29:07 2016
@@ -35,5 +35,7 @@ public interface InputContext {
      */
     void setPassThroughHandler(XmlHandler passThroughHandler);
 
+    void setTarget(CoreParentNode target);
+
     void discard();
 }

Modified: webservices/axiom/trunk/aspects/core-aspects/src/main/java/org/apache/axiom/core/impl/AbstractNodeIterator.java
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/aspects/core-aspects/src/main/java/org/apache/axiom/core/impl/AbstractNodeIterator.java?rev=1735163&r1=1735162&r2=1735163&view=diff
==============================================================================
--- webservices/axiom/trunk/aspects/core-aspects/src/main/java/org/apache/axiom/core/impl/AbstractNodeIterator.java
(original)
+++ webservices/axiom/trunk/aspects/core-aspects/src/main/java/org/apache/axiom/core/impl/AbstractNodeIterator.java
Tue Mar 15 20:29:07 2016
@@ -134,7 +134,11 @@ public abstract class AbstractNodeIterat
             currentNode = nextNode;
             currentParent = currentNode instanceof CoreChildNode ? ((CoreChildNode)currentNode).coreGetParent()
: null;
             hasNext = false;
-            return mapper.map(currentNode);
+            S mapped = mapper.map(currentNode);
+            if (mapped != currentNode && mapped instanceof CoreNode) {
+                currentNode = type.cast(mapped);
+            }
+            return mapped;
         } else {
             throw new NoSuchElementException();
         }

Modified: webservices/axiom/trunk/aspects/core-aspects/src/main/java/org/apache/axiom/core/impl/mixin/CoreElementSupport.aj
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/aspects/core-aspects/src/main/java/org/apache/axiom/core/impl/mixin/CoreElementSupport.aj?rev=1735163&r1=1735162&r2=1735163&view=diff
==============================================================================
--- webservices/axiom/trunk/aspects/core-aspects/src/main/java/org/apache/axiom/core/impl/mixin/CoreElementSupport.aj
(original)
+++ webservices/axiom/trunk/aspects/core-aspects/src/main/java/org/apache/axiom/core/impl/mixin/CoreElementSupport.aj
Tue Mar 15 20:29:07 2016
@@ -225,4 +225,18 @@ public aspect CoreElementSupport {
     // This is basically a hook for OMSourcedElement
     public <T> void CoreElement.initSource(ClonePolicy<T> policy, T options,
CoreElement other) {
     }
+    
+    public final <T extends CoreElement> T CoreElement.corePromote(Class<T> type,
Semantics semantics) throws CoreModelException {
+        T newElement = coreCreateNode(type);
+        newElement.initName(this);
+        CoreAttribute attr = newElement.firstAttribute = firstAttribute;
+        while (attr != null) {
+            attr.internalSetOwnerElement(newElement);
+            attr = attr.coreGetNextAttribute();
+        }
+        firstAttribute = null;
+        newElement.coreMoveChildrenFrom(this, semantics);
+        coreReplaceWith(newElement, semantics);
+        return newElement;
+    }
 }

Modified: webservices/axiom/trunk/aspects/core-aspects/src/main/java/org/apache/axiom/core/impl/mixin/CoreParentNodeSupport.aj
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/aspects/core-aspects/src/main/java/org/apache/axiom/core/impl/mixin/CoreParentNodeSupport.aj?rev=1735163&r1=1735162&r2=1735163&view=diff
==============================================================================
--- webservices/axiom/trunk/aspects/core-aspects/src/main/java/org/apache/axiom/core/impl/mixin/CoreParentNodeSupport.aj
(original)
+++ webservices/axiom/trunk/aspects/core-aspects/src/main/java/org/apache/axiom/core/impl/mixin/CoreParentNodeSupport.aj
Tue Mar 15 20:29:07 2016
@@ -426,4 +426,25 @@ public aspect CoreParentNodeSupport {
                 }
         }
     }
+    
+    public final void CoreParentNode.coreMoveChildrenFrom(CoreParentNode other, Semantics
semantics) throws CoreModelException {
+        coreRemoveChildren(semantics);
+        context = other.context;
+        content = other.content;
+        int state = other.getState();
+        coreSetState(state);
+        if (state != COMPACT) {
+            CoreChildNode child = coreGetFirstChildIfAvailable();
+            while (child != null) {
+                child.internalSetParent(this);
+                child = child.coreGetNextSiblingIfAvailable();
+            }
+            if (context != null ) {
+                context.setTarget(this);
+            }
+        }
+        other.context = null;
+        other.content = null;
+        other.coreSetState(DISCARDED);
+    }
 }

Modified: webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/common/builder/BuildableContext.java
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/common/builder/BuildableContext.java?rev=1735163&r1=1735162&r2=1735163&view=diff
==============================================================================
--- webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/common/builder/BuildableContext.java
(original)
+++ webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/common/builder/BuildableContext.java
Tue Mar 15 20:29:07 2016
@@ -85,6 +85,11 @@ final class BuildableContext extends Con
     }
     
     @Override
+    public void setTarget(CoreParentNode target) {
+        this.target = target;
+    }
+
+    @Override
     public void discard() {
         target.coreSetState(CoreParentNode.DISCARDING);
         passThroughHandler = NullXmlHandler.INSTANCE;

Added: webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/soap/impl/common/SOAPHeaderBlockMapper.java
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/soap/impl/common/SOAPHeaderBlockMapper.java?rev=1735163&view=auto
==============================================================================
--- webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/soap/impl/common/SOAPHeaderBlockMapper.java
(added)
+++ webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/soap/impl/common/SOAPHeaderBlockMapper.java
Tue Mar 15 20:29:07 2016
@@ -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.core.CoreModelException;
+import org.apache.axiom.core.Mapper;
+import org.apache.axiom.om.impl.common.AxiomSemantics;
+import org.apache.axiom.om.impl.intf.AxiomElement;
+import org.apache.axiom.soap.SOAPHeaderBlock;
+import org.apache.axiom.soap.impl.intf.AxiomSOAPHeader;
+
+public final class SOAPHeaderBlockMapper implements Mapper<SOAPHeaderBlock,AxiomElement>
{
+    public static final SOAPHeaderBlockMapper INSTANCE = new SOAPHeaderBlockMapper();
+    
+    private SOAPHeaderBlockMapper() {}
+    
+    @Override
+    public SOAPHeaderBlock map(AxiomElement element) {
+        try {
+            return element.corePromote(((AxiomSOAPHeader)element.coreGetParent()).getSOAPHelper().getHeaderBlockClass(),
AxiomSemantics.INSTANCE);
+        } catch (CoreModelException ex) {
+            throw AxiomSemantics.INSTANCE.toUncheckedException(ex);
+        }
+    }
+}

Propchange: webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/soap/impl/common/SOAPHeaderBlockMapper.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/soap/impl/mixin/AxiomSOAPHeaderSupport.aj
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/soap/impl/mixin/AxiomSOAPHeaderSupport.aj?rev=1735163&r1=1735162&r2=1735163&view=diff
==============================================================================
--- webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/soap/impl/mixin/AxiomSOAPHeaderSupport.aj
(original)
+++ webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/soap/impl/mixin/AxiomSOAPHeaderSupport.aj
Tue Mar 15 20:29:07 2016
@@ -18,12 +18,24 @@
  */
 package org.apache.axiom.soap.impl.mixin;
 
+import java.util.Iterator;
+
+import org.apache.axiom.core.Axis;
+import org.apache.axiom.core.ElementMatcher;
 import org.apache.axiom.om.OMElement;
+import org.apache.axiom.om.impl.common.AxiomSemantics;
+import org.apache.axiom.om.impl.intf.AxiomElement;
 import org.apache.axiom.soap.SOAPHeaderBlock;
+import org.apache.axiom.soap.impl.common.SOAPHeaderBlockMapper;
 import org.apache.axiom.soap.impl.intf.AxiomSOAPHeader;
 
 public aspect AxiomSOAPHeaderSupport {
     public final boolean AxiomSOAPHeader.isChildElementAllowed(OMElement child) {
         return child instanceof SOAPHeaderBlock;
     }
+
+    public final Iterator<SOAPHeaderBlock> AxiomSOAPHeader.examineAllHeaderBlocks()
{
+        return coreGetElements(Axis.CHILDREN, AxiomElement.class, ElementMatcher.ANY, null,
null,
+                SOAPHeaderBlockMapper.INSTANCE, AxiomSemantics.INSTANCE);
+    }
 }

Modified: webservices/axiom/trunk/axiom-api/src/main/java/org/apache/axiom/soap/SOAPHeader.java
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/axiom-api/src/main/java/org/apache/axiom/soap/SOAPHeader.java?rev=1735163&r1=1735162&r2=1735163&view=diff
==============================================================================
--- webservices/axiom/trunk/axiom-api/src/main/java/org/apache/axiom/soap/SOAPHeader.java
(original)
+++ webservices/axiom/trunk/axiom-api/src/main/java/org/apache/axiom/soap/SOAPHeader.java
Tue Mar 15 20:29:07 2016
@@ -125,7 +125,7 @@ public interface SOAPHeader extends OMEl
      * @return An iterator over all the {@link SOAPHeaderBlock} objects contained by this
      *         {@link SOAPHeader}. If there are no header blocks then an empty iterator is
returned.
      */
-    Iterator examineAllHeaderBlocks();
+    Iterator<SOAPHeaderBlock> examineAllHeaderBlocks();
 
     /**
      * Returns an iterator over all the {@link SOAPHeaderBlock} objects in this {@link SOAPHeader}

Modified: webservices/axiom/trunk/implementations/axiom-dom/src/main/java/org/apache/axiom/soap/impl/dom/SOAPHeaderImpl.java
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/implementations/axiom-dom/src/main/java/org/apache/axiom/soap/impl/dom/SOAPHeaderImpl.java?rev=1735163&r1=1735162&r2=1735163&view=diff
==============================================================================
--- webservices/axiom/trunk/implementations/axiom-dom/src/main/java/org/apache/axiom/soap/impl/dom/SOAPHeaderImpl.java
(original)
+++ webservices/axiom/trunk/implementations/axiom-dom/src/main/java/org/apache/axiom/soap/impl/dom/SOAPHeaderImpl.java
Tue Mar 15 20:29:07 2016
@@ -84,10 +84,6 @@ public abstract class SOAPHeaderImpl ext
         return new HeaderIterator(this, new MURoleChecker(actor));
     }
 
-    public Iterator examineAllHeaderBlocks() {
-        return this.getChildrenWithName(null);
-    }
-
     public Iterator extractAllHeaderBlocks() {
         List result = new ArrayList();
         for (Iterator iter = getChildElements(); iter.hasNext();) {

Modified: webservices/axiom/trunk/implementations/axiom-impl/src/main/java/org/apache/axiom/soap/impl/llom/SOAPHeaderImpl.java
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/implementations/axiom-impl/src/main/java/org/apache/axiom/soap/impl/llom/SOAPHeaderImpl.java?rev=1735163&r1=1735162&r2=1735163&view=diff
==============================================================================
--- webservices/axiom/trunk/implementations/axiom-impl/src/main/java/org/apache/axiom/soap/impl/llom/SOAPHeaderImpl.java
(original)
+++ webservices/axiom/trunk/implementations/axiom-impl/src/main/java/org/apache/axiom/soap/impl/llom/SOAPHeaderImpl.java
Tue Mar 15 20:29:07 2016
@@ -90,16 +90,6 @@ public abstract class SOAPHeaderImpl ext
         return new HeaderIterator(this, new MURoleChecker(actor));
     }
 
-    public Iterator examineAllHeaderBlocks() {
-        class DefaultChecker implements Checker {
-            public boolean checkHeader(SOAPHeaderBlock header) {
-                return true;
-            }
-        }
-
-        return new HeaderIterator(this, new DefaultChecker());
-    }
-
     public Iterator extractAllHeaderBlocks() {
         List result = new ArrayList();
         for (Iterator iter = getChildElements(); iter.hasNext();) {

Modified: webservices/axiom/trunk/testing/axiom-testsuite/src/main/java/org/apache/axiom/ts/soapdom/SOAPDOMTestSuiteBuilder.java
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/testing/axiom-testsuite/src/main/java/org/apache/axiom/ts/soapdom/SOAPDOMTestSuiteBuilder.java?rev=1735163&r1=1735162&r2=1735163&view=diff
==============================================================================
--- webservices/axiom/trunk/testing/axiom-testsuite/src/main/java/org/apache/axiom/ts/soapdom/SOAPDOMTestSuiteBuilder.java
(original)
+++ webservices/axiom/trunk/testing/axiom-testsuite/src/main/java/org/apache/axiom/ts/soapdom/SOAPDOMTestSuiteBuilder.java
Tue Mar 15 20:29:07 2016
@@ -35,6 +35,7 @@ public class SOAPDOMTestSuiteBuilder ext
     }
     
     private void addTests(SOAPSpec spec) {
+        addTest(new org.apache.axiom.ts.soapdom.header.TestExamineAllHeaderBlocks(metaFactory,
spec));
         addTest(new org.apache.axiom.ts.soapdom.message.TestLazySOAPFactorySelection(metaFactory,
spec));
     }
 }

Added: webservices/axiom/trunk/testing/axiom-testsuite/src/main/java/org/apache/axiom/ts/soapdom/header/TestExamineAllHeaderBlocks.java
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/testing/axiom-testsuite/src/main/java/org/apache/axiom/ts/soapdom/header/TestExamineAllHeaderBlocks.java?rev=1735163&view=auto
==============================================================================
--- webservices/axiom/trunk/testing/axiom-testsuite/src/main/java/org/apache/axiom/ts/soapdom/header/TestExamineAllHeaderBlocks.java
(added)
+++ webservices/axiom/trunk/testing/axiom-testsuite/src/main/java/org/apache/axiom/ts/soapdom/header/TestExamineAllHeaderBlocks.java
Tue Mar 15 20:29:07 2016
@@ -0,0 +1,74 @@
+/*
+ * 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.ts.soapdom.header;
+
+import static com.google.common.truth.Truth.assertThat;
+
+import java.util.Iterator;
+
+import javax.xml.namespace.QName;
+
+import org.apache.axiom.om.OMElement;
+import org.apache.axiom.om.OMMetaFactory;
+import org.apache.axiom.soap.SOAPHeader;
+import org.apache.axiom.soap.SOAPHeaderBlock;
+import org.apache.axiom.ts.soap.SOAPSpec;
+import org.apache.axiom.ts.soap.SOAPTestCase;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+
+/**
+ * Tests that child elements of a {@link SOAPHeader} created using the DOM API are converted
on the
+ * fly and returned as {@link SOAPHeaderBlock} instances by
+ * {@link SOAPHeader#examineAllHeaderBlocks()}.
+ */
+public class TestExamineAllHeaderBlocks extends SOAPTestCase {
+    public TestExamineAllHeaderBlocks(OMMetaFactory metaFactory, SOAPSpec spec) {
+        super(metaFactory, spec);
+    }
+
+    @Override
+    protected void runTest() throws Throwable {
+        SOAPHeader header = soapFactory.createSOAPHeader();
+        
+        // Add header blocks using DOM
+        Element domHeader = (Element)header;
+        Document document = domHeader.getOwnerDocument();
+        Element headerBlock1 = document.createElementNS("urn:test", "p:h1");
+        headerBlock1.setAttributeNS(spec.getEnvelopeNamespaceURI(), "S:mustUnderstand", "1");
+        headerBlock1.setTextContent("test");
+        Element headerBlock2 = document.createElementNS("urn:test", "p:h2");
+        headerBlock2.appendChild(document.createElementNS(null, "test"));
+        domHeader.appendChild(headerBlock1);
+        domHeader.appendChild(headerBlock2);
+        
+        // Use the Axiom API to iterate over the header blocks
+        Iterator<SOAPHeaderBlock> it = header.examineAllHeaderBlocks();
+        assertThat(it.hasNext()).isTrue();
+        SOAPHeaderBlock headerBlock = it.next();
+        assertThat(headerBlock.getQName()).isEqualTo(new QName("urn:test", "h1"));
+        assertThat(headerBlock.getMustUnderstand()).isTrue();
+        assertThat(headerBlock.getText()).isEqualTo("test");
+        assertThat(it.hasNext()).isTrue();
+        headerBlock = it.next();
+        assertThat(headerBlock.getQName()).isEqualTo(new QName("urn:test", "h2"));
+        assertThat(headerBlock.getFirstOMChild()).isInstanceOf(OMElement.class);
+        assertThat(it.hasNext()).isFalse();
+    }
+}

Propchange: webservices/axiom/trunk/testing/axiom-testsuite/src/main/java/org/apache/axiom/ts/soapdom/header/TestExamineAllHeaderBlocks.java
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message