You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commons-dev@ws.apache.org by sc...@apache.org on 2007/09/05 21:53:55 UTC
svn commit: r573038 - in /webservices/commons/trunk/modules/axiom/modules:
axiom-api/src/main/java/org/apache/axiom/om/
axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/
axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/
axiom-tests/src/test/j...
Author: scheu
Date: Wed Sep 5 12:53:55 2007
New Revision: 573038
URL: http://svn.apache.org/viewvc?rev=573038&view=rev
Log:
WSCOMMONS-240
Contributor:Rich Scheuerle
Added OMNode.close method plus a validation test.
Modified:
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/OMNode.java
webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/NodeImpl.java
webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMNodeImpl.java
webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/om/impl/builder/StAXOMBuilderTest.java
Modified: webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/OMNode.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/OMNode.java?rev=573038&r1=573037&r2=573038&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/OMNode.java (original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/OMNode.java Wed Sep 5 12:53:55 2007
@@ -283,8 +283,14 @@
void buildWithAttachments();
/**
+ * If a builder and parser is associated with the node, it is closed.
+ * @param build if true, the object is built first before closing the builder/parser
+ */
+ void close(boolean build);
+
+ /**
* Returns the OMFactory that created this object
- */
- OMFactory getOMFactory();
+ */
+ OMFactory getOMFactory();
}
Modified: webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/NodeImpl.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/NodeImpl.java?rev=573038&r1=573037&r2=573038&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/NodeImpl.java (original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/NodeImpl.java Wed Sep 5 12:53:55 2007
@@ -26,6 +26,7 @@
import org.apache.axiom.om.OMXMLParserWrapper;
import org.apache.axiom.om.impl.MTOMXMLStreamWriter;
import org.apache.axiom.om.impl.OMNodeEx;
+import org.apache.axiom.om.impl.builder.StAXBuilder;
import org.apache.axiom.om.util.StAXUtils;
import org.w3c.dom.DOMException;
import org.w3c.dom.Document;
@@ -461,6 +462,20 @@
}
}
+ public void close(boolean build) {
+ if (build) {
+ this.build();
+ }
+ this.done = true;
+
+ // If this is a StAXBuilder, close it.
+ if (builder instanceof StAXBuilder &&
+ !((StAXBuilder) builder).isClosed()) {
+ ((StAXBuilder) builder).releaseParserOnClose(true);
+ ((StAXBuilder) builder).close();
+ }
+ }
+
/**
* Sets the owner document.
*
Modified: webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMNodeImpl.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMNodeImpl.java?rev=573038&r1=573037&r2=573038&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMNodeImpl.java (original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMNodeImpl.java Wed Sep 5 12:53:55 2007
@@ -33,6 +33,7 @@
import org.apache.axiom.om.impl.MTOMXMLStreamWriter;
import org.apache.axiom.om.impl.OMContainerEx;
import org.apache.axiom.om.impl.OMNodeEx;
+import org.apache.axiom.om.impl.builder.StAXBuilder;
import org.apache.axiom.om.impl.builder.StAXOMBuilder;
import org.apache.axiom.om.impl.llom.factory.OMLinkedListImplFactory;
import org.apache.axiom.om.util.StAXUtils;
@@ -330,6 +331,21 @@
public void buildWithAttachments() {
if (!this.done) {
this.build();
+ }
+ }
+
+
+ public void close(boolean build) {
+ if (build) {
+ this.build();
+ }
+ this.done = true;
+
+ // If this is a StAXBuilder, close it.
+ if (builder instanceof StAXBuilder &&
+ !((StAXBuilder) builder).isClosed()) {
+ ((StAXBuilder) builder).releaseParserOnClose(true);
+ ((StAXBuilder) builder).close();
}
}
Modified: webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/om/impl/builder/StAXOMBuilderTest.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/om/impl/builder/StAXOMBuilderTest.java?rev=573038&r1=573037&r2=573038&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/om/impl/builder/StAXOMBuilderTest.java (original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/om/impl/builder/StAXOMBuilderTest.java Wed Sep 5 12:53:55 2007
@@ -68,4 +68,54 @@
}
assertTrue(childrenCount == 5);
}
+
+ public void testClose1() throws Exception {
+ rootElement = stAXOMBuilder.getDocumentElement();
+ assertTrue("Root element can not be null", rootElement != null);
+ assertTrue(" Name of the root element is wrong",
+ rootElement.getLocalName().equalsIgnoreCase("Root"));
+ // get the first OMElement child
+ OMNode omnode = rootElement.getFirstOMChild();
+ while (omnode instanceof OMText) {
+ omnode = omnode.getNextOMSibling();
+ }
+ // Close the element immediately
+ OMElement omElement = (OMElement) omnode;
+ omElement.close(false);
+
+ Iterator children = ((OMElement) omnode).getChildren();
+ int childrenCount = 0;
+ while (children.hasNext()) {
+ OMNode node = (OMNode) children.next();
+ if (node instanceof OMElement)
+ childrenCount++;
+ }
+
+ assertTrue(childrenCount == 0);
+ }
+
+ public void testClose2() throws Exception {
+ rootElement = stAXOMBuilder.getDocumentElement();
+ assertTrue("Root element can not be null", rootElement != null);
+ assertTrue(" Name of the root element is wrong",
+ rootElement.getLocalName().equalsIgnoreCase("Root"));
+ // get the first OMElement child
+ OMNode omnode = rootElement.getFirstOMChild();
+ while (omnode instanceof OMText) {
+ omnode = omnode.getNextOMSibling();
+ }
+ // Close the element after building the element
+ OMElement omElement = (OMElement) omnode;
+ omElement.close(true);
+
+ Iterator children = ((OMElement) omnode).getChildren();
+ int childrenCount = 0;
+ while (children.hasNext()) {
+ OMNode node = (OMNode) children.next();
+ if (node instanceof OMElement)
+ childrenCount++;
+ }
+
+ assertTrue(childrenCount == 5);
+ }
}
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@ws.apache.org
For additional commands, e-mail: commons-dev-help@ws.apache.org