ws-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From veit...@apache.org
Subject svn commit: r1728374 - in /webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom: om/impl/common/builder/ soap/impl/common/builder/ soap/impl/mixin/
Date Wed, 03 Feb 2016 21:07:47 GMT
Author: veithen
Date: Wed Feb  3 21:07:47 2016
New Revision: 1728374

URL: http://svn.apache.org/viewvc?rev=1728374&view=rev
Log:
Implement a more straightforward way to initialize the SOAPFactory on a SOAPMessage.

Added:
    webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/common/builder/NodePostProcessor.java
  (with props)
Modified:
    webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/common/builder/StAXOMBuilder.java
    webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/soap/impl/common/builder/StAXSOAPModelBuilder.java
    webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/soap/impl/mixin/AxiomSOAPMessageSupport.aj

Added: webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/common/builder/NodePostProcessor.java
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/common/builder/NodePostProcessor.java?rev=1728374&view=auto
==============================================================================
--- webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/common/builder/NodePostProcessor.java
(added)
+++ webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/common/builder/NodePostProcessor.java
Wed Feb  3 21:07:47 2016
@@ -0,0 +1,25 @@
+/*
+ * 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.om.impl.common.builder;
+
+import org.apache.axiom.om.OMSerializable;
+
+public interface NodePostProcessor {
+    void postProcessNode(OMSerializable node);
+}

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

Modified: webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/common/builder/StAXOMBuilder.java
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/common/builder/StAXOMBuilder.java?rev=1728374&r1=1728373&r2=1728374&view=diff
==============================================================================
--- webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/common/builder/StAXOMBuilder.java
(original)
+++ webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/common/builder/StAXOMBuilder.java
Wed Feb  3 21:07:47 2016
@@ -31,6 +31,7 @@ import org.apache.axiom.om.OMException;
 import org.apache.axiom.om.OMFactory;
 import org.apache.axiom.om.OMNamespace;
 import org.apache.axiom.om.OMNode;
+import org.apache.axiom.om.OMSerializable;
 import org.apache.axiom.om.OMText;
 import org.apache.axiom.om.impl.builder.Builder;
 import org.apache.axiom.om.impl.builder.CustomBuilder;
@@ -53,6 +54,7 @@ import javax.xml.namespace.QName;
 import javax.xml.stream.Location;
 
 import java.io.Closeable;
+import java.util.ArrayList;
 import java.util.LinkedHashMap;
 import java.util.Map;
 
@@ -169,6 +171,8 @@ public class StAXOMBuilder implements Bu
     
     private int lookAheadToken = -1;
     
+    private ArrayList<NodePostProcessor> nodePostProcessors;
+    
     private StAXOMBuilder(OMFactory omFactory, XMLStreamReader parser, String encoding,
             boolean autoClose, Detachable detachable, Closeable closeable, PayloadSelector
payloadSelector) {
         omfactory = (OMFactoryEx)omFactory;
@@ -532,6 +536,7 @@ public class StAXOMBuilder implements Bu
             document.setXMLEncoding(parser.getCharacterEncodingScheme());
             document.setStandalone(parser.isStandalone() ? "yes" : "no");
             target = (AxiomContainer)document;
+            postProcessNode(document);
         }
     }
     
@@ -632,11 +637,12 @@ public class StAXOMBuilder implements Bu
             }
            
             // Note: if autoClose is enabled, then the parser may be null at this point
-           
+            
+            OMNode node;
             switch (token) {
                 case XMLStreamConstants.START_ELEMENT: {
                     elementLevel++;
-                    OMNode node = createNextOMElement();
+                    node = createNextOMElement();
                     // If the node was created by a custom builder, then it will be complete;
                     // in this case, the target doesn't change
                     if (!node.isComplete()) {
@@ -645,38 +651,41 @@ public class StAXOMBuilder implements Bu
                     break;
                 }
                 case XMLStreamConstants.CHARACTERS:
-                    createOMText(XMLStreamConstants.CHARACTERS);
+                    node = createOMText(XMLStreamConstants.CHARACTERS);
                     break;
                 case XMLStreamConstants.CDATA:
-                    createOMText(XMLStreamConstants.CDATA);
+                    node = createOMText(XMLStreamConstants.CDATA);
                     break;
                 case XMLStreamConstants.END_ELEMENT:
                     elementLevel--;
                     endElement();
+                    node = null;
                     break;
                 case XMLStreamConstants.END_DOCUMENT:
                     done = true;
                     ((AxiomContainer) this.document).setComplete(true);
                     target = null;
+                    node = null;
                     break;
                 case XMLStreamConstants.SPACE:
-                    createOMText(XMLStreamConstants.SPACE);
+                    node = createOMText(XMLStreamConstants.SPACE);
                     break;
                 case XMLStreamConstants.COMMENT:
-                    createComment();
+                    node = createComment();
                     break;
                 case XMLStreamConstants.DTD:
-                    createDTD();
+                    node = createDTD();
                     break;
                 case XMLStreamConstants.PROCESSING_INSTRUCTION:
-                    createPI();
+                    node = createPI();
                     break;
                 case XMLStreamConstants.ENTITY_REFERENCE:
-                    createEntityReference();
+                    node = createEntityReference();
                     break;
                 default :
                     throw new OMException();
             }
+            postProcessNode(node);
             
             if (target == null && !done) {
                 // We get here if the document has been discarded (by getDocumentElement(true)
@@ -1045,4 +1054,19 @@ public class StAXOMBuilder implements Bu
     public final AxiomContainer getTarget() {
         return target;
     }
+    
+    public final void addNodePostProcessor(NodePostProcessor nodePostProcessor) {
+        if (nodePostProcessors == null) {
+            nodePostProcessors = new ArrayList<NodePostProcessor>();
+        }
+        nodePostProcessors.add(nodePostProcessor);
+    }
+    
+    private void postProcessNode(OMSerializable node) {
+        if (nodePostProcessors != null) {
+            for (int i=0, size=nodePostProcessors.size(); i<size; i++) {
+                nodePostProcessors.get(i).postProcessNode(node);
+            }
+        }
+    }
 }

Modified: webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/soap/impl/common/builder/StAXSOAPModelBuilder.java
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/soap/impl/common/builder/StAXSOAPModelBuilder.java?rev=1728374&r1=1728373&r2=1728374&view=diff
==============================================================================
--- webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/soap/impl/common/builder/StAXSOAPModelBuilder.java
(original)
+++ webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/soap/impl/common/builder/StAXSOAPModelBuilder.java
Wed Feb  3 21:07:47 2016
@@ -27,7 +27,9 @@ import org.apache.axiom.om.OMElement;
 import org.apache.axiom.om.OMException;
 import org.apache.axiom.om.OMMetaFactory;
 import org.apache.axiom.om.OMNode;
+import org.apache.axiom.om.OMSerializable;
 import org.apache.axiom.om.impl.builder.Detachable;
+import org.apache.axiom.om.impl.common.builder.NodePostProcessor;
 import org.apache.axiom.om.impl.common.builder.StAXOMBuilder;
 import org.apache.axiom.om.impl.intf.AxiomElement;
 import org.apache.axiom.soap.SOAP11Constants;
@@ -41,6 +43,8 @@ import org.apache.axiom.soap.SOAPMessage
 import org.apache.axiom.soap.SOAPModelBuilder;
 import org.apache.axiom.soap.SOAPProcessingException;
 import org.apache.axiom.soap.impl.builder.OMMetaFactoryEx;
+import org.apache.axiom.soap.impl.intf.AxiomSOAPEnvelope;
+import org.apache.axiom.soap.impl.intf.AxiomSOAPMessage;
 import org.apache.axiom.soap.impl.intf.SOAPFactoryEx;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
@@ -76,6 +80,21 @@ public class StAXSOAPModelBuilder extend
             boolean autoClose, Detachable detachable, Closeable closeable) {
         super(metaFactory.getOMFactory(), parser, autoClose, detachable, closeable, SOAPPayloadSelector.INSTANCE);
         this.metaFactory = metaFactory;
+        // The SOAPFactory instance linked to the SOAPMessage is unknown until we reach the
+        // SOAPEnvelope. Register a post-processor that does the necessary updates on the
+        // SOAPMessage.
+        addNodePostProcessor(new NodePostProcessor() {
+            private AxiomSOAPMessage message;
+            
+            @Override
+            public void postProcessNode(OMSerializable node) {
+                if (node instanceof AxiomSOAPMessage) {
+                    message = (AxiomSOAPMessage)node;
+                } else if (message != null && node instanceof AxiomSOAPEnvelope)
{
+                    message.initSOAPFactory((SOAPFactory)((AxiomSOAPEnvelope)node).getOMFactory());
+                }
+            }
+        });
     }
     
     public SOAPEnvelope getSOAPEnvelope() throws OMException {
@@ -203,11 +222,4 @@ public class StAXSOAPModelBuilder extend
     public SOAPMessage getSOAPMessage() {
         return (SOAPMessage)getDocument();
     }
-
-    public SOAPFactory getSOAPFactory() {
-        if (soapFactory == null) {
-            getSOAPEnvelope();
-        }
-        return soapFactory;
-    }
 }

Modified: webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/soap/impl/mixin/AxiomSOAPMessageSupport.aj
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/soap/impl/mixin/AxiomSOAPMessageSupport.aj?rev=1728374&r1=1728373&r2=1728374&view=diff
==============================================================================
--- webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/soap/impl/mixin/AxiomSOAPMessageSupport.aj
(original)
+++ webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/soap/impl/mixin/AxiomSOAPMessageSupport.aj
Wed Feb  3 21:07:47 2016
@@ -27,7 +27,6 @@ import org.apache.axiom.om.impl.common.s
 import org.apache.axiom.om.impl.intf.AxiomElement;
 import org.apache.axiom.soap.SOAPEnvelope;
 import org.apache.axiom.soap.SOAPFactory;
-import org.apache.axiom.soap.impl.common.builder.StAXSOAPModelBuilder;
 import org.apache.axiom.soap.impl.intf.AxiomSOAPMessage;
 
 public aspect AxiomSOAPMessageSupport {
@@ -47,7 +46,8 @@ public aspect AxiomSOAPMessageSupport {
     
     public final OMFactory AxiomSOAPMessage.getOMFactory() {
         if (factory == null) {
-            factory = ((StAXSOAPModelBuilder)getBuilder()).getSOAPFactory();
+            // Force expansion up to the SOAP envelope; this will initialize the factory
+            getSOAPEnvelope();
         }
         return factory;
     }



Mime
View raw message