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/15 20:46:18 UTC

svn commit: r1433603 - in /webservices/commons/trunk/modules/axiom/modules/axiom-common-impl/src/main/java/org/apache/axiom/om/impl/common: ClosedReader.java SwitchingWrapper.java

Author: veithen
Date: Tue Jan 15 19:46:18 2013
New Revision: 1433603

URL: http://svn.apache.org/viewvc?rev=1433603&view=rev
Log:
Use the StreamSwitch to change the XMLStreamReader after the original one has been closed.

Added:
    webservices/commons/trunk/modules/axiom/modules/axiom-common-impl/src/main/java/org/apache/axiom/om/impl/common/ClosedReader.java   (with props)
Modified:
    webservices/commons/trunk/modules/axiom/modules/axiom-common-impl/src/main/java/org/apache/axiom/om/impl/common/SwitchingWrapper.java

Added: webservices/commons/trunk/modules/axiom/modules/axiom-common-impl/src/main/java/org/apache/axiom/om/impl/common/ClosedReader.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-common-impl/src/main/java/org/apache/axiom/om/impl/common/ClosedReader.java?rev=1433603&view=auto
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-common-impl/src/main/java/org/apache/axiom/om/impl/common/ClosedReader.java (added)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-common-impl/src/main/java/org/apache/axiom/om/impl/common/ClosedReader.java Tue Jan 15 19:46:18 2013
@@ -0,0 +1,212 @@
+/*
+ * 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;
+
+import javax.xml.namespace.NamespaceContext;
+import javax.xml.namespace.QName;
+import javax.xml.stream.Location;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
+
+final class ClosedReader implements XMLStreamReader {
+    static final ClosedReader INSTANCE = new ClosedReader();
+    
+    private ClosedReader() {}
+
+    public void close() throws XMLStreamException {
+        // no-op
+    }
+
+    public Object getProperty(String name) throws IllegalArgumentException {
+        return null;
+    }
+
+    public int getAttributeCount() {
+        throw new IllegalStateException("Reader already closed");
+    }
+
+    public String getAttributeLocalName(int index) {
+        throw new IllegalStateException("Reader already closed");
+    }
+
+    public QName getAttributeName(int index) {
+        throw new IllegalStateException("Reader already closed");
+    }
+
+    public String getAttributeNamespace(int index) {
+        throw new IllegalStateException("Reader already closed");
+    }
+
+    public String getAttributePrefix(int index) {
+        throw new IllegalStateException("Reader already closed");
+    }
+
+    public String getAttributeType(int index) {
+        throw new IllegalStateException("Reader already closed");
+    }
+
+    public String getAttributeValue(int index) {
+        throw new IllegalStateException("Reader already closed");
+    }
+
+    public String getAttributeValue(String namespaceURI, String localName) {
+        throw new IllegalStateException("Reader already closed");
+    }
+
+    public String getCharacterEncodingScheme() {
+        throw new IllegalStateException("Reader already closed");
+    }
+
+    public String getElementText() throws XMLStreamException {
+        throw new IllegalStateException("Reader already closed");
+    }
+
+    public String getEncoding() {
+        throw new IllegalStateException("Reader already closed");
+    }
+
+    public int getEventType() {
+        throw new IllegalStateException("Reader already closed");
+    }
+
+    public String getLocalName() {
+        throw new IllegalStateException("Reader already closed");
+    }
+
+    public Location getLocation() {
+        throw new IllegalStateException("Reader already closed");
+    }
+
+    public QName getName() {
+        throw new IllegalStateException("Reader already closed");
+    }
+
+    public NamespaceContext getNamespaceContext() {
+        throw new IllegalStateException("Reader already closed");
+    }
+
+    public int getNamespaceCount() {
+        throw new IllegalStateException("Reader already closed");
+    }
+
+    public String getNamespacePrefix(int index) {
+        throw new IllegalStateException("Reader already closed");
+    }
+
+    public String getNamespaceURI() {
+        throw new IllegalStateException("Reader already closed");
+    }
+
+    public String getNamespaceURI(String prefix) {
+        throw new IllegalStateException("Reader already closed");
+    }
+
+    public String getNamespaceURI(int index) {
+        throw new IllegalStateException("Reader already closed");
+    }
+
+    public String getPIData() {
+        throw new IllegalStateException("Reader already closed");
+    }
+
+    public String getPITarget() {
+        throw new IllegalStateException("Reader already closed");
+    }
+
+    public String getPrefix() {
+        throw new IllegalStateException("Reader already closed");
+    }
+
+    public String getText() {
+        throw new IllegalStateException("Reader already closed");
+    }
+
+    public char[] getTextCharacters() {
+        throw new IllegalStateException("Reader already closed");
+    }
+
+    public int getTextCharacters(int sourceStart, char[] target, int targetStart, int length)
+            throws XMLStreamException {
+        throw new IllegalStateException("Reader already closed");
+    }
+
+    public int getTextLength() {
+        throw new IllegalStateException("Reader already closed");
+    }
+
+    public int getTextStart() {
+        throw new IllegalStateException("Reader already closed");
+    }
+
+    public String getVersion() {
+        throw new IllegalStateException("Reader already closed");
+    }
+
+    public boolean hasName() {
+        throw new IllegalStateException("Reader already closed");
+    }
+
+    public boolean hasNext() throws XMLStreamException {
+        throw new IllegalStateException("Reader already closed");
+    }
+
+    public boolean hasText() {
+        throw new IllegalStateException("Reader already closed");
+    }
+
+    public boolean isAttributeSpecified(int index) {
+        throw new IllegalStateException("Reader already closed");
+    }
+
+    public boolean isCharacters() {
+        throw new IllegalStateException("Reader already closed");
+    }
+
+    public boolean isEndElement() {
+        throw new IllegalStateException("Reader already closed");
+    }
+
+    public boolean isStandalone() {
+        throw new IllegalStateException("Reader already closed");
+    }
+
+    public boolean isStartElement() {
+        throw new IllegalStateException("Reader already closed");
+    }
+
+    public boolean isWhiteSpace() {
+        throw new IllegalStateException("Reader already closed");
+    }
+
+    public int next() throws XMLStreamException {
+        throw new IllegalStateException("Reader already closed");
+    }
+
+    public int nextTag() throws XMLStreamException {
+        throw new IllegalStateException("Reader already closed");
+    }
+
+    public void require(int type, String namespaceURI, String localName) throws XMLStreamException {
+        throw new IllegalStateException("Reader already closed");
+    }
+
+    public boolean standaloneSet() {
+        throw new IllegalStateException("Reader already closed");
+    }
+}

Propchange: webservices/commons/trunk/modules/axiom/modules/axiom-common-impl/src/main/java/org/apache/axiom/om/impl/common/ClosedReader.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: webservices/commons/trunk/modules/axiom/modules/axiom-common-impl/src/main/java/org/apache/axiom/om/impl/common/SwitchingWrapper.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-common-impl/src/main/java/org/apache/axiom/om/impl/common/SwitchingWrapper.java?rev=1433603&r1=1433602&r2=1433603&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-common-impl/src/main/java/org/apache/axiom/om/impl/common/SwitchingWrapper.java (original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-common-impl/src/main/java/org/apache/axiom/om/impl/common/SwitchingWrapper.java Tue Jan 15 19:46:18 2013
@@ -97,8 +97,6 @@ class SwitchingWrapper extends AbstractX
      * if the parser doesn't support this extension.
      */
     private DataHandlerReader dataHandlerReader;
-    
-    private boolean isClosed = false;              // Indicate if parser is closed
 
     /**
      * The root node, i.e. the node from which the {@link XMLStreamReader} has been requested.
@@ -821,24 +819,21 @@ class SwitchingWrapper extends AbstractX
      * @throws XMLStreamException
      */
     public void close() throws XMLStreamException {
-
-        // If there is a builder, it controls its parser
-        if (builder != null && builder instanceof StAXBuilder) {
-            StAXBuilder staxBuilder = (StAXBuilder) builder;
-            staxBuilder.close();
-            setParser(null);
-        } else {
-            if (parser != null) {
-                try {
-                    if (!isClosed()) {
-                        parser.close();
-                    }
-                } finally {
-                    isClosed = true;
-                    // Release the parser so that it can be GC'd or reused.
-                    setParser(null);
+        try {
+            // If there is a builder, it controls its parser
+            if (builder != null && builder instanceof StAXBuilder) {
+                StAXBuilder staxBuilder = (StAXBuilder) builder;
+                staxBuilder.close();
+                setParser(null);
+            } else {
+                if (parser != null) {
+                    parser.close();
                 }
             }
+        } finally {
+            // Note that as a side effect of this instruction, the SwitchingWrapper instance
+            // will become unreachable and the parser can be GC'd or reused.
+            streamSwitch.setParent(ClosedReader.INSTANCE);
         }
     }
 
@@ -1361,20 +1356,6 @@ class SwitchingWrapper extends AbstractX
     }
 
     /**
-     * @return if parser is closed
-     */
-    private boolean isClosed() {
-        
-        // If there is a builder, the builder owns the parser
-        // and knows the isClosed status
-        if (builder != null && builder instanceof StAXBuilder) {
-           return ((StAXBuilder) builder).isClosed();
-        } else {
-            return isClosed;
-        }
-    }
-    
-    /**
      * @return OMDataSource associated with the current node or Null
      */
     public OMDataSource getDataSource() {