Author: veithen
Date: Wed Dec 29 17:44:11 2010
New Revision: 1053681
URL: http://svn.apache.org/viewvc?rev=1053681&view=rev
Log:
Implemented the new API described in AXIOM-313 so that we can get rid of some
references to OMNodeEx (which is an internal API) in Axis2.
Added:
webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/builder/TestGetDocumentElementWithDiscardDocument.java
(with props)
webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/TestSerializationWithTwoNonBuiltOMElements.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/StAXOMBuilder.java
webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/ChildNode.java
webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/om/SerializationTest.java
webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/AxiomTestSuiteBuilder.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=1053681&r1=1053680&r2=1053681&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 Dec 29 17:44:11 2010
@@ -83,6 +83,22 @@ public interface OMXMLParserWrapper {
OMElement getDocumentElement();
/**
+ * Get the document element, optionally discarding the document. The
return value of this method
+ * is the same as {...@link #getDocumentElement()}. However, if the
<code>discardDocument</code>
+ * parameter is set to <code>true</code>, then the document element is
removed from the document
+ * and the document itself is discarded. In contrast to using {...@link
OMElement#detach()} this
+ * will not build the element. The implementation also ensures that the
element is not built
+ * when it is added to another OM tree. This makes it possible to add the
content of a document
+ * to an existing OM tree while preserving the deferred parsing feature.
It is even possible to
+ * create an OM tree where different subtrees are associated with
different builder instances.
+ *
+ * @param discardDocument
+ * specifies whether the document should be discarded
+ * @return the document element
+ */
+ OMElement getDocumentElement(boolean discardDocument);
+
+ /**
* Returns the type of the builder. Can be either {...@link
OMConstants#PUSH_TYPE_BUILDER}
* or {...@link OMConstants#PULL_TYPE_BUILDER}.
*
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=1053681&r1=1053680&r2=1053681&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 Dec 29 17:44:11 2010
@@ -560,7 +560,18 @@ public class StAXOMBuilder extends StAXB
}
public OMElement getDocumentElement() {
- return document.getOMDocumentElement();
+ return getDocumentElement(false);
+ }
+
+ public OMElement getDocumentElement(boolean discardDocument) {
+ OMElement element = document.getOMDocumentElement();
+ if (discardDocument) {
+ OMNodeEx nodeEx = (OMNodeEx)element;
+ nodeEx.setParent(null);
+ nodeEx.setPreviousOMSibling(null);
+ nodeEx.setNextOMSibling(null);
+ }
+ return element;
}
/**
Modified:
webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/ChildNode.java
URL:
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/ChildNode.java?rev=1053681&r1=1053680&r2=1053681&view=diff
==============================================================================
---
webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/ChildNode.java
(original)
+++
webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/ChildNode.java
Wed Dec 29 17:44:11 2010
@@ -102,7 +102,7 @@ public abstract class ChildNode extends
}
public void setParent(OMContainer element) {
- if (element instanceof ParentNode) {
+ if (element == null || element instanceof ParentNode) {
this.parentNode = (ParentNode) element;
} else {
throw new OMException("The given parent is not of the type "
Modified:
webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/om/SerializationTest.java
URL:
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/om/SerializationTest.java?rev=1053681&r1=1053680&r2=1053681&view=diff
==============================================================================
---
webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/om/SerializationTest.java
(original)
+++
webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/om/SerializationTest.java
Wed Dec 29 17:44:11 2010
@@ -20,11 +20,6 @@
package org.apache.axiom.om;
import junit.framework.TestCase;
-import org.apache.axiom.om.impl.OMNodeEx;
-import org.apache.axiom.om.impl.builder.StAXOMBuilder;
-
-import javax.xml.stream.XMLStreamException;
-import java.io.ByteArrayInputStream;
public class SerializationTest extends TestCase {
/**
@@ -48,35 +43,4 @@ public class SerializationTest extends T
assertEquals("Incorrect serialization", 2,
xml.split("xmlns=\"\"").length);
}
-
- public void testOMSerializationWithTwoNonBuiltOMElements() {
- try {
- String sampleXMLOne =
"<ChildOne><Name>ChildName</Name></ChildOne>";
- String sampleXMLTwo =
"<ChildTwo><Name>ChildName</Name></ChildTwo>";
-
- String expectedXML =
-
"<Root><ChildOne><Name>ChildName</Name></ChildOne><ChildTwo><Name>ChildName</Name></ChildTwo></Root>";
- OMFactory omFactory = OMAbstractFactory.getOMFactory();
-
- OMElement rootElement = omFactory.createOMElement("Root", null);
- OMElement childOne =
- new StAXOMBuilder(new
ByteArrayInputStream(sampleXMLOne.getBytes()))
- .getDocumentElement();
- ((OMNodeEx) childOne).setParent(null);
- rootElement.addChild(childOne);
- OMElement childTwo =
- new StAXOMBuilder(new
ByteArrayInputStream(sampleXMLTwo.getBytes()))
- .getDocumentElement();
- ((OMNodeEx) childTwo).setParent(null);
- rootElement.addChild(childTwo);
-
- assertTrue(expectedXML.equals(rootElement.toString()));
-
- childOne.close(false);
- childTwo.close(false);
- } catch (XMLStreamException e) {
- e.printStackTrace(); //To change body of catch statement use File
| Settings | File Templates.
- }
- }
-
}
Modified:
webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/AxiomTestSuiteBuilder.java
URL:
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/AxiomTestSuiteBuilder.java?rev=1053681&r1=1053680&r2=1053681&view=diff
==============================================================================
---
webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/AxiomTestSuiteBuilder.java
(original)
+++
webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/AxiomTestSuiteBuilder.java
Wed Dec 29 17:44:11 2010
@@ -41,6 +41,7 @@ public class AxiomTestSuiteBuilder {
public TestSuite build() {
suite = new TestSuite();
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.attribute.TestGetQName(metaFactory));
addTest(new
org.apache.axiom.ts.om.element.TestAddAttributeWithExistingNamespaceDeclarationInScope(metaFactory));
addTest(new
org.apache.axiom.ts.om.element.TestAddAttributeWithExistingNamespaceDeclarationOnSameElement(metaFactory));
@@ -70,6 +71,7 @@ public class AxiomTestSuiteBuilder {
"<person><p:name xmlns:p=\"urn:ns\">John</p:name><p:age
xmlns:p=\"urn:ns\">34</p:age><p:weight
xmlns:p=\"urn:ns\">50</p:weight></person>"));
addTest(new
org.apache.axiom.ts.om.element.TestSerialization(metaFactory, "U", "D",
"<person><name xmlns=\"urn:ns\">John</name><age
xmlns=\"urn:ns\">34</age><weight xmlns=\"urn:ns\">50</weight></person>"));
+ addTest(new
org.apache.axiom.ts.om.element.TestSerializationWithTwoNonBuiltOMElements(metaFactory));
addTest(new
org.apache.axiom.ts.om.element.TestSetTextQName(metaFactory));
addTest(new org.apache.axiom.ts.om.node.TestDetach(metaFactory, true));
addTest(new org.apache.axiom.ts.om.node.TestDetach(metaFactory,
false));
Added:
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=1053681&view=auto
==============================================================================
---
webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/builder/TestGetDocumentElementWithDiscardDocument.java
(added)
+++
webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/builder/TestGetDocumentElementWithDiscardDocument.java
Wed Dec 29 17:44:11 2010
@@ -0,0 +1,52 @@
+/*
+ * 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.OMFactory;
+import org.apache.axiom.om.OMMetaFactory;
+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>.
+ */
+public class TestGetDocumentElementWithDiscardDocument extends AxiomTestCase {
+ public TestGetDocumentElementWithDiscardDocument(OMMetaFactory
metaFactory) {
+ super(metaFactory);
+ }
+
+ protected void runTest() throws Throwable {
+ OMFactory factory = metaFactory.getOMFactory();
+ OMXMLParserWrapper builder = metaFactory.createOMBuilder(factory,
+ new StringReader("<!--comment1--><root/><!--comment2-->"));
+ OMElement element = builder.getDocumentElement(true);
+ assertEquals("root", element.getLocalName());
+ assertFalse(element.isComplete());
+ assertNull(element.getParent());
+ // Note: we can't test getNextOMSibling here because this would build
the element
+ assertNull(element.getPreviousOMSibling());
+ OMElement newParent = factory.createOMElement("newParent", null);
+ newParent.addChild(element);
+ assertFalse(element.isComplete());
+ }
+}
Propchange:
webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/builder/TestGetDocumentElementWithDiscardDocument.java
------------------------------------------------------------------------------
svn:eol-style = native
Added:
webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/TestSerializationWithTwoNonBuiltOMElements.java
URL:
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/TestSerializationWithTwoNonBuiltOMElements.java?rev=1053681&view=auto
==============================================================================
---
webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/TestSerializationWithTwoNonBuiltOMElements.java
(added)
+++
webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/TestSerializationWithTwoNonBuiltOMElements.java
Wed Dec 29 17:44:11 2010
@@ -0,0 +1,54 @@
+/*
+ * 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.element;
+
+import java.io.StringReader;
+
+import org.apache.axiom.om.OMElement;
+import org.apache.axiom.om.OMFactory;
+import org.apache.axiom.om.OMMetaFactory;
+import org.apache.axiom.om.impl.OMNodeEx;
+import org.apache.axiom.ts.AxiomTestCase;
+
+public class TestSerializationWithTwoNonBuiltOMElements extends AxiomTestCase {
+ public TestSerializationWithTwoNonBuiltOMElements(OMMetaFactory
metaFactory) {
+ super(metaFactory);
+ }
+
+ protected void runTest() throws Throwable {
+ String sampleXMLOne = "<ChildOne><Name>ChildName</Name></ChildOne>";
+ String sampleXMLTwo = "<ChildTwo><Name>ChildName</Name></ChildTwo>";
+
+ String expectedXML =
+
"<Root><ChildOne><Name>ChildName</Name></ChildOne><ChildTwo><Name>ChildName</Name></ChildTwo></Root>";
+ OMFactory omFactory = metaFactory.getOMFactory();
+
+ OMElement rootElement = omFactory.createOMElement("Root", null);
+ OMElement childOne = metaFactory.createOMBuilder(omFactory, new
StringReader(sampleXMLOne)).getDocumentElement(true);
+ rootElement.addChild(childOne);
+ OMElement childTwo = metaFactory.createOMBuilder(omFactory, new
StringReader(sampleXMLTwo)).getDocumentElement(true);
+ ((OMNodeEx) childTwo).setParent(null);
+ rootElement.addChild(childTwo);
+
+ assertTrue(expectedXML.equals(rootElement.toString()));
+
+ childOne.close(false);
+ childTwo.close(false);
+ }
+}
Propchange:
webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/TestSerializationWithTwoNonBuiltOMElements.java
------------------------------------------------------------------------------
svn:eol-style = native