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/07/11 23:27:03 UTC
svn commit: r1360410 - in /webservices/commons/trunk/modules/axiom/modules:
axiom-api/src/main/java/org/apache/axiom/om/
axiom-api/src/main/java/org/apache/axiom/om/impl/builder/
axiom-testsuite/src/main/java/org/apache/axiom/ts/om/ axiom-testsuite/src...
Author: veithen
Date: Wed Jul 11 21:27:03 2012
New Revision: 1360410
URL: http://svn.apache.org/viewvc?rev=1360410&view=rev
Log:
Don't let the builder create an OMDocument for an OMSourcedElement. This is useless.
Added:
webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/sourcedelement/TestGetDocumentFromBuilder.java (with props)
Modified:
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/OMXMLParserWrapper.java
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/builder/StAXBuilder.java
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
Modified: webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/OMXMLParserWrapper.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/OMXMLParserWrapper.java?rev=1360410&r1=1360409&r2=1360410&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/OMXMLParserWrapper.java (original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/OMXMLParserWrapper.java Wed Jul 11 21:27:03 2012
@@ -70,6 +70,9 @@ public interface OMXMLParserWrapper {
* Get the document being built by this builder.
*
* @return the {@link OMDocument} instance
+ * @throws UnsupportedOperationException
+ * if there is no document linked to this builder; this may occur if the builder is
+ * associated with an {@link OMSourcedElement}
*/
OMDocument getDocument();
@@ -86,6 +89,9 @@ public interface OMXMLParserWrapper {
* @return the document element
* @throws OMException
* if a parse error occurs
+ * @throws UnsupportedOperationException
+ * if there is no document linked to this builder; this may occur if the builder is
+ * associated with an {@link OMSourcedElement}
*/
OMElement getDocumentElement();
@@ -104,6 +110,9 @@ public interface OMXMLParserWrapper {
* @return the document element
* @throws OMException
* if a parse error occurs
+ * @throws UnsupportedOperationException
+ * if there is no document linked to this builder; this may occur if the builder is
+ * associated with an {@link OMSourcedElement}
*/
OMElement getDocumentElement(boolean discardDocument);
Modified: webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/builder/StAXBuilder.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/builder/StAXBuilder.java?rev=1360410&r1=1360409&r2=1360410&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/builder/StAXBuilder.java (original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/builder/StAXBuilder.java Wed Jul 11 21:27:03 2012
@@ -603,6 +603,9 @@ public abstract class StAXBuilder implem
}
public OMDocument getDocument() {
+ if (document == null) {
+ throw new UnsupportedOperationException("There is no document linked to this builder");
+ }
return document;
}
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=1360410&r1=1360409&r2=1360410&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 Wed Jul 11 21:27:03 2012
@@ -116,7 +116,6 @@ public class StAXOMBuilder extends StAXB
String characterEncoding) {
// Use this constructor because the parser is passed the START_DOCUMENT state.
super(factory, parser, characterEncoding);
- document = createDocument();
target = (OMContainerEx)element;
populateOMElement(element);
}
@@ -173,17 +172,9 @@ public class StAXOMBuilder extends StAXB
if (charEncoding != null) {
document.setCharsetEncoding(charEncoding);
}
- if (parser.getEventType() == XMLStreamConstants.START_DOCUMENT) {
- document.setXMLVersion(parser.getVersion());
- document.setXMLEncoding(parser.getCharacterEncodingScheme());
- document.setStandalone(parser.isStandalone() ? "yes" : "no");
- } else {
- // We allow creating a StAXOMWrapper from a parser in state START_ELEMENT. In that
- // case, we must not call getVersion or isStandalone since this is forbidden by the
- // StAX specs. Set some reasonable defaults.
- document.setXMLVersion("1.0");
- document.setStandalone("yes");
- }
+ document.setXMLVersion(parser.getVersion());
+ document.setXMLEncoding(parser.getCharacterEncodingScheme());
+ document.setStandalone(parser.isStandalone() ? "yes" : "no");
return document;
}
@@ -519,7 +510,7 @@ public class StAXOMBuilder extends StAXB
}
public OMElement getDocumentElement(boolean discardDocument) {
- OMElement element = document.getOMDocumentElement();
+ OMElement element = getDocument().getOMDocumentElement();
if (discardDocument) {
OMNodeEx nodeEx = (OMNodeEx)element;
nodeEx.setParent(null);
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=1360410&r1=1360409&r2=1360410&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 Wed Jul 11 21:27:03 2012
@@ -363,6 +363,7 @@ public class OMTestSuiteBuilder extends
addTest(new org.apache.axiom.ts.om.sourcedelement.TestCloneOMElementUnknownName(metaFactory));
addTest(new org.apache.axiom.ts.om.sourcedelement.TestComplete(metaFactory));
addTest(new org.apache.axiom.ts.om.sourcedelement.TestExpand(metaFactory));
+ addTest(new org.apache.axiom.ts.om.sourcedelement.TestGetDocumentFromBuilder(metaFactory));
addTest(new org.apache.axiom.ts.om.sourcedelement.TestGetNamespaceNormalized(metaFactory));
addTest(new org.apache.axiom.ts.om.sourcedelement.TestGetNamespaceNormalized2(metaFactory));
addTest(new org.apache.axiom.ts.om.sourcedelement.TestGetNextOMSiblingIncomplete(metaFactory));
Added: webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/sourcedelement/TestGetDocumentFromBuilder.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/sourcedelement/TestGetDocumentFromBuilder.java?rev=1360410&view=auto
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/sourcedelement/TestGetDocumentFromBuilder.java (added)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/sourcedelement/TestGetDocumentFromBuilder.java Wed Jul 11 21:27:03 2012
@@ -0,0 +1,59 @@
+/*
+ * 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.sourcedelement;
+
+import org.apache.axiom.om.OMDataSource;
+import org.apache.axiom.om.OMFactory;
+import org.apache.axiom.om.OMMetaFactory;
+import org.apache.axiom.om.OMSourcedElement;
+import org.apache.axiom.om.OMXMLParserWrapper;
+import org.apache.axiom.om.ds.ByteArrayDataSource;
+import org.apache.axiom.ts.AxiomTestCase;
+
+/**
+ * Tests that {@link OMXMLParserWrapper#getDocument()} and {@link OMXMLParserWrapper#getDocumentElement()}
+ * throw {@link UnsupportedOperationException} when invoked on the builder
+ * associated with an {@link OMSourcedElement}.
+ */
+public class TestGetDocumentFromBuilder extends AxiomTestCase {
+ public TestGetDocumentFromBuilder(OMMetaFactory metaFactory) {
+ super(metaFactory);
+ }
+
+ protected void runTest() throws Throwable {
+ OMFactory factory = metaFactory.getOMFactory();
+ OMDataSource ds = new ByteArrayDataSource("<root><a/></root>".getBytes("utf-8"), "utf-8");
+ OMSourcedElement element = factory.createOMElement(ds);
+ // Force expansion
+ element.getFirstOMChild();
+ OMXMLParserWrapper builder = element.getBuilder();
+ try {
+ builder.getDocument();
+ fail("Expected UnsupportedOperationException");
+ } catch (UnsupportedOperationException ex) {
+ // Expected
+ }
+ try {
+ builder.getDocumentElement();
+ fail("Expected UnsupportedOperationException");
+ } catch (UnsupportedOperationException ex) {
+ // Expected
+ }
+ }
+}
Propchange: webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/sourcedelement/TestGetDocumentFromBuilder.java
------------------------------------------------------------------------------
svn:eol-style = native