Author: veithen
Date: Sun Dec 12 13:13:38 2010
New Revision: 1044816
URL: http://svn.apache.org/viewvc?rev=1044816&view=rev
Log:
Promoted the StAXBuilder#close() method to the OMXMLParserWrapper interface,
added the necessary Javadoc to specify its behavior and added a couple of test
cases to validate its behavior.
Added:
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/om/OMXMLParserWrapperTestBase.java
(with props)
webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/test/java/org/apache/axiom/om/impl/dom/OMXMLParserWrapperTest.java
(with props)
webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/test/java/org/apache/axiom/om/impl/llom/OMXMLParserWrapperTest.java
(with props)
webservices/commons/trunk/modules/axiom/modules/axiom-testutils/src/main/java/org/apache/axiom/testutils/io/CloseSensorInputStream.java
(with props)
webservices/commons/trunk/modules/axiom/modules/axiom-testutils/src/main/java/org/apache/axiom/testutils/io/CloseSensorReader.java
(with props)
Modified:
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/OMXMLParserWrapper.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=1044816&r1=1044815&r2=1044816&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
Sun Dec 12 13:13:38 2010
@@ -104,4 +104,11 @@ public interface OMXMLParserWrapper {
* @return the character encoding, defaults to "UTF-8"
*/
public String getCharacterEncoding();
+
+ /**
+ * Close this builder. This method frees the resources associated with
this builder. In
+ * particular, it releases the resources held by the underlying parser.
This method does
+ * <b>not</b> close the underlying input source.
+ */
+ void close();
}
Added:
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/om/OMXMLParserWrapperTestBase.java
URL:
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/om/OMXMLParserWrapperTestBase.java?rev=1044816&view=auto
==============================================================================
---
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/om/OMXMLParserWrapperTestBase.java
(added)
+++
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/om/OMXMLParserWrapperTestBase.java
Sun Dec 12 13:13:38 2010
@@ -0,0 +1,85 @@
+/*
+ * 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;
+
+import java.io.InputStream;
+import java.io.StringReader;
+import java.lang.ref.WeakReference;
+
+import javax.xml.stream.XMLStreamReader;
+
+import org.apache.axiom.om.util.StAXUtils;
+import org.apache.axiom.testutils.io.CloseSensorInputStream;
+import org.apache.axiom.testutils.io.CloseSensorReader;
+
+public class OMXMLParserWrapperTestBase extends AbstractTestCase {
+ private final OMMetaFactory omMetaFactory;
+
+ public OMXMLParserWrapperTestBase(OMMetaFactory omMetaFactory) {
+ this.omMetaFactory = omMetaFactory;
+ }
+
+ public void testCloseWithInputStream() throws Exception {
+ CloseSensorInputStream in = new
CloseSensorInputStream(getTestResource(TestConstants.TEST));
+ try {
+ OMXMLParserWrapper builder =
omMetaFactory.createOMBuilder(omMetaFactory.getOMFactory(), in);
+ builder.getDocument().build();
+ builder.close();
+ // OMXMLParserWrapper#close() does _not_ close the underlying
input stream
+ assertFalse(in.isClosed());
+ } finally {
+ in.close();
+ }
+ }
+
+ public void testCloseWithReader() throws Exception {
+ CloseSensorReader in = new CloseSensorReader(new
StringReader("<root><child/></root>"));
+ try {
+ OMXMLParserWrapper builder =
omMetaFactory.createOMBuilder(omMetaFactory.getOMFactory(), in);
+ builder.getDocument().build();
+ builder.close();
+ // OMXMLParserWrapper#close() does _not_ close the underlying
input stream
+ assertFalse(in.isClosed());
+ } finally {
+ in.close();
+ }
+ }
+
+ public void testCloseWithXMLStreamReader() throws Exception {
+ InputStream in = getTestResource(TestConstants.TEST);
+ try {
+ XMLStreamReader reader = StAXUtils.createXMLStreamReader(in);
+ OMXMLParserWrapper builder =
omMetaFactory.createStAXOMBuilder(omMetaFactory.getOMFactory(), reader);
+ WeakReference readerWeakRef = new WeakReference(reader);
+ reader = null;
+ builder.getDocument().build();
+ builder.close();
+ for (int i=0; i<10; i++) {
+ Thread.sleep(500);
+ if (readerWeakRef.get() == null) {
+ return;
+ }
+ System.gc();
+ }
+ fail("Builder didn't release reference to the underlying parser");
+ } finally {
+ in.close();
+ }
+ }
+}
Propchange:
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/om/OMXMLParserWrapperTestBase.java
------------------------------------------------------------------------------
svn:eol-style = native
Added:
webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/test/java/org/apache/axiom/om/impl/dom/OMXMLParserWrapperTest.java
URL:
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/test/java/org/apache/axiom/om/impl/dom/OMXMLParserWrapperTest.java?rev=1044816&view=auto
==============================================================================
---
webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/test/java/org/apache/axiom/om/impl/dom/OMXMLParserWrapperTest.java
(added)
+++
webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/test/java/org/apache/axiom/om/impl/dom/OMXMLParserWrapperTest.java
Sun Dec 12 13:13:38 2010
@@ -0,0 +1,28 @@
+/*
+ * 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.dom;
+
+import org.apache.axiom.om.OMXMLParserWrapperTestBase;
+import org.apache.axiom.om.impl.dom.factory.OMDOMMetaFactory;
+
+public class OMXMLParserWrapperTest extends OMXMLParserWrapperTestBase {
+ public OMXMLParserWrapperTest() {
+ super(new OMDOMMetaFactory());
+ }
+}
Propchange:
webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/test/java/org/apache/axiom/om/impl/dom/OMXMLParserWrapperTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Added:
webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/test/java/org/apache/axiom/om/impl/llom/OMXMLParserWrapperTest.java
URL:
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/test/java/org/apache/axiom/om/impl/llom/OMXMLParserWrapperTest.java?rev=1044816&view=auto
==============================================================================
---
webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/test/java/org/apache/axiom/om/impl/llom/OMXMLParserWrapperTest.java
(added)
+++
webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/test/java/org/apache/axiom/om/impl/llom/OMXMLParserWrapperTest.java
Sun Dec 12 13:13:38 2010
@@ -0,0 +1,28 @@
+/*
+ * 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.llom;
+
+import org.apache.axiom.om.OMXMLParserWrapperTestBase;
+import org.apache.axiom.om.impl.llom.factory.OMLinkedListMetaFactory;
+
+public class OMXMLParserWrapperTest extends OMXMLParserWrapperTestBase {
+ public OMXMLParserWrapperTest() {
+ super(new OMLinkedListMetaFactory());
+ }
+}
Propchange:
webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/test/java/org/apache/axiom/om/impl/llom/OMXMLParserWrapperTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Added:
webservices/commons/trunk/modules/axiom/modules/axiom-testutils/src/main/java/org/apache/axiom/testutils/io/CloseSensorInputStream.java
URL:
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-testutils/src/main/java/org/apache/axiom/testutils/io/CloseSensorInputStream.java?rev=1044816&view=auto
==============================================================================
---
webservices/commons/trunk/modules/axiom/modules/axiom-testutils/src/main/java/org/apache/axiom/testutils/io/CloseSensorInputStream.java
(added)
+++
webservices/commons/trunk/modules/axiom/modules/axiom-testutils/src/main/java/org/apache/axiom/testutils/io/CloseSensorInputStream.java
Sun Dec 12 13:13:38 2010
@@ -0,0 +1,44 @@
+/*
+ * 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.testutils.io;
+
+import java.io.IOException;
+import java.io.InputStream;
+
+import org.apache.commons.io.input.ProxyInputStream;
+
+/**
+ * {...@link InputStream} wrapper that remembers if {...@link
InputStream#close()} has been called.
+ */
+public class CloseSensorInputStream extends ProxyInputStream {
+ private boolean closed;
+
+ public CloseSensorInputStream(InputStream parent) {
+ super(parent);
+ }
+
+ public void close() throws IOException {
+ closed = true;
+ super.close();
+ }
+
+ public boolean isClosed() {
+ return closed;
+ }
+}
Propchange:
webservices/commons/trunk/modules/axiom/modules/axiom-testutils/src/main/java/org/apache/axiom/testutils/io/CloseSensorInputStream.java
------------------------------------------------------------------------------
svn:eol-style = native
Added:
webservices/commons/trunk/modules/axiom/modules/axiom-testutils/src/main/java/org/apache/axiom/testutils/io/CloseSensorReader.java
URL:
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-testutils/src/main/java/org/apache/axiom/testutils/io/CloseSensorReader.java?rev=1044816&view=auto
==============================================================================
---
webservices/commons/trunk/modules/axiom/modules/axiom-testutils/src/main/java/org/apache/axiom/testutils/io/CloseSensorReader.java
(added)
+++
webservices/commons/trunk/modules/axiom/modules/axiom-testutils/src/main/java/org/apache/axiom/testutils/io/CloseSensorReader.java
Sun Dec 12 13:13:38 2010
@@ -0,0 +1,44 @@
+/*
+ * 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.testutils.io;
+
+import java.io.IOException;
+import java.io.Reader;
+
+import org.apache.commons.io.input.ProxyReader;
+
+/**
+ * {...@link Reader} wrapper that remembers if {...@link Reader#close()} has
been called.
+ */
+public class CloseSensorReader extends ProxyReader {
+ private boolean closed;
+
+ public CloseSensorReader(Reader parent) {
+ super(parent);
+ }
+
+ public void close() throws IOException {
+ closed = true;
+ super.close();
+ }
+
+ public boolean isClosed() {
+ return closed;
+ }
+}
Propchange:
webservices/commons/trunk/modules/axiom/modules/axiom-testutils/src/main/java/org/apache/axiom/testutils/io/CloseSensorReader.java
------------------------------------------------------------------------------
svn:eol-style = native