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 2012/12/20 10:33:33 UTC
svn commit: r1424378 - in /webservices/commons/trunk/modules/axiom/modules:
axiom-api/src/main/java/org/apache/axiom/om/impl/builder/
axiom-testsuite/src/main/java/org/apache/axiom/ts/om/
axiom-testsuite/src/main/java/org/apache/axiom/ts/om/builder/
Author: veithen
Date: Thu Dec 20 09:33:33 2012
New Revision: 1424378
URL: http://svn.apache.org/viewvc?rev=1424378&view=rev
Log:
Performance improvement: give Woodstox a chance to recycle symbol tables.
Added:
webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/builder/TestGetDocumentElementWithDiscardDocumentIllFormedEpilog.java (with props)
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-testsuite/src/main/java/org/apache/axiom/ts/om/OMTestSuiteBuilder.java
webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/builder/TestGetDocumentElementWithDiscardDocument.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=1424378&r1=1424377&r2=1424378&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 Thu Dec 20 09:33:33 2012
@@ -120,6 +120,7 @@ public class StAXOMBuilder extends StAXB
String characterEncoding) {
// Use this constructor because the parser is passed the START_DOCUMENT state.
super(factory, parser, characterEncoding);
+ elementLevel = 1;
target = (OMContainerEx)element;
populateOMElement(element);
}
@@ -270,6 +271,23 @@ public class StAXOMBuilder extends StAXB
default :
throw new OMException();
}
+
+ if (target == null && !done) {
+ // We get here if the document has been discarded (using getDocumentElement(true)) 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.
+ // * Many parsers will perform some cleanup when the end of the document is reached.
+ // For example, Woodstox will recycle the symbol table if the parser gets past the
+ // 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().
+ while (parserNext() != XMLStreamConstants.END_DOCUMENT) {
+ // Just loop
+ }
+ done = true;
+ }
+
return token;
}
} catch (XMLStreamException e) {
@@ -533,7 +551,14 @@ public class StAXOMBuilder extends StAXB
private void endElement() {
target.setComplete(true);
- target = (OMContainerEx)((OMElement)target).getParent();
+ if (elementLevel == 0) {
+ // This is relevant for OMSourcedElements and for the case where the document has been discarded
+ // using getDocumentElement(true). In these cases, this will actually set target to null. In all
+ // other cases, this will have the same effect as the instruction in the else clause.
+ target = (OMContainerEx)document;
+ } else {
+ target = (OMContainerEx)((OMElement)target).getParent();
+ }
}
public OMElement getDocumentElement() {
@@ -547,6 +572,7 @@ public class StAXOMBuilder extends StAXB
nodeEx.setParent(null);
nodeEx.setPreviousOMSibling(null);
nodeEx.setNextOMSibling(null);
+ document = null;
}
return element;
}
Modified: webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/OMTestSuiteBuilder.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/OMTestSuiteBuilder.java?rev=1424378&r1=1424377&r2=1424378&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/OMTestSuiteBuilder.java (original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/OMTestSuiteBuilder.java Thu Dec 20 09:33:33 2012
@@ -99,6 +99,7 @@ public class OMTestSuiteBuilder extends
addTest(new org.apache.axiom.ts.om.builder.TestCreateStAXOMBuilderNamespaceRepairing2(metaFactory));
addTest(new org.apache.axiom.ts.om.builder.TestGetDocumentElement(metaFactory));
addTest(new org.apache.axiom.ts.om.builder.TestGetDocumentElementWithDiscardDocument(metaFactory));
+ addTest(new org.apache.axiom.ts.om.builder.TestGetDocumentElementWithDiscardDocumentIllFormedEpilog(metaFactory));
addTest(new org.apache.axiom.ts.om.builder.TestGetDocumentElementWithIllFormedDocument(metaFactory));
addTest(new org.apache.axiom.ts.om.builder.TestInvalidXML(metaFactory));
addTest(new org.apache.axiom.ts.om.builder.TestIOExceptionInGetText(metaFactory));
Modified: webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/builder/TestGetDocumentElementWithDiscardDocument.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/builder/TestGetDocumentElementWithDiscardDocument.java?rev=1424378&r1=1424377&r2=1424378&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/builder/TestGetDocumentElementWithDiscardDocument.java (original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/builder/TestGetDocumentElementWithDiscardDocument.java Thu Dec 20 09:33:33 2012
@@ -26,6 +26,7 @@ import org.apache.axiom.om.OMMetaFactory
import org.apache.axiom.om.OMXMLBuilderFactory;
import org.apache.axiom.om.OMXMLParserWrapper;
import org.apache.axiom.ts.AxiomTestCase;
+import org.custommonkey.xmlunit.XMLAssert;
/**
* Tests the behavior of {@link OMXMLParserWrapper#getDocumentElement(boolean)} with
@@ -49,5 +50,13 @@ public class TestGetDocumentElementWithD
OMElement newParent = factory.createOMElement("newParent", null);
newParent.addChild(element);
assertFalse(element.isComplete());
+ assertFalse(builder.isCompleted());
+ XMLAssert.assertXMLEqual("<newParent><root/></newParent>", newParent.toString());
+ assertTrue(element.isComplete());
+ // Since we discarded the document, the nodes in the epilog will not be accessible.
+ // Therefore we expect that when the document element changes its completion status,
+ // the builder will consume the epilog and change its completion status as well.
+ // This gives the underlying parser a chance to release some resources.
+ assertTrue(builder.isCompleted());
}
}
Added: webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/builder/TestGetDocumentElementWithDiscardDocumentIllFormedEpilog.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/builder/TestGetDocumentElementWithDiscardDocumentIllFormedEpilog.java?rev=1424378&view=auto
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/builder/TestGetDocumentElementWithDiscardDocumentIllFormedEpilog.java (added)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/builder/TestGetDocumentElementWithDiscardDocumentIllFormedEpilog.java Thu Dec 20 09:33:33 2012
@@ -0,0 +1,53 @@
+/*
+ * 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.ts.om.builder;
+
+import java.io.StringReader;
+
+import org.apache.axiom.om.OMElement;
+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.OMXMLParserWrapper;
+import org.apache.axiom.ts.AxiomTestCase;
+
+/**
+ * Tests the behavior of {@link OMXMLParserWrapper#getDocumentElement(boolean)} with
+ * <code>discardDocument</code> set to <code>true</code> and a document that has an epilog that is
+ * not well formed. This situation should be detected.
+ */
+public class TestGetDocumentElementWithDiscardDocumentIllFormedEpilog extends AxiomTestCase {
+ public TestGetDocumentElementWithDiscardDocumentIllFormedEpilog(OMMetaFactory metaFactory) {
+ super(metaFactory);
+ }
+
+ protected void runTest() throws Throwable {
+ OMFactory factory = metaFactory.getOMFactory();
+ OMXMLParserWrapper builder = OMXMLBuilderFactory.createOMBuilder(factory,
+ new StringReader("<root/> there shouldn't be text here!"));
+ OMElement element = builder.getDocumentElement(true);
+ try {
+ element.build();
+ fail("Expected OMException");
+ } catch (OMException ex) {
+ // Expected
+ }
+ }
+}
Propchange: webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/builder/TestGetDocumentElementWithDiscardDocumentIllFormedEpilog.java
------------------------------------------------------------------------------
svn:eol-style = native