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 2013/01/06 16:18:53 UTC

svn commit: r1429539 - in /webservices/commons/trunk/modules/axiom/modules: axiom-api/src/main/java/org/apache/axiom/om/impl/builder/ axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/ axiom-testsuite/src/main/java/org/apache/axiom/ts/om/sourcedel...

Author: veithen
Date: Sun Jan  6 15:18:52 2013
New Revision: 1429539

URL: http://svn.apache.org/viewvc?rev=1429539&view=rev
Log:
AXIOM-443: Ensure that OMSourcedElementImpl doesn't continue to use the parser returned by OMDataSource#getReader() after it has been closed. This causes no problem with Woodstox, but XLXP 1 correctly complains about this.

This fixes a regression caused by r1424378.

Modified:
    webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/builder/StAXOMBuilder.java
    webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMSourcedElementImpl.java
    webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/sourcedelement/CloseTestXMLStreamReaderWrapper.java

Modified: webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/builder/StAXOMBuilder.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/builder/StAXOMBuilder.java?rev=1429539&r1=1429538&r2=1429539&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/builder/StAXOMBuilder.java (original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/builder/StAXOMBuilder.java Sun Jan  6 15:18:52 2013
@@ -94,6 +94,12 @@ public class StAXOMBuilder extends StAXB
     // on an OMElement is interned.
     private boolean namespaceURIInterning = false;
     
+    /**
+     * Specifies whether the builder/parser should be automatically closed when the
+     * {@link XMLStreamConstants#END_DOCUMENT} event is reached.
+     */
+    private boolean autoClose;
+    
     private int lookAheadToken = -1;
     
     /**
@@ -273,7 +279,8 @@ public class StAXOMBuilder extends StAXB
                 }
                 
                 if (target == null && !done) {
-                    // We get here if the document has been discarded (using getDocumentElement(true)) and
+                    // We get here if the document has been discarded (by getDocumentElement(true)
+                    // or because the builder is linked to an OMSourcedElement) and
                     // we just processed the END_ELEMENT event for the root element. In this case, we consume
                     // the remaining events until we reach the end of the document. This serves several purposes:
                     //  * It allows us to detect documents that have an epilog that is not well formed.
@@ -282,6 +289,8 @@ public class StAXOMBuilder extends StAXB
                     //    last END_ELEMENT. This improves performance because Woodstox by default interns
                     //    all symbols; if the symbol table can be recycled, then this reduces the number of
                     //    calls to String#intern().
+                    //  * If autoClose is set, the parser will be closed so that even more resources
+                    //    can be released.
                     while (parserNext() != XMLStreamConstants.END_DOCUMENT) {
                         // Just loop
                     }
@@ -652,6 +661,15 @@ public class StAXOMBuilder extends StAXB
     }
     
     /**
+     * For internal use only.
+     * 
+     * @param autoClose
+     */
+    public void setAutoClose(boolean autoClose) {
+        this.autoClose = autoClose;
+    }
+
+    /**
      * Pushes the virtual parser ahead one token.
      * If a look ahead token was calculated it is returned.
      * @return next token
@@ -690,6 +708,9 @@ public class StAXOMBuilder extends StAXB
                     if (elementLevel != 0) {
                         throw new OMException("Unexpected END_DOCUMENT event");
                     }
+                    if (autoClose) {
+                        close();
+                    }
                     break;
             }
             return event;

Modified: webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMSourcedElementImpl.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMSourcedElementImpl.java?rev=1429539&r1=1429538&r2=1429539&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMSourcedElementImpl.java (original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMSourcedElementImpl.java Sun Jan  6 15:18:52 2013
@@ -93,8 +93,6 @@ public class OMSourcedElementImpl extend
     
     private static final Log forceExpandLog = LogFactory.getLog(OMSourcedElementImpl.class.getName() + ".forceExpand");
     
-    private XMLStreamReader readerFromDS = null;  // Reader from DataSource
-
     private static OMNamespace getOMNamespace(QName qName) {
         return qName.getNamespaceURI().length() == 0 ? null
                 : new OMNamespaceImpl(qName.getNamespaceURI(), qName.getPrefix());
@@ -251,6 +249,7 @@ public class OMSourcedElementImpl extend
                 }
             } else {
                 // Get the XMLStreamReader
+                XMLStreamReader readerFromDS;
                 try {
                     readerFromDS = dataSource.getReader();  
                 } catch (XMLStreamException ex) {
@@ -276,10 +275,10 @@ public class OMSourcedElementImpl extend
                 // Set the builder for this element. Note that the StAXOMBuilder constructor will also
                 // update the namespace of the element, so we don't need to do that here.
                 isExpanded = true;
-                super.setBuilder(new StAXOMBuilder(getOMFactory(), 
-                                                   readerFromDS, 
-                                                   this, 
-                                                   characterEncoding));
+                StAXOMBuilder builder = new StAXOMBuilder(getOMFactory(), readerFromDS, this, characterEncoding);
+                builder.setAutoClose(true);
+                builder.releaseParserOnClose(true);
+                super.setBuilder(builder);
                 setComplete(false);
             }
         }
@@ -1029,29 +1028,13 @@ public class OMSourcedElementImpl extend
      * expansion process. Thus calls to setCompete should stop here and not propogate up to the
      * parent (which may have a different builder or no builder).
      */
-    public void setComplete(boolean value) {
-        state = value ? COMPLETE : INCOMPLETE;
-        if (value == true) {
-            if (readerFromDS != null) {
-                try {
-                    readerFromDS.close();
-                } catch (XMLStreamException e) {
-                }
-                readerFromDS = null;
-            }
-            if (dataSource != null) {
-                if (dataSource instanceof OMDataSourceExt) {
-                    ((OMDataSourceExt)dataSource).close();
-                }
-                dataSource = null;
-            }
-        }
-        if (value == true && readerFromDS != null) {
-            try {
-                readerFromDS.close();
-            } catch (XMLStreamException e) {
+    public void setComplete(boolean complete) {
+        state = complete ? COMPLETE : INCOMPLETE;
+        if (complete && dataSource != null) {
+            if (dataSource instanceof OMDataSourceExt) {
+                ((OMDataSourceExt)dataSource).close();
             }
-            readerFromDS = null;
+            dataSource = null;
         }
     }
     

Modified: webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/sourcedelement/CloseTestXMLStreamReaderWrapper.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/sourcedelement/CloseTestXMLStreamReaderWrapper.java?rev=1429539&r1=1429538&r2=1429539&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/sourcedelement/CloseTestXMLStreamReaderWrapper.java (original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/sourcedelement/CloseTestXMLStreamReaderWrapper.java Sun Jan  6 15:18:52 2013
@@ -25,6 +25,7 @@ import org.apache.axiom.util.stax.wrappe
 
 class CloseTestXMLStreamReaderWrapper extends XMLStreamReaderWrapper {
     private final CloseTestDataSource ds;
+    private boolean closed;
     
     CloseTestXMLStreamReaderWrapper(CloseTestDataSource ds, XMLStreamReader parent) {
         super(parent);
@@ -34,5 +35,13 @@ class CloseTestXMLStreamReaderWrapper ex
     public void close() throws XMLStreamException {
         super.close();
         ds.readerClosed(this);
+        closed = true;
+    }
+
+    public int next() throws XMLStreamException {
+        if (closed) {
+            throw new IllegalStateException();
+        }
+        return super.next();
     }
 }