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/27 12:34:51 UTC

svn commit: r1732625 - in /webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/mixin: AxiomElementSupport.aj AxiomSourcedElementSupport.aj

Author: veithen
Date: Sat Feb 27 11:34:50 2016
New Revision: 1732625

URL: http://svn.apache.org/viewvc?rev=1732625&view=rev
Log:
Simplify the serialization logic in OMSourcedElement.

Modified:
    webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/mixin/AxiomElementSupport.aj
    webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/mixin/AxiomSourcedElementSupport.aj

Modified: webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/mixin/AxiomElementSupport.aj
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/mixin/AxiomElementSupport.aj?rev=1732625&r1=1732624&r2=1732625&view=diff
==============================================================================
--- webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/mixin/AxiomElementSupport.aj (original)
+++ webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/mixin/AxiomElementSupport.aj Sat Feb 27 11:34:50 2016
@@ -43,8 +43,11 @@ import org.apache.axiom.core.CoreParentN
 import org.apache.axiom.core.ElementAction;
 import org.apache.axiom.core.ElementMatcher;
 import org.apache.axiom.core.Mapper;
+import org.apache.axiom.core.stream.DocumentElementExtractingFilterHandler;
 import org.apache.axiom.core.stream.StreamException;
 import org.apache.axiom.core.stream.XmlHandler;
+import org.apache.axiom.core.stream.XmlInput;
+import org.apache.axiom.core.stream.XmlReader;
 import org.apache.axiom.om.OMAttribute;
 import org.apache.axiom.om.OMConstants;
 import org.apache.axiom.om.OMContainer;
@@ -528,18 +531,28 @@ public aspect AxiomElementSupport {
         return findNamespaceURI("");
     }
 
-    public void AxiomElement.internalSerialize(XmlHandler handler, boolean cache) throws StreamException {
-        defaultInternalSerialize(handler, cache);
+    public XmlInput AxiomElement.getXmlInput(boolean cache) throws StreamException {
+        return null;
     }
     
-    public final void AxiomElement.defaultInternalSerialize(XmlHandler handler, boolean cache) throws StreamException {
-        try {
-            coreSerializeStartPart(handler);
-        } catch (CoreModelException ex) {
-            throw new StreamException(ex);
+    public final void AxiomElement.internalSerialize(XmlHandler handler, boolean cache) throws StreamException {
+        XmlInput input = getXmlInput(cache);
+        if (input != null) {
+            // TODO: the serializer ignores namespaceURI and localName
+            XmlReader reader = input.createReader(new DocumentElementExtractingFilterHandler(handler));
+            while (!reader.proceed()) {
+                // Just loop
+            }
+        } else {
+            forceExpand();
+            try {
+                coreSerializeStartPart(handler);
+            } catch (CoreModelException ex) {
+                throw new StreamException(ex);
+            }
+            serializeChildren(handler, cache);
+            handler.endElement();
         }
-        serializeChildren(handler, cache);
-        handler.endElement();
     }
 
     public final String AxiomElement.toStringWithConsume() throws XMLStreamException {

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=1732625&r1=1732624&r2=1732625&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 Sat Feb 27 11:34:50 2016
@@ -22,11 +22,8 @@ import org.apache.axiom.core.Builder;
 import org.apache.axiom.core.ClonePolicy;
 import org.apache.axiom.core.CoreElement;
 import org.apache.axiom.core.CoreNode;
-import org.apache.axiom.core.stream.DocumentElementExtractingFilterHandler;
 import org.apache.axiom.core.stream.StreamException;
-import org.apache.axiom.core.stream.XmlHandler;
 import org.apache.axiom.core.stream.XmlInput;
-import org.apache.axiom.core.stream.XmlReader;
 import org.apache.axiom.om.OMCloneOptions;
 import org.apache.axiom.om.OMDataSource;
 import org.apache.axiom.om.OMDataSourceExt;
@@ -406,31 +403,20 @@ public aspect AxiomSourcedElementSupport
         }
     }
 
-    public void AxiomSourcedElement.internalSerialize(XmlHandler handler, boolean cache)
-            throws StreamException {
-        if (isExpanded()) {
-            defaultInternalSerialize(handler, cache);
-        } else if (cache&& OMDataSourceUtil.isDestructiveWrite(dataSource)) {
-            forceExpand();
-            defaultInternalSerialize(handler, true);
-        } else {
-            XmlInput input;
-            // Note: if we can't determine the type (push/pull) of the OMDataSource, we
-            // default to push
-            if (OMDataSourceUtil.isPullDataSource(dataSource)) {
-                try {
-                    input = new StAXPullInput(dataSource.getReader());
-                } catch (XMLStreamException ex) {
-                    throw new StreamException(ex);
-                }
-            } else {
-                input = new PushOMDataSourceInput(this, dataSource);
-            }
-            // TODO: the serializer ignores namespaceURI and localName
-            XmlReader reader = input.createReader(new DocumentElementExtractingFilterHandler(handler));
-            while (!reader.proceed()) {
-                // Just loop
+    public final XmlInput AxiomSourcedElement.getXmlInput(boolean cache) throws StreamException {
+        if (isExpanded() || (cache && OMDataSourceUtil.isDestructiveWrite(dataSource))) {
+            return null;
+        }
+        // Note: if we can't determine the type (push/pull) of the OMDataSource, we
+        // default to push
+        if (OMDataSourceUtil.isPullDataSource(dataSource)) {
+            try {
+                return new StAXPullInput(dataSource.getReader());
+            } catch (XMLStreamException ex) {
+                throw new StreamException(ex);
             }
+        } else {
+            return new PushOMDataSourceInput(this, dataSource);
         }
     }