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 2016/02/02 20:57:34 UTC

svn commit: r1728198 - in /webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom: om/impl/common/builder/ soap/impl/common/builder/

Author: veithen
Date: Tue Feb  2 19:57:33 2016
New Revision: 1728198

URL: http://svn.apache.org/viewvc?rev=1728198&view=rev
Log:
Create an interface that defines the notion of 'payload' and increase the level of encapsulation in StAXOMBuilder.

Added:
    webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/common/builder/PayloadSelector.java   (with props)
    webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/soap/impl/common/builder/SOAPPayloadSelector.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

Added: webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/common/builder/PayloadSelector.java
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/common/builder/PayloadSelector.java?rev=1728198&view=auto
==============================================================================
--- webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/common/builder/PayloadSelector.java (added)
+++ webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/common/builder/PayloadSelector.java Tue Feb  2 19:57:33 2016
@@ -0,0 +1,38 @@
+/*
+ * 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.impl.builder.CustomBuilder;
+import org.apache.axiom.om.impl.builder.CustomBuilderSupport;
+import org.apache.axiom.om.impl.intf.AxiomContainer;
+
+/**
+ * Interface defining the notion of "payload" to be used by
+ * {@link CustomBuilderSupport#registerCustomBuilderForPayload(CustomBuilder)}.
+ */
+public interface PayloadSelector {
+    PayloadSelector DEFAULT = new PayloadSelector() {
+        @Override
+        public boolean isPayload(int elementLevel, AxiomContainer parent) {
+            return elementLevel == 1;
+        }
+    };
+    
+    boolean isPayload(int elementLevel, AxiomContainer parent);
+}

Propchange: webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/common/builder/PayloadSelector.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=1728198&r1=1728197&r2=1728198&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 Tue Feb  2 19:57:33 2016
@@ -101,7 +101,7 @@ public class StAXOMBuilder implements Bu
     private final Closeable closeable;
 
     /** Field lastNode */
-    protected AxiomContainer target;
+    private AxiomContainer target;
 
     // returns the state of completion
 
@@ -131,9 +131,10 @@ public class StAXOMBuilder implements Bu
     private boolean _isClosed = false;              // Indicate if parser is closed
 
     // Fields for Custom Builder implementation
-    protected CustomBuilder customBuilderForPayload = null;
-    protected Map<QName,CustomBuilder> customBuilders = null;
-    protected int maxDepthForCustomBuilders = -1;
+    private final PayloadSelector payloadSelector;
+    private CustomBuilder customBuilderForPayload;
+    private Map<QName,CustomBuilder> customBuilders;
+    private int maxDepthForCustomBuilders = -1;
     
     /**
      * Reference to the {@link DataHandlerReader} extension of the parser, or <code>null</code> if
@@ -169,20 +170,27 @@ public class StAXOMBuilder implements Bu
     private int lookAheadToken = -1;
     
     private StAXOMBuilder(OMFactory omFactory, XMLStreamReader parser, String encoding,
-            boolean autoClose, Detachable detachable, Closeable closeable) {
+            boolean autoClose, Detachable detachable, Closeable closeable, PayloadSelector payloadSelector) {
         omfactory = (OMFactoryEx)omFactory;
         this.parser = parser;
         this.autoClose = autoClose;
         this.detachable = detachable;
         this.closeable = closeable;
+        this.payloadSelector = payloadSelector;
         charEncoding = encoding;
         dataHandlerReader = XMLStreamReaderUtils.getDataHandlerReader(parser);
     }
     
+    protected StAXOMBuilder(OMFactory omFactory, XMLStreamReader parser, boolean autoClose,
+            Detachable detachable, Closeable closeable, PayloadSelector payloadSelector) {
+        // The getEncoding information is only available at the START_DOCUMENT event.
+        this(omFactory, parser, parser.getEncoding(), autoClose, detachable, closeable, payloadSelector);
+        
+    }
+    
     public StAXOMBuilder(OMFactory omFactory, XMLStreamReader parser, boolean autoClose,
             Detachable detachable, Closeable closeable) {
-        // The getEncoding information is only available at the START_DOCUMENT event.
-        this(omFactory, parser, parser.getEncoding(), autoClose, detachable, closeable);
+        this(omFactory, parser, autoClose, detachable, closeable, PayloadSelector.DEFAULT);
     }
     
     public StAXOMBuilder(OMFactory factory, 
@@ -190,7 +198,7 @@ public class StAXOMBuilder implements Bu
                          OMElement element, 
                          String characterEncoding) {
         // Use this constructor because the parser is passed the START_DOCUMENT state.
-        this(factory, parser, characterEncoding, true, null, null);  
+        this(factory, parser, characterEncoding, true, null, null, PayloadSelector.DEFAULT);  
         elementLevel = 1;
         target = (AxiomContainer)element;
         populateOMElement(element);
@@ -699,16 +707,17 @@ public class StAXOMBuilder implements Bu
      * the default Builder mechanism.
      * @return TODO
      */
-    protected OMNode createNextOMElement() {
+    private OMNode createNextOMElement() {
         OMNode newElement = null;
-        if (elementLevel == 1 && this.customBuilderForPayload != null) {
-            newElement = createWithCustomBuilder(customBuilderForPayload,  omfactory);
-        } else if (customBuilders != null && elementLevel <= this.maxDepthForCustomBuilders) {
+        if (customBuilderForPayload != null && payloadSelector.isPayload(elementLevel, target)) {
+            newElement = createWithCustomBuilder(customBuilderForPayload);
+        }
+        if (newElement == null && customBuilders != null && elementLevel <= this.maxDepthForCustomBuilders) {
             String namespace = parser.getNamespaceURI();
             String localPart = parser.getLocalName();
             CustomBuilder customBuilder = getCustomBuilder(namespace, localPart);
             if (customBuilder != null) {
-                newElement = createWithCustomBuilder(customBuilder, omfactory);
+                newElement = createWithCustomBuilder(customBuilder);
             }
         }
         if (newElement == null) {
@@ -719,7 +728,7 @@ public class StAXOMBuilder implements Bu
         return newElement;
     }
     
-    protected final OMNode createWithCustomBuilder(CustomBuilder customBuilder, OMFactory factory) {
+    private OMNode createWithCustomBuilder(CustomBuilder customBuilder) {
         
         String namespace = parser.getNamespaceURI();
         if (namespace == null) {
@@ -740,7 +749,8 @@ public class StAXOMBuilder implements Bu
         // custom builder API. This should be fixed in Axiom 1.3.
         target.setComplete(true);
         
-        OMNode node = customBuilder.create(namespace, localPart, target, parser, factory);
+        // Use target.getOMFactory() because the factory may actually be a SOAPFactory
+        OMNode node = customBuilder.create(namespace, localPart, target, parser, target.getOMFactory());
         
         // TODO: dirty hack part 2
         target.setComplete(false);
@@ -782,7 +792,7 @@ public class StAXOMBuilder implements Bu
      * @return Returns OMNode.
      * @throws OMException
      */
-    protected final OMNode createOMElement() throws OMException {
+    private OMNode createOMElement() throws OMException {
         AxiomElement node = omfactory.createAxiomElement(determineElementType(target, parser.getLocalName()), parser.getLocalName(), target, this);
         postProcessElement(node);
         populateOMElement(node);

Added: webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/soap/impl/common/builder/SOAPPayloadSelector.java
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/soap/impl/common/builder/SOAPPayloadSelector.java?rev=1728198&view=auto
==============================================================================
--- webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/soap/impl/common/builder/SOAPPayloadSelector.java (added)
+++ webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/soap/impl/common/builder/SOAPPayloadSelector.java Tue Feb  2 19:57:33 2016
@@ -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.builder;
+
+import org.apache.axiom.om.impl.common.builder.PayloadSelector;
+import org.apache.axiom.om.impl.intf.AxiomContainer;
+import org.apache.axiom.soap.SOAPBody;
+
+public final class SOAPPayloadSelector implements PayloadSelector {
+    public static final SOAPPayloadSelector INSTANCE = new SOAPPayloadSelector();
+
+    private SOAPPayloadSelector() {}
+    
+    @Override
+    public boolean isPayload(int elementLevel, AxiomContainer parent) {
+        return elementLevel == 3 && parent instanceof SOAPBody;
+    }
+}

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

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=1728198&r1=1728197&r2=1728198&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 Tue Feb  2 19:57:33 2016
@@ -27,7 +27,6 @@ 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.impl.builder.CustomBuilder;
 import org.apache.axiom.om.impl.builder.Detachable;
 import org.apache.axiom.om.impl.common.builder.StAXOMBuilder;
 import org.apache.axiom.om.impl.intf.AxiomElement;
@@ -35,7 +34,6 @@ import org.apache.axiom.soap.SOAP11Const
 import org.apache.axiom.soap.SOAP11Version;
 import org.apache.axiom.soap.SOAP12Constants;
 import org.apache.axiom.soap.SOAP12Version;
-import org.apache.axiom.soap.SOAPBody;
 import org.apache.axiom.soap.SOAPConstants;
 import org.apache.axiom.soap.SOAPEnvelope;
 import org.apache.axiom.soap.SOAPFactory;
@@ -76,7 +74,7 @@ public class StAXSOAPModelBuilder extend
 
     public StAXSOAPModelBuilder(OMMetaFactory metaFactory, XMLStreamReader parser,
             boolean autoClose, Detachable detachable, Closeable closeable) {
-        super(metaFactory.getOMFactory(), parser, autoClose, detachable, closeable);
+        super(metaFactory.getOMFactory(), parser, autoClose, detachable, closeable, SOAPPayloadSelector.INSTANCE);
         this.metaFactory = metaFactory;
     }
     
@@ -84,34 +82,6 @@ public class StAXSOAPModelBuilder extend
         return (SOAPEnvelope)getDocumentElement();
     }
 
-    protected OMNode createNextOMElement() {
-        OMNode newElement = null;
-        
-        
-        if (elementLevel == 3 && 
-            customBuilderForPayload != null) {
-            
-            if (target instanceof SOAPBody) {
-                newElement = createWithCustomBuilder(customBuilderForPayload,  soapFactory);
-            }
-        } 
-        if (newElement == null && customBuilders != null && 
-                elementLevel <= maxDepthForCustomBuilders) {
-            String namespace = parser.getNamespaceURI();
-            String localPart = parser.getLocalName();
-            CustomBuilder customBuilder = getCustomBuilder(namespace, localPart);
-            if (customBuilder != null) {
-                newElement = createWithCustomBuilder(customBuilder, soapFactory);
-            }
-        }
-        if (newElement == null) {
-            newElement = createOMElement();
-        } else {
-            elementLevel--; // Decrease level since custom builder read the end element event
-        }
-        return newElement;
-    }
-    
     @Override
     protected Class<? extends AxiomElement> determineElementType(OMContainer parent, String elementName) {
         Class<? extends AxiomElement> elementType;