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/05/09 22:14:20 UTC
svn commit: r1336376 - in /webservices/commons/trunk/modules/axiom: ./
modules/axiom-api/src/main/java/org/apache/axiom/om/ds/
modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/
modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/...
Author: veithen
Date: Wed May 9 20:14:19 2012
New Revision: 1336376
URL: http://svn.apache.org/viewvc?rev=1336376&view=rev
Log:
* AXIOM-420: Added support for push-only OMDataSources.
* The change also provides a regression test for AXIOM-421 because AbstractXMLStreamWriter is involved in both cases.
* AXIOM-419: Added an AbstractPushOMDataSource as counterpart for AbstractPullOMDataSource.
Added:
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/ds/AbstractOMDataSource.java
- copied unchanged from r1336372, webservices/axiom/branches/AXIOM-420/modules/axiom-api/src/main/java/org/apache/axiom/om/ds/AbstractOMDataSource.java
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/ds/AbstractPushOMDataSource.java
- copied unchanged from r1336372, webservices/axiom/branches/AXIOM-420/modules/axiom-api/src/main/java/org/apache/axiom/om/ds/AbstractPushOMDataSource.java
webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/PushOMBuilder.java
- copied unchanged from r1336372, webservices/axiom/branches/AXIOM-420/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/PushOMBuilder.java
webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/sourcedelement/PushOMDataSource.java
- copied unchanged from r1336372, webservices/axiom/branches/AXIOM-420/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/sourcedelement/PushOMDataSource.java
webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/sourcedelement/TestGetXMLStreamReaderWithPushOMDataSource.java
- copied unchanged from r1336372, webservices/axiom/branches/AXIOM-420/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/sourcedelement/TestGetXMLStreamReaderWithPushOMDataSource.java
webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/sourcedelement/push/
- copied from r1336372, webservices/axiom/branches/AXIOM-420/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/sourcedelement/push/
webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/sourcedelement/push/TestGetNamespaceContext.java
- copied unchanged from r1336372, webservices/axiom/branches/AXIOM-420/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/sourcedelement/push/TestGetNamespaceContext.java
webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/sourcedelement/push/TestWriteAttributeNoNamespace.java
- copied unchanged from r1336372, webservices/axiom/branches/AXIOM-420/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/sourcedelement/push/TestWriteAttributeNoNamespace.java
webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/sourcedelement/push/TestWriteDataHandler.java
- copied unchanged from r1336372, webservices/axiom/branches/AXIOM-420/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/sourcedelement/push/TestWriteDataHandler.java
webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/sourcedelement/push/TestWriteDataHandlerProvider.java
- copied unchanged from r1336372, webservices/axiom/branches/AXIOM-420/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/sourcedelement/push/TestWriteDataHandlerProvider.java
webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/sourcedelement/push/TestWriteEmptyElementAutoPrefix.java
- copied unchanged from r1336372, webservices/axiom/branches/AXIOM-420/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/sourcedelement/push/TestWriteEmptyElementAutoPrefix.java
webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/sourcedelement/push/TestWriteNamespace.java
- copied unchanged from r1336372, webservices/axiom/branches/AXIOM-420/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/sourcedelement/push/TestWriteNamespace.java
webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/sourcedelement/push/TestWriteStartElementAutoPrefix.java
- copied unchanged from r1336372, webservices/axiom/branches/AXIOM-420/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/sourcedelement/push/TestWriteStartElementAutoPrefix.java
Modified:
webservices/commons/trunk/modules/axiom/ (props changed)
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/ds/AbstractPullOMDataSource.java
webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMElementImpl.java
webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMSourcedElementImpl.java
webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/OMTestSuiteBuilder.java
Propchange: webservices/commons/trunk/modules/axiom/
------------------------------------------------------------------------------
Merged /webservices/axiom/branches/AXIOM-420:r1334121-1336372
Modified: webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/ds/AbstractPullOMDataSource.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/ds/AbstractPullOMDataSource.java?rev=1336376&r1=1336375&r2=1336376&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/ds/AbstractPullOMDataSource.java (original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/ds/AbstractPullOMDataSource.java Wed May 9 20:14:19 2012
@@ -18,101 +18,27 @@
*/
package org.apache.axiom.om.ds;
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.InputStream;
-import java.io.OutputStream;
-import java.io.UnsupportedEncodingException;
-import java.io.Writer;
-import java.util.HashMap;
-
import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamReader;
import javax.xml.stream.XMLStreamWriter;
import org.apache.axiom.om.OMDataSourceExt;
-import org.apache.axiom.om.OMException;
-import org.apache.axiom.om.OMOutputFormat;
-import org.apache.axiom.om.impl.MTOMXMLStreamWriter;
import org.apache.axiom.om.impl.serialize.StreamingOMSerializer;
-import org.apache.axiom.om.util.StAXUtils;
/**
* Base class for {@link OMDataSourceExt} implementations that can easily produce the content as an
* {@link XMLStreamReader} and that don't implement any kind of optimization for serializing the
* content.
*/
-public abstract class AbstractPullOMDataSource implements OMDataSourceExt {
- private HashMap properties = null;
-
- public final Object getProperty(String key) {
- return properties == null ? null : properties.get(key);
- }
-
- public final boolean hasProperty(String key) {
- return properties != null && properties.containsKey(key);
- }
-
- public final Object setProperty(String key, Object value) {
- if (properties == null) {
- properties = new HashMap();
- }
- return properties.put(key, value);
- }
-
+public abstract class AbstractPullOMDataSource extends AbstractOMDataSource {
public final boolean isDestructiveWrite() {
// Since we serialize by copying the events from the XMLStreamReader returned by getReader(),
// obviously write is destructive if and only if read is destructiveñ
return isDestructiveRead();
}
- public final void serialize(OutputStream out, OMOutputFormat format) throws XMLStreamException {
- XMLStreamWriter writer = new MTOMXMLStreamWriter(out, format);
- serialize(writer);
- writer.flush();
- }
-
- public final void serialize(Writer writer, OMOutputFormat format) throws XMLStreamException {
- MTOMXMLStreamWriter xmlWriter =
- new MTOMXMLStreamWriter(StAXUtils.createXMLStreamWriter(writer));
- xmlWriter.setOutputFormat(format);
- serialize(xmlWriter);
- xmlWriter.flush();
- }
-
public final void serialize(XMLStreamWriter xmlWriter) throws XMLStreamException {
StreamingOMSerializer serializer = new StreamingOMSerializer();
serializer.serialize(getReader(), xmlWriter);
}
-
- public final byte[] getXMLBytes(String encoding) throws UnsupportedEncodingException {
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
- OMOutputFormat format = new OMOutputFormat();
- format.setCharSetEncoding(encoding);
- try {
- serialize(baos, format);
- } catch (XMLStreamException ex) {
- throw new OMException(ex);
- }
- return baos.toByteArray();
- }
-
- public final InputStream getXMLInputStream(String encoding) throws UnsupportedEncodingException {
- return new ByteArrayInputStream(getXMLBytes(encoding));
- }
-
- //
- // Default implementations that may be overridden by subclasses
- //
-
- public Object getObject() {
- return null;
- }
-
- public void close() {
- }
-
- public OMDataSourceExt copy() {
- throw new UnsupportedOperationException();
- }
}
Modified: webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMElementImpl.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMElementImpl.java?rev=1336376&r1=1336375&r2=1336376&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMElementImpl.java (original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMElementImpl.java Wed May 9 20:14:19 2012
@@ -433,12 +433,16 @@ public class OMElementImpl extends OMNod
}
public OMNamespace addNamespaceDeclaration(String uri, String prefix) {
+ OMNamespace ns = new OMNamespaceImpl(uri, prefix);
+ addNamespaceDeclaration(ns);
+ return ns;
+ }
+
+ void addNamespaceDeclaration(OMNamespace ns) {
if (namespaces == null) {
this.namespaces = new HashMap(5);
}
- OMNamespace ns = new OMNamespaceImpl(uri, prefix);
- namespaces.put(prefix, ns);
- return ns;
+ namespaces.put(ns.getPrefix(), ns);
}
/** @return Returns namespace. */
@@ -649,9 +653,6 @@ public class OMElementImpl extends OMNod
attr.getLocalName(), attr.getNamespace(), attr.getAttributeValue(), attr.getOMFactory());
}
- if (attributes == null) {
- this.attributes = new LinkedHashMap(5);
- }
OMNamespace namespace = attr.getNamespace();
if (namespace != null) {
String uri = namespace.getNamespaceURI();
@@ -664,6 +665,14 @@ public class OMElementImpl extends OMNod
}
}
+ appendAttribute(attr);
+ return attr;
+ }
+
+ void appendAttribute(OMAttribute attr) {
+ if (attributes == null) {
+ this.attributes = new LinkedHashMap(5);
+ }
// Set the owner element of the attribute
((OMAttributeImpl)attr).owner = this;
OMAttributeImpl oldAttr = (OMAttributeImpl)attributes.put(attr.getQName(), attr);
@@ -671,7 +680,6 @@ public class OMElementImpl extends OMNod
if (oldAttr != null) {
oldAttr.owner = null;
}
- return attr;
}
public void removeAttribute(OMAttribute attr) {
Modified: webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMSourcedElementImpl.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMSourcedElementImpl.java?rev=1336376&r1=1336375&r2=1336376&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMSourcedElementImpl.java (original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMSourcedElementImpl.java Wed May 9 20:14:19 2012
@@ -33,6 +33,7 @@ import org.apache.axiom.om.OMSourcedElem
import org.apache.axiom.om.OMXMLParserWrapper;
import org.apache.axiom.om.OMXMLStreamReaderConfiguration;
import org.apache.axiom.om.QNameAwareOMDataSource;
+import org.apache.axiom.om.ds.AbstractPushOMDataSource;
import org.apache.axiom.om.impl.builder.StAXOMBuilder;
import org.apache.axiom.om.impl.common.OMNamespaceImpl;
import org.apache.axiom.om.util.StAXUtils;
@@ -252,39 +253,53 @@ public class OMSourcedElementImpl extend
}
}
- // Get the XMLStreamReader
- try {
- readerFromDS = dataSource.getReader();
- } catch (XMLStreamException ex) {
- throw new OMException("Error obtaining parser from data source for element " + getPrintableName(), ex);
- }
-
- // Advance past the START_DOCUMENT to the start tag.
- // Remember the character encoding.
- String characterEncoding = readerFromDS.getCharacterEncodingScheme();
- if (characterEncoding != null) {
- characterEncoding = readerFromDS.getEncoding();
- }
- try {
- if (readerFromDS.getEventType() != XMLStreamConstants.START_ELEMENT) {
- while (readerFromDS.next() != XMLStreamConstants.START_ELEMENT) ;
+ if (isPushDataSource()) {
+ // Set this before we start expanding; otherwise this would result in an infinite recursion
+ isExpanded = true;
+ try {
+ dataSource.serialize(new PushOMBuilder(this));
+ } catch (XMLStreamException ex) {
+ throw new OMException("Failed to expand data source", ex);
+ }
+ } else {
+ // Get the XMLStreamReader
+ try {
+ readerFromDS = dataSource.getReader();
+ } catch (XMLStreamException ex) {
+ throw new OMException("Error obtaining parser from data source for element " + getPrintableName(), ex);
+ }
+
+ // Advance past the START_DOCUMENT to the start tag.
+ // Remember the character encoding.
+ String characterEncoding = readerFromDS.getCharacterEncodingScheme();
+ if (characterEncoding != null) {
+ characterEncoding = readerFromDS.getEncoding();
+ }
+ try {
+ if (readerFromDS.getEventType() != XMLStreamConstants.START_ELEMENT) {
+ while (readerFromDS.next() != XMLStreamConstants.START_ELEMENT) ;
+ }
+ } catch (XMLStreamException ex) {
+ throw new OMException("Error parsing data source document for element " + getLocalName(), ex);
}
- } catch (XMLStreamException ex) {
- throw new OMException("Error parsing data source document for element " + getLocalName(), ex);
+
+ validateName(readerFromDS.getPrefix(), readerFromDS.getLocalName(), readerFromDS.getNamespaceURI());
+
+ // Set the builder for this element. Note that the StAXOMBuilder constructor will also
+ // update the namespace of the element, so we don't need to do that here.
+ isExpanded = true;
+ super.setBuilder(new StAXOMBuilder(getOMFactory(),
+ readerFromDS,
+ this,
+ characterEncoding));
+ setComplete(false);
}
-
- validateName(readerFromDS.getPrefix(), readerFromDS.getLocalName(), readerFromDS.getNamespaceURI());
-
- // Set the builder for this element. Note that the StAXOMBuilder constructor will also
- // update the namespace of the element, so we don't need to do that here.
- isExpanded = true;
- super.setBuilder(new StAXOMBuilder(getOMFactory(),
- readerFromDS,
- this,
- characterEncoding));
- setComplete(false);
}
}
+
+ private boolean isPushDataSource() {
+ return dataSource instanceof AbstractPushOMDataSource;
+ }
/**
* Validates that the actual name of the element obtained from StAX matches the information
@@ -368,6 +383,10 @@ public class OMSourcedElementImpl extend
return super.addNamespaceDeclaration(uri, prefix);
}
+ void addNamespaceDeclaration(OMNamespace ns) {
+ super.addNamespaceDeclaration(ns);
+ }
+
public void undeclarePrefix(String prefix) {
forceExpand();
super.undeclarePrefix(prefix);
@@ -423,6 +442,10 @@ public class OMSourcedElementImpl extend
return super.addAttribute(attributeName, value, namespace);
}
+ void appendAttribute(OMAttribute attr) {
+ super.appendAttribute(attr);
+ }
+
public void removeAttribute(OMAttribute attr) {
forceExpand();
super.removeAttribute(attr);
@@ -465,7 +488,7 @@ public class OMSourcedElementImpl extend
if (isExpanded) {
return super.getXMLStreamReader(cache, configuration);
} else {
- if (cache && isDestructiveRead()) {
+ if ((cache && isDestructiveRead()) || isPushDataSource()) {
forceExpand();
return super.getXMLStreamReader(true, configuration);
} else {
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=1336376&r1=1336375&r2=1336376&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 May 9 20:14:19 2012
@@ -348,6 +348,8 @@ public class OMTestSuiteBuilder extends
addTest(new org.apache.axiom.ts.om.sourcedelement.TestGetNamespaceNormalized2(metaFactory));
addTest(new org.apache.axiom.ts.om.sourcedelement.TestGetObject(metaFactory));
addTest(new org.apache.axiom.ts.om.sourcedelement.TestGetTextAsStreamWithNonDestructiveOMDataSource(metaFactory));
+ addTest(new org.apache.axiom.ts.om.sourcedelement.TestGetXMLStreamReaderWithPushOMDataSource(metaFactory, true));
+ addTest(new org.apache.axiom.ts.om.sourcedelement.TestGetXMLStreamReaderWithPushOMDataSource(metaFactory, false));
addTest(new org.apache.axiom.ts.om.sourcedelement.TestInputStreamDS(metaFactory));
addTest(new org.apache.axiom.ts.om.sourcedelement.TestName1DefaultPrefix(metaFactory));
addTest(new org.apache.axiom.ts.om.sourcedelement.TestName1QualifiedPrefix(metaFactory));
@@ -378,6 +380,15 @@ public class OMTestSuiteBuilder extends
addTest(new org.apache.axiom.ts.om.sourcedelement.TestSetLocalName(metaFactory, true));
addTest(new org.apache.axiom.ts.om.sourcedelement.TestWrappedTextNodeOMDataSourceFromReader(metaFactory));
addTest(new org.apache.axiom.ts.om.sourcedelement.TestWriteTextToWithNonDestructiveOMDataSource(metaFactory));
+ addTest(new org.apache.axiom.ts.om.sourcedelement.push.TestGetNamespaceContext(metaFactory));
+ addTest(new org.apache.axiom.ts.om.sourcedelement.push.TestWriteAttributeNoNamespace(metaFactory));
+ addTest(new org.apache.axiom.ts.om.sourcedelement.push.TestWriteDataHandler(metaFactory));
+ addTest(new org.apache.axiom.ts.om.sourcedelement.push.TestWriteDataHandlerProvider(metaFactory));
+ addTest(new org.apache.axiom.ts.om.sourcedelement.push.TestWriteEmptyElementAutoPrefix(metaFactory));
+ addTest(new org.apache.axiom.ts.om.sourcedelement.push.TestWriteNamespace(metaFactory, "", ""));
+ addTest(new org.apache.axiom.ts.om.sourcedelement.push.TestWriteNamespace(metaFactory, "", "urn:test"));
+ addTest(new org.apache.axiom.ts.om.sourcedelement.push.TestWriteNamespace(metaFactory, "p", "urn:test"));
+ addTest(new org.apache.axiom.ts.om.sourcedelement.push.TestWriteStartElementAutoPrefix(metaFactory));
}
addTest(new org.apache.axiom.ts.om.pi.TestDigest(metaFactory));
addTest(new org.apache.axiom.ts.om.text.TestBase64Streaming(metaFactory));