ws-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From veit...@apache.org
Subject svn commit: r1729052 - in /webservices/axiom/trunk: aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/common/ aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/common/builder/ aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/co...
Date Sun, 07 Feb 2016 23:39:16 GMT
Author: veithen
Date: Sun Feb  7 23:39:16 2016
New Revision: 1729052

URL: http://svn.apache.org/viewvc?rev=1729052&view=rev
Log:
Redesign the CustomBuilder API so that it better fits into the new builder architecture.

Modified:
    webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/common/SAXResultContentHandler.java
    webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/common/builder/BuilderHandler.java
    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/om/impl/common/serializer/push/SerializerImpl.java
    webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/intf/Serializer.java
    webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/mixin/AxiomSourcedElementSupport.aj
    webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/stream/XmlHandler.java
    webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/stream/XmlHandlerWrapper.java
    webservices/axiom/trunk/axiom-api/src/main/java/org/apache/axiom/om/ds/custombuilder/ByteArrayCustomBuilder.java
    webservices/axiom/trunk/axiom-api/src/main/java/org/apache/axiom/om/impl/builder/CustomBuilder.java
    webservices/axiom/trunk/src/site/markdown/release-notes/1.3.0.md
    webservices/axiom/trunk/testing/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/builder/JAXBCustomBuilder.java
    webservices/axiom/trunk/testing/axiom-testsuite/src/main/java/org/apache/axiom/ts/soap/body/FirstElementNameWithParserTestCase.java
    webservices/axiom/trunk/testing/axiom-testsuite/src/main/java/org/apache/axiom/ts/soap/builder/TestRegisterCustomBuilderForPayload.java

Modified: webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/common/SAXResultContentHandler.java
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/common/SAXResultContentHandler.java?rev=1729052&r1=1729051&r2=1729052&view=diff
==============================================================================
--- webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/common/SAXResultContentHandler.java
(original)
+++ webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/common/SAXResultContentHandler.java
Sun Feb  7 23:39:16 2016
@@ -20,12 +20,14 @@ package org.apache.axiom.om.impl.common;
 
 import org.apache.axiom.om.OMAttribute;
 import org.apache.axiom.om.OMContainer;
+import org.apache.axiom.om.OMDataSource;
 import org.apache.axiom.om.OMDocument;
 import org.apache.axiom.om.OMElement;
 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.impl.stream.StreamException;
 import org.apache.axiom.om.impl.stream.XmlHandler;
 
 public final  class SAXResultContentHandler implements XmlHandler {
@@ -117,4 +119,11 @@ public final  class SAXResultContentHand
             throw new UnsupportedOperationException();
         }
     }
+
+    @Override
+    public void processOMDataSource(String namespaceURI, String localName, OMDataSource dataSource)
+            throws StreamException {
+        // TODO
+        throw new UnsupportedOperationException();
+    }
 }

Modified: webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/common/builder/BuilderHandler.java
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/common/builder/BuilderHandler.java?rev=1729052&r1=1729051&r2=1729052&view=diff
==============================================================================
--- webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/common/builder/BuilderHandler.java
(original)
+++ webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/common/builder/BuilderHandler.java
Sun Feb  7 23:39:16 2016
@@ -27,6 +27,8 @@ import javax.xml.stream.XMLStreamConstan
 import org.apache.axiom.core.CoreParentNode;
 import org.apache.axiom.core.NodeFactory;
 import org.apache.axiom.om.OMContainer;
+import org.apache.axiom.om.OMDataSource;
+import org.apache.axiom.om.OMException;
 import org.apache.axiom.om.OMNamespace;
 import org.apache.axiom.om.OMSerializable;
 import org.apache.axiom.om.OMXMLParserWrapper;
@@ -45,6 +47,7 @@ import org.apache.axiom.om.impl.intf.Axi
 import org.apache.axiom.om.impl.intf.AxiomNamespaceDeclaration;
 import org.apache.axiom.om.impl.intf.AxiomProcessingInstruction;
 import org.apache.axiom.om.impl.intf.AxiomSourcedElement;
+import org.apache.axiom.om.impl.stream.StreamException;
 import org.apache.axiom.om.impl.stream.XmlHandler;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
@@ -248,4 +251,20 @@ public final class BuilderHandler implem
         target = null;
         done = true;
     }
+
+    @Override
+    public void processOMDataSource(String namespaceURI, String localName, OMDataSource dataSource)
throws StreamException {
+        Class<? extends AxiomElement> elementType = model.determineElementType(target,
elementLevel+1, namespaceURI, localName);
+        Class<? extends AxiomSourcedElement> sourcedElementType;
+        if (elementType == AxiomElement.class) {
+            sourcedElementType = AxiomSourcedElement.class;
+        } else if (AxiomSourcedElement.class.isAssignableFrom(elementType)) {
+            sourcedElementType = elementType.asSubclass(AxiomSourcedElement.class);
+        } else {
+            throw new OMException("Cannot build an OMSourcedElement where a " + elementType.getName()
+ " is expected");
+        }
+        AxiomSourcedElement element = nodeFactory.createNode(sourcedElementType);
+        element.init(localName, new OMNamespaceImpl(namespaceURI, null), dataSource);
+        addChild(element);
+    }
 }

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=1729052&r1=1729051&r2=1729052&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
Sun Feb  7 23:39:16 2016
@@ -24,6 +24,7 @@ import org.apache.axiom.ext.stax.DTDRead
 import org.apache.axiom.ext.stax.datahandler.DataHandlerReader;
 import org.apache.axiom.om.DeferredParsingException;
 import org.apache.axiom.om.OMContainer;
+import org.apache.axiom.om.OMDataSource;
 import org.apache.axiom.om.OMElement;
 import org.apache.axiom.om.OMException;
 import org.apache.axiom.om.OMFactory;
@@ -576,37 +577,35 @@ public class StAXOMBuilder extends Abstr
         String namespaceURI = normalize(parser.getNamespaceURI());
         String localName = parser.getLocalName();
         String prefix = normalize(parser.getPrefix());
-        OMElement newElement = null;
-        if (customBuilderForPayload != null && payloadSelector.isPayload(builderHandler.elementLevel+1,
builderHandler.target)) {
-            newElement = createWithCustomBuilder(customBuilderForPayload);
+        if (customBuilderForPayload != null && payloadSelector.isPayload(builderHandler.elementLevel+1,
builderHandler.target)
+                && createWithCustomBuilder(customBuilderForPayload)) {
+            return;
         }
-        if (newElement == null && customBuilders != null && builderHandler.elementLevel
< this.maxDepthForCustomBuilders) {
+        if (customBuilders != null && builderHandler.elementLevel < this.maxDepthForCustomBuilders)
{
             CustomBuilder customBuilder = customBuilders.get(namespaceURI, localName);
-            if (customBuilder != null) {
-                newElement = createWithCustomBuilder(customBuilder);
+            if (customBuilder != null && createWithCustomBuilder(customBuilder))
{
+                return;
             }
         }
-        if (newElement == null) {
-            handler.startElement(namespaceURI, localName, prefix);
-            for (int i = 0, count = parser.getNamespaceCount(); i < count; i++) {
-                handler.processNamespaceDeclaration(
-                        normalize(parser.getNamespacePrefix(i)),
-                        normalize(parser.getNamespaceURI(i)));
-            }
-            for (int i = 0, count = parser.getAttributeCount(); i < count; i++) {
-                handler.processAttribute(
-                        normalize(parser.getAttributeNamespace(i)),
-                        parser.getAttributeLocalName(i),
-                        normalize(parser.getAttributePrefix(i)),
-                        parser.getAttributeValue(i),
-                        parser.getAttributeType(i),
-                        parser.isAttributeSpecified(i));
-            }
-            handler.attributesCompleted();
+        handler.startElement(namespaceURI, localName, prefix);
+        for (int i = 0, count = parser.getNamespaceCount(); i < count; i++) {
+            handler.processNamespaceDeclaration(
+                    normalize(parser.getNamespacePrefix(i)),
+                    normalize(parser.getNamespaceURI(i)));
+        }
+        for (int i = 0, count = parser.getAttributeCount(); i < count; i++) {
+            handler.processAttribute(
+                    normalize(parser.getAttributeNamespace(i)),
+                    parser.getAttributeLocalName(i),
+                    normalize(parser.getAttributePrefix(i)),
+                    parser.getAttributeValue(i),
+                    parser.getAttributeType(i),
+                    parser.isAttributeSpecified(i));
         }
+        handler.attributesCompleted();
     }
     
-    private OMElement createWithCustomBuilder(CustomBuilder customBuilder) {
+    private boolean createWithCustomBuilder(CustomBuilder customBuilder) throws StreamException
{
         
         String namespace = parser.getNamespaceURI();
         if (namespace == null) {
@@ -619,31 +618,22 @@ public class StAXOMBuilder extends Abstr
                       ", to the OMNode for {" + namespace + "}" + localPart);
         }
         
-        // TODO: dirty hack part 1
-        // The custom builder will use addNode to insert the new node into the tree. However,
-        // addNode is expected to always add the new child at the end and will attempt to
-        // build the parent node. We temporarily set complete to true to avoid this.
-        // There is really an incompatibility between the contract of addNode and the
-        // custom builder API. This should be fixed in Axiom 1.3.
-        builderHandler.target.setComplete(true);
-        
-        // Use target.getOMFactory() because the factory may actually be a SOAPFactory
-        OMElement node = customBuilder.create(namespace, localPart, builderHandler.target,
parser, builderHandler.target.getOMFactory());
-        
-        // TODO: dirty hack part 2
-        builderHandler.target.setComplete(false);
-        
-        if (log.isDebugEnabled()) {
-            if (node != null) {
+        OMDataSource ds = customBuilder.create(parser);
+        if (ds == null) {
+            if (log.isDebugEnabled()) {
                 log.debug("The CustomBuilder, " + customBuilder.toString() + 
-                          "successfully constructed the OMNode for {" + namespace + "}" +
localPart);
-            } else {
+                        " did not construct an OMDataSource for {" + namespace + "}" + localPart
+
+                        ". The OMElement will be constructed using the installed stax om
builder");
+            }
+            return false;
+        } else {
+            if (log.isDebugEnabled()) {
                 log.debug("The CustomBuilder, " + customBuilder.toString() + 
-                          " did not construct an OMNode for {" + namespace + "}" + localPart
+
-                          ". The OMNode will be constructed using the installed stax om builder");
+                          "successfully constructed the OMDataSource for {" + namespace +
"}" + localPart);
             }
+            handler.processOMDataSource(namespace, localPart, ds);
+            return true;
         }
-        return node;
     }
     
     private void createDTD() throws StreamException {

Modified: webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/common/serializer/push/SerializerImpl.java
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/common/serializer/push/SerializerImpl.java?rev=1729052&r1=1729051&r2=1729052&view=diff
==============================================================================
--- webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/common/serializer/push/SerializerImpl.java
(original)
+++ webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/common/serializer/push/SerializerImpl.java
Sun Feb  7 23:39:16 2016
@@ -207,7 +207,7 @@ public abstract class SerializerImpl imp
      * @throws DeferredParsingException
      *             if an error occurs while reading from the data source
      */
-    public final void serialize(OMDataSource dataSource) throws StreamException {
+    public final void processOMDataSource(String namespaceURI, String localName, OMDataSource
dataSource) throws StreamException {
         // Note: if we can't determine the type (push/pull) of the OMDataSource, we
         // default to push
         if (OMDataSourceUtil.isPullDataSource(dataSource)) {

Modified: webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/intf/Serializer.java
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/intf/Serializer.java?rev=1729052&r1=1729051&r2=1729052&view=diff
==============================================================================
--- webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/intf/Serializer.java
(original)
+++ webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/intf/Serializer.java
Sun Feb  7 23:39:16 2016
@@ -21,7 +21,6 @@ package org.apache.axiom.om.impl.intf;
 import javax.xml.stream.XMLStreamReader;
 
 import org.apache.axiom.ext.stax.datahandler.DataHandlerReader;
-import org.apache.axiom.om.OMDataSource;
 import org.apache.axiom.om.OMElement;
 import org.apache.axiom.om.impl.stream.StreamException;
 import org.apache.axiom.om.impl.stream.XmlHandler;
@@ -29,5 +28,4 @@ import org.apache.axiom.om.impl.stream.X
 public interface Serializer extends XmlHandler {
     void serializeStartpart(OMElement element) throws StreamException;
     void copyEvent(XMLStreamReader reader, DataHandlerReader dataHandlerReader) throws StreamException;
-    void serialize(OMDataSource dataSource) throws StreamException;
 }

Modified: webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/mixin/AxiomSourcedElementSupport.aj
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/mixin/AxiomSourcedElementSupport.aj?rev=1729052&r1=1729051&r2=1729052&view=diff
==============================================================================
--- webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/mixin/AxiomSourcedElementSupport.aj
(original)
+++ webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/mixin/AxiomSourcedElementSupport.aj
Sun Feb  7 23:39:16 2016
@@ -409,10 +409,11 @@ public aspect AxiomSourcedElementSupport
                 forceExpand();
                 defaultInternalSerialize(serializer, format, true);
             } else {
-                serializer.serialize(dataSource);
+                // TODO: the serializer ignores namespaceURI and localName
+                serializer.processOMDataSource(null, null, dataSource);
             }
         } else {
-            serializer.serialize(dataSource); 
+            serializer.processOMDataSource(null, null, dataSource); 
         }
     }
 

Modified: webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/stream/XmlHandler.java
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/stream/XmlHandler.java?rev=1729052&r1=1729051&r2=1729052&view=diff
==============================================================================
--- webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/stream/XmlHandler.java
(original)
+++ webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/stream/XmlHandler.java
Sun Feb  7 23:39:16 2016
@@ -18,6 +18,8 @@
  */
 package org.apache.axiom.om.impl.stream;
 
+import org.apache.axiom.om.OMDataSource;
+
 public interface XmlHandler {
     void startDocument(String inputEncoding, String xmlVersion, String xmlEncoding, boolean
standalone) throws StreamException;
     
@@ -45,4 +47,6 @@ public interface XmlHandler {
     void processCDATASection(String content) throws StreamException;
     
     void processEntityReference(String name, String replacementText) throws StreamException;
+    
+    void processOMDataSource(String namespaceURI, String localName, OMDataSource dataSource)
throws StreamException;
 }

Modified: webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/stream/XmlHandlerWrapper.java
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/stream/XmlHandlerWrapper.java?rev=1729052&r1=1729051&r2=1729052&view=diff
==============================================================================
--- webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/stream/XmlHandlerWrapper.java
(original)
+++ webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/stream/XmlHandlerWrapper.java
Sun Feb  7 23:39:16 2016
@@ -18,6 +18,8 @@
  */
 package org.apache.axiom.om.impl.stream;
 
+import org.apache.axiom.om.OMDataSource;
+
 public class XmlHandlerWrapper implements XmlHandler {
     private final XmlHandler parent;
 
@@ -82,4 +84,9 @@ public class XmlHandlerWrapper implement
     public void processEntityReference(String name, String replacementText) throws StreamException
{
         parent.processEntityReference(name, replacementText);
     }
+
+    public void processOMDataSource(String namespaceURI, String localName, OMDataSource dataSource)
+            throws StreamException {
+        parent.processOMDataSource(namespaceURI, localName, dataSource);
+    }
 }

Modified: webservices/axiom/trunk/axiom-api/src/main/java/org/apache/axiom/om/ds/custombuilder/ByteArrayCustomBuilder.java
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/axiom-api/src/main/java/org/apache/axiom/om/ds/custombuilder/ByteArrayCustomBuilder.java?rev=1729052&r1=1729051&r2=1729052&view=diff
==============================================================================
--- webservices/axiom/trunk/axiom-api/src/main/java/org/apache/axiom/om/ds/custombuilder/ByteArrayCustomBuilder.java
(original)
+++ webservices/axiom/trunk/axiom-api/src/main/java/org/apache/axiom/om/ds/custombuilder/ByteArrayCustomBuilder.java
Sun Feb  7 23:39:16 2016
@@ -19,17 +19,12 @@
 
 package org.apache.axiom.om.ds.custombuilder;
 
-import org.apache.axiom.om.OMContainer;
-import org.apache.axiom.om.OMElement;
+import org.apache.axiom.om.OMDataSource;
 import org.apache.axiom.om.OMException;
-import org.apache.axiom.om.OMFactory;
-import org.apache.axiom.om.OMNamespace;
 import org.apache.axiom.om.ds.ByteArrayDataSource;
 import org.apache.axiom.om.impl.builder.CustomBuilder;
 import org.apache.axiom.om.impl.serialize.StreamingOMSerializer;
 import org.apache.axiom.om.util.StAXUtils;
-import org.apache.axiom.soap.SOAPFactory;
-import org.apache.axiom.soap.SOAPHeader;
 
 import javax.xml.stream.XMLStreamException;
 import javax.xml.stream.XMLStreamReader;
@@ -56,14 +51,7 @@ public class ByteArrayCustomBuilder impl
         this.encoding = (encoding == null) ? "utf-8" :encoding;
     }
 
-    /* 
-     * Create an OMSourcedElement back by a ByteArrayDataSource
-     */
-    public OMElement create(String namespace, 
-                            String localPart, 
-                            OMContainer parent, 
-                            XMLStreamReader reader,
-                            OMFactory factory) throws OMException {
+    public OMDataSource create(XMLStreamReader reader) throws OMException {
         try {
             // Get the prefix of the start tag
             String prefix = reader.getPrefix();
@@ -80,22 +68,7 @@ public class ByteArrayCustomBuilder impl
             
             // Capture the written byte array as a ByteArrayDataSource
             byte[] bytes = baos.toByteArray();
-            String text = new String(bytes, "utf-8");
-            ByteArrayDataSource ds = new ByteArrayDataSource(bytes, encoding);
-            
-            // Create an OMSourcedElement backed by the ByteArrayDataSource
-            OMNamespace ns = factory.createOMNamespace(namespace, prefix);
-            
-            OMElement om = null;
-            if (parent instanceof SOAPHeader && factory instanceof SOAPFactory) {
-                om = ((SOAPFactory)factory).createSOAPHeaderBlock(localPart, ns, ds);
-            } else {
-                om = factory.createOMElement(ds, localPart, ns);
-            }
-            
-            // Add the new OMSourcedElement ot the parent
-            parent.addChild(om);
-            return om;
+            return new ByteArrayDataSource(bytes, encoding);
         } catch (XMLStreamException e) {
             throw new OMException(e);
         } catch (OMException e) {

Modified: webservices/axiom/trunk/axiom-api/src/main/java/org/apache/axiom/om/impl/builder/CustomBuilder.java
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/axiom-api/src/main/java/org/apache/axiom/om/impl/builder/CustomBuilder.java?rev=1729052&r1=1729051&r2=1729052&view=diff
==============================================================================
--- webservices/axiom/trunk/axiom-api/src/main/java/org/apache/axiom/om/impl/builder/CustomBuilder.java
(original)
+++ webservices/axiom/trunk/axiom-api/src/main/java/org/apache/axiom/om/impl/builder/CustomBuilder.java
Sun Feb  7 23:39:16 2016
@@ -19,30 +19,25 @@
 
 package org.apache.axiom.om.impl.builder;
 
-import org.apache.axiom.om.OMContainer;
-import org.apache.axiom.om.OMElement;
+import org.apache.axiom.om.OMDataSource;
 import org.apache.axiom.om.OMException;
-import org.apache.axiom.om.OMFactory;
-import javax.xml.stream.XMLStreamReader;
-
+import org.apache.axiom.om.OMXMLParserWrapper;
 
+import javax.xml.stream.XMLStreamReader;
 
 /**
- * A Custom Builder is registered on the StAXBuilder for a particular QName or payload.
- * When the QName or payload is encountered, the CustomBuilder will build the OMElement
- * or OMSourcedElement for the StAXBuilder.  
+ * A Custom Builder is registered on the {@link OMXMLParserWrapper} for a particular QName
or payload.
+ * When the QName or payload is encountered, the CustomBuilder will build an {@link OMDataSource}
+ * for the builder.
  *
  * @see CustomBuilderSupport#registerCustomBuilder(javax.xml.namespace.QName, int, CustomBuilder)
  * @see CustomBuilderSupport#registerCustomBuilderForPayload(CustomBuilder)
  */
 public interface CustomBuilder {
     /**
-     * Create an OMElement for this whole subtree.
-     * A null is returned if the default StAXBuilder behavior should be used.
-     * @param namespace
-     *            the namespace URI, or the empty string if the element has no namespace
-     * @param localPart
-     * @param parent
+     * Create an {@link OMDataSource} for this whole subtree.
+     * A null is returned if the default builder behavior should be used.
+     * 
      * @param reader
      *            The stream reader to read the StAX events from. The data read
      *            from this reader always represents plain XML, even if the
@@ -86,12 +81,7 @@ public interface CustomBuilder {
      *            XOP encoded stream and wants to get access to the original reader, it should
invoke
      *            {@link org.apache.axiom.util.stax.XMLStreamReaderUtils#getOriginalXMLStreamReader(XMLStreamReader)}
      *            after {@link org.apache.axiom.util.stax.xop.XOPUtils#getXOPEncodedStream(XMLStreamReader)}.
-     * @return null or OMElement
+     * @return null or OMDataSource
      */
-    public OMElement create(String namespace, 
-                            String localPart, 
-                            OMContainer parent, 
-                            XMLStreamReader reader,
-                            OMFactory factory)
-        throws OMException;
+    public OMDataSource create(XMLStreamReader reader) throws OMException;
 }

Modified: webservices/axiom/trunk/src/site/markdown/release-notes/1.3.0.md
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/src/site/markdown/release-notes/1.3.0.md?rev=1729052&r1=1729051&r2=1729052&view=diff
==============================================================================
--- webservices/axiom/trunk/src/site/markdown/release-notes/1.3.0.md (original)
+++ webservices/axiom/trunk/src/site/markdown/release-notes/1.3.0.md Sun Feb  7 23:39:16 2016
@@ -54,3 +54,7 @@ Changes in this release
 
 *   Elements no longer store line number information, and the corresponding
     methods on the `OMElement` interface have been deprecated.
+
+*   The `CustomBuilder` API has changed in an incompatible way. Note that this
+    API was designed to enable some very specific optimizations in Axis2, so
+    that this change should have limited impact.

Modified: webservices/axiom/trunk/testing/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/builder/JAXBCustomBuilder.java
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/testing/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/builder/JAXBCustomBuilder.java?rev=1729052&r1=1729051&r2=1729052&view=diff
==============================================================================
--- webservices/axiom/trunk/testing/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/builder/JAXBCustomBuilder.java
(original)
+++ webservices/axiom/trunk/testing/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/builder/JAXBCustomBuilder.java
Sun Feb  7 23:39:16 2016
@@ -24,13 +24,13 @@ import static org.junit.Assert.assertTru
 import javax.xml.bind.JAXBContext;
 import javax.xml.bind.JAXBException;
 import javax.xml.bind.Unmarshaller;
-import javax.xml.namespace.QName;
+import javax.xml.stream.XMLStreamException;
 import javax.xml.stream.XMLStreamReader;
+import javax.xml.stream.XMLStreamWriter;
 
-import org.apache.axiom.om.OMContainer;
-import org.apache.axiom.om.OMElement;
+import org.apache.axiom.om.OMDataSource;
 import org.apache.axiom.om.OMException;
-import org.apache.axiom.om.OMFactory;
+import org.apache.axiom.om.ds.AbstractPushOMDataSource;
 import org.apache.axiom.om.impl.builder.CustomBuilder;
 import org.apache.axiom.util.stax.xop.XOPEncodedStream;
 import org.apache.axiom.util.stax.xop.XOPUtils;
@@ -46,10 +46,11 @@ public class JAXBCustomBuilder implement
         this.expectBareReader = expectBareReader;
     }
 
-    public OMElement create(String namespaceURI, String localPart,
-            OMContainer parent, XMLStreamReader reader, OMFactory factory)
+    public OMDataSource create(XMLStreamReader reader)
             throws OMException {
         try {
+            final String namespaceURI = reader.getNamespaceURI();
+            final String localName = reader.getLocalName();
             XOPEncodedStream xopStream = XOPUtils.getXOPEncodedStream(reader);
             XMLStreamReader encodedReader = xopStream.getReader();
             if (expectBareReader) {
@@ -61,10 +62,20 @@ public class JAXBCustomBuilder implement
             AttachmentUnmarshallerImpl attachmentUnmarshaller = new AttachmentUnmarshallerImpl(xopStream.getMimePartProvider());
             unmarshaller.setAttachmentUnmarshaller(attachmentUnmarshaller);
             // For the purpose of the test we just store the JAXB object and return
-            // a dummy element. Normally, one would create an OMSourcedElement here.
+            // a dummy OMDataSource.
             jaxbObject = unmarshaller.unmarshal(encodedReader);
             attachmentsAccessed = attachmentUnmarshaller.isAccessed();
-            return factory.createOMElement(new QName(namespaceURI, localPart), parent);
+            return new AbstractPushOMDataSource() {
+                @Override
+                public boolean isDestructiveWrite() {
+                    return false;
+                }
+
+                @Override
+                public void serialize(XMLStreamWriter xmlWriter) throws XMLStreamException
{
+                    xmlWriter.writeEmptyElement("ns1", localName, namespaceURI);
+                }
+            };
         } catch (JAXBException ex) {
             throw new OMException(ex);
         }

Modified: webservices/axiom/trunk/testing/axiom-testsuite/src/main/java/org/apache/axiom/ts/soap/body/FirstElementNameWithParserTestCase.java
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/testing/axiom-testsuite/src/main/java/org/apache/axiom/ts/soap/body/FirstElementNameWithParserTestCase.java?rev=1729052&r1=1729051&r2=1729052&view=diff
==============================================================================
--- webservices/axiom/trunk/testing/axiom-testsuite/src/main/java/org/apache/axiom/ts/soap/body/FirstElementNameWithParserTestCase.java
(original)
+++ webservices/axiom/trunk/testing/axiom-testsuite/src/main/java/org/apache/axiom/ts/soap/body/FirstElementNameWithParserTestCase.java
Sun Feb  7 23:39:16 2016
@@ -25,10 +25,8 @@ import javax.xml.stream.XMLStreamReader;
 
 import junit.framework.AssertionFailedError;
 
-import org.apache.axiom.om.OMContainer;
-import org.apache.axiom.om.OMElement;
+import org.apache.axiom.om.OMDataSource;
 import org.apache.axiom.om.OMException;
-import org.apache.axiom.om.OMFactory;
 import org.apache.axiom.om.OMMetaFactory;
 import org.apache.axiom.om.OMXMLBuilderFactory;
 import org.apache.axiom.om.impl.builder.CustomBuilder;
@@ -63,9 +61,7 @@ public abstract class FirstElementNameWi
             // To detect if the child element is instantiated or not, we register a custom
             // builder that throws an exception.
             ((CustomBuilderSupport)builder).registerCustomBuilderForPayload(new CustomBuilder()
{
-                public OMElement create(String namespace, String localPart,
-                        OMContainer parent, XMLStreamReader reader, OMFactory factory)
-                        throws OMException {
+                public OMDataSource create(XMLStreamReader reader) throws OMException {
                     throw new AssertionFailedError("Custom builder called.");
                 }
             });

Modified: webservices/axiom/trunk/testing/axiom-testsuite/src/main/java/org/apache/axiom/ts/soap/builder/TestRegisterCustomBuilderForPayload.java
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/testing/axiom-testsuite/src/main/java/org/apache/axiom/ts/soap/builder/TestRegisterCustomBuilderForPayload.java?rev=1729052&r1=1729051&r2=1729052&view=diff
==============================================================================
--- webservices/axiom/trunk/testing/axiom-testsuite/src/main/java/org/apache/axiom/ts/soap/builder/TestRegisterCustomBuilderForPayload.java
(original)
+++ webservices/axiom/trunk/testing/axiom-testsuite/src/main/java/org/apache/axiom/ts/soap/builder/TestRegisterCustomBuilderForPayload.java
Sun Feb  7 23:39:16 2016
@@ -23,13 +23,18 @@ import static org.apache.axiom.truth.xml
 
 import java.io.ByteArrayInputStream;
 
+import javax.xml.stream.XMLStreamReader;
+
+import org.apache.axiom.om.OMDataSource;
 import org.apache.axiom.om.OMElement;
+import org.apache.axiom.om.OMException;
 import org.apache.axiom.om.OMMetaFactory;
 import org.apache.axiom.om.OMSourcedElement;
 import org.apache.axiom.om.ds.ByteArrayDataSource;
 import org.apache.axiom.om.ds.ByteArrayDataSource.ByteArray;
 import org.apache.axiom.om.ds.custombuilder.ByteArrayCustomBuilder;
 import org.apache.axiom.om.impl.builder.CustomBuilderSupport;
+import org.apache.axiom.soap.SOAPFault;
 import org.apache.axiom.soap.SOAPModelBuilder;
 import org.apache.axiom.ts.AxiomTestCase;
 import org.apache.axiom.ts.soap.SOAPSample;
@@ -48,10 +53,21 @@ public class TestRegisterCustomBuilderFo
     @Override
     protected void runTest() throws Throwable {
         SOAPModelBuilder builder = message.getAdapter(SOAPSampleAdapter.class).getBuilder(metaFactory);
-        ((CustomBuilderSupport)builder).registerCustomBuilderForPayload(new ByteArrayCustomBuilder("utf-8"));
+        ((CustomBuilderSupport)builder).registerCustomBuilderForPayload(new ByteArrayCustomBuilder("utf-8")
{
+            @Override
+            public OMDataSource create(XMLStreamReader reader) throws OMException {
+                if (reader.getName().equals(message.getSOAPSpec().getFaultQName())) {
+                    return null;
+                } else {
+                    return super.create(reader);
+                }
+            }
+        });
         OMElement payload = builder.getSOAPEnvelope().getBody().getFirstElement();
         if (message.getPayload() == null) {
             assertNull(payload);
+        } else if (message.getPayload().getLocalName().equals("Fault")) {
+            assertTrue(payload instanceof SOAPFault);
         } else {
             assertTrue(payload instanceof OMSourcedElement);
             ByteArray byteArray = (ByteArray)((OMSourcedElement)payload).getObject(ByteArrayDataSource.class);



Mime
View raw message