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 ve...@apache.org on 2009/07/14 23:47:26 UTC
svn commit: r794080 - in
/webservices/commons/trunk/modules/axiom/modules/axiom-api/src:
main/java/org/apache/axiom/ext/stax/datahandler/
main/java/org/apache/axiom/om/impl/
main/java/org/apache/axiom/om/impl/builder/
main/java/org/apache/axiom/util/st...
Author: veithen
Date: Tue Jul 14 21:47:26 2009
New Revision: 794080
URL: http://svn.apache.org/viewvc?rev=794080&view=rev
Log:
Some improvements to the data handler extension API.
Modified:
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/ext/stax/datahandler/DataHandlerProvider.java
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/ext/stax/datahandler/DataHandlerReader.java
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/OMStAXWrapper.java
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/SwitchingWrapper.java
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/builder/DataHandlerReaderUtil.java
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/util/stax/xop/MimePartProvider.java
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/util/stax/xop/XOPDecodingStreamReader.java
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/util/stax/xop/XOPEncodingStreamReader.java
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/om/OMTextTestBase.java
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/util/stax/xop/OMAttachmentAccessorMimePartProvider.java
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/util/stax/xop/XOPEncodingStreamReaderTest.java
Modified: webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/ext/stax/datahandler/DataHandlerProvider.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/ext/stax/datahandler/DataHandlerProvider.java?rev=794080&r1=794079&r2=794080&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/ext/stax/datahandler/DataHandlerProvider.java (original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/ext/stax/datahandler/DataHandlerProvider.java Tue Jul 14 21:47:26 2009
@@ -30,6 +30,20 @@
*/
public interface DataHandlerProvider {
/**
+ * Check whether the {@link DataHandler} has already been loaded. A return value of
+ * <code>true</code> means that a call to {@link #getDataHandler()} will not block or will
+ * retrieve the {@link DataHandler} without overhead. Note the return value of this method for a
+ * given instance of this class may change over time due to events other than a call to
+ * {@link #getDataHandler()} on the same instance. E.g. a call to {@link #getDataHandler()} on
+ * one instance may change the return value of the method on another instance (because the
+ * {@link DataHandler} objects can only be loaded in a certain sequence).
+ *
+ * @return <code>true</code> if the {@link DataHandler} has already been loaded;
+ * <code>false</code> otherwise
+ */
+ boolean isLoaded();
+
+ /**
* Get the {@link DataHandler} object for the binary content.
*
* @return the binary content
Modified: webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/ext/stax/datahandler/DataHandlerReader.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/ext/stax/datahandler/DataHandlerReader.java?rev=794080&r1=794079&r2=794080&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/ext/stax/datahandler/DataHandlerReader.java (original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/ext/stax/datahandler/DataHandlerReader.java Tue Jul 14 21:47:26 2009
@@ -77,6 +77,17 @@
* available; <code>false</code> for all other types of events.
*/
boolean isBinary();
+
+ /**
+ * Check if the binary content is eligible for optimization (e.g. using XOP) or if it should
+ * be serialized as base64.
+ * Calling this method is only meaningful if {@link #isBinary()} returns <code>true</code> for
+ * the current event. The behavior of this method is undefined if this is not the case.
+ *
+ * @return <code>true</code> if the binary content is eligible for optimization;
+ * <code>false</code> otherwise
+ */
+ boolean isOptimized();
/**
* Check whether the {@link javax.xml.stream.XMLStreamReader} supports deferred loading of the
Modified: webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/OMStAXWrapper.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/OMStAXWrapper.java?rev=794080&r1=794079&r2=794080&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/OMStAXWrapper.java (original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/OMStAXWrapper.java Tue Jul 14 21:47:26 2009
@@ -97,7 +97,10 @@
}
} else {
if (xopEncoder == null) {
- xopEncoder = new XOPEncodingStreamReader(switchingWrapper, contentIDGenerator);
+ // Since the intention is to support an efficient way to pass binary content to a
+ // consumer that is not aware of our data handler extension (see WSCOMMONS-344), we
+ // use optimizeAll=true, i.e. we ignore OMText#isOptimized().
+ xopEncoder = new XOPEncodingStreamReader(switchingWrapper, contentIDGenerator, true);
setParent(xopEncoder);
}
}
Modified: webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/SwitchingWrapper.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/SwitchingWrapper.java?rev=794080&r1=794079&r2=794080&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/SwitchingWrapper.java (original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/SwitchingWrapper.java Tue Jul 14 21:47:26 2009
@@ -1204,6 +1204,22 @@
}
}
+ public boolean isOptimized() {
+ if (parser != null) {
+ if (dataHandlerReader != null) {
+ return dataHandlerReader.isOptimized();
+ } else {
+ throw new IllegalStateException();
+ }
+ } else {
+ if (lastNode instanceof OMText) {
+ return ((OMText)lastNode).isOptimized();
+ } else {
+ throw new IllegalStateException();
+ }
+ }
+ }
+
public boolean isDeferred() {
if (parser != null) {
if (dataHandlerReader != null) {
Modified: webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/builder/DataHandlerReaderUtil.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/builder/DataHandlerReaderUtil.java?rev=794080&r1=794079&r2=794080&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/builder/DataHandlerReaderUtil.java (original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/builder/DataHandlerReaderUtil.java Tue Jul 14 21:47:26 2009
@@ -122,6 +122,11 @@
return ((Boolean)reader.getProperty(OMConstants.IS_BINARY)).booleanValue();
}
+ public boolean isOptimized() {
+ // This is compatible with the old StAXBuilder implementation
+ return true;
+ }
+
public boolean isDeferred() {
return false;
}
Modified: webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/util/stax/xop/MimePartProvider.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/util/stax/xop/MimePartProvider.java?rev=794080&r1=794079&r2=794080&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/util/stax/xop/MimePartProvider.java (original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/util/stax/xop/MimePartProvider.java Tue Jul 14 21:47:26 2009
@@ -28,6 +28,17 @@
*/
public interface MimePartProvider {
/**
+ * Check whether the MIME part identified by a given content ID has already been loaded. A
+ * return value of <code>true</code> means that a call to {@link #getMimePart(String)} (for
+ * the same content ID) will not block or will retrieve the {@link DataHandler} without
+ * overhead.
+ *
+ * @return <code>true</code> if the MIME part has already been loaded; <code>false</code>
+ * otherwise
+ */
+ boolean isLoaded(String contentID);
+
+ /**
* Get the {@link DataHandler} for the MIME part identified by a given content ID.
*
* @param contentID the content ID
Modified: webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/util/stax/xop/XOPDecodingStreamReader.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/util/stax/xop/XOPDecodingStreamReader.java?rev=794080&r1=794079&r2=794080&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/util/stax/xop/XOPDecodingStreamReader.java (original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/util/stax/xop/XOPDecodingStreamReader.java Tue Jul 14 21:47:26 2009
@@ -73,6 +73,10 @@
return contentID;
}
+ public boolean isLoaded() {
+ return mimePartProvider.isLoaded(contentID);
+ }
+
public DataHandler getDataHandler() throws XMLStreamException {
return mimePartProvider.getMimePart(contentID);
}
@@ -513,6 +517,11 @@
return dh != null;
}
+ public boolean isOptimized() {
+ // xop:Include implies optimized
+ return true;
+ }
+
public boolean isDeferred() {
return true;
}
Modified: webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/util/stax/xop/XOPEncodingStreamReader.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/util/stax/xop/XOPEncodingStreamReader.java?rev=794080&r1=794079&r2=794080&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/util/stax/xop/XOPEncodingStreamReader.java (original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/util/stax/xop/XOPEncodingStreamReader.java Tue Jul 14 21:47:26 2009
@@ -109,6 +109,7 @@
private final XMLStreamReader parent;
private final ContentIDGenerator contentIDGenerator;
private final DataHandlerReader dataHandlerReader;
+ private final boolean optimizeAll;
private int state = STATE_PASS_THROUGH;
private String currentContentID;
private Map dataHandlerObjects = new LinkedHashMap();
@@ -122,12 +123,17 @@
* @param contentIDGenerator
* used to generate content IDs for the binary content exposed as
* <tt>xop:Include</tt> element information items
+ * @param optimizeAll
+ * if set to <code>true</code>, <tt>xop:Include</tt> element information items
+ * will be generated for all data handlers, regardless of the return value of
+ * {@link DataHandlerReader#isOptimized()}
*
* @throws IllegalArgumentException
* if the provided {@link XMLStreamReader} doesn't implement the extension defined
* by {@link DataHandlerReader}
*/
- public XOPEncodingStreamReader(XMLStreamReader parent, ContentIDGenerator contentIDGenerator) {
+ public XOPEncodingStreamReader(XMLStreamReader parent, ContentIDGenerator contentIDGenerator,
+ boolean optimizeAll) {
this.parent = parent;
this.contentIDGenerator = contentIDGenerator;
DataHandlerReader dataHandlerReader;
@@ -140,6 +146,7 @@
throw new IllegalArgumentException("The supplied XMLStreamReader doesn't implement the DataHandlerReader extension");
}
this.dataHandlerReader = dataHandlerReader;
+ this.optimizeAll = optimizeAll;
}
/**
@@ -186,7 +193,8 @@
// Fall through
default:
int event = parent.next();
- if (event == CHARACTERS && dataHandlerReader.isBinary()) {
+ if (event == CHARACTERS && dataHandlerReader.isBinary()
+ && (optimizeAll || dataHandlerReader.isOptimized())) {
String contentID = dataHandlerReader.getContentID();
contentID = contentIDGenerator.generateContentID(contentID);
Object dataHandlerObject = dataHandlerReader.isDeferred()
Modified: webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/om/OMTextTestBase.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/om/OMTextTestBase.java?rev=794080&r1=794079&r2=794080&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/om/OMTextTestBase.java (original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/om/OMTextTestBase.java Tue Jul 14 21:47:26 2009
@@ -30,6 +30,10 @@
static class TestDataHandlerProvider implements DataHandlerProvider {
private DataHandler dh;
+ public boolean isLoaded() {
+ return false;
+ }
+
public DataHandler getDataHandler() {
if (dh == null) {
dh = new DataHandler("Data", "text/plain");
Modified: webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/util/stax/xop/OMAttachmentAccessorMimePartProvider.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/util/stax/xop/OMAttachmentAccessorMimePartProvider.java?rev=794080&r1=794079&r2=794080&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/util/stax/xop/OMAttachmentAccessorMimePartProvider.java (original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/util/stax/xop/OMAttachmentAccessorMimePartProvider.java Tue Jul 14 21:47:26 2009
@@ -34,6 +34,11 @@
this.attachments = attachments;
}
+ public boolean isLoaded(String contentID) {
+ // TODO: probably we can only determine this for an Attachments object
+ return false;
+ }
+
public DataHandler getMimePart(String contentID) throws XMLStreamException {
DataHandler dh = attachments.getDataHandler(contentID);
if (dh == null) {
Modified: webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/util/stax/xop/XOPEncodingStreamReaderTest.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/util/stax/xop/XOPEncodingStreamReaderTest.java?rev=794080&r1=794079&r2=794080&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/util/stax/xop/XOPEncodingStreamReaderTest.java (original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/util/stax/xop/XOPEncodingStreamReaderTest.java Tue Jul 14 21:47:26 2009
@@ -48,7 +48,7 @@
TestConstants.MTOM_MESSAGE_CONTENT_TYPE);
soapPartReader[i] = StAXUtils.createXMLStreamReader(attachments[i].getSOAPPartInputStream());
}
- XMLStreamReader actual = new XOPEncodingStreamReader(new XOPDecodingStreamReader(soapPartReader[1], new OMAttachmentAccessorMimePartProvider(attachments[1])), contentIDGenerator);
+ XMLStreamReader actual = new XOPEncodingStreamReader(new XOPDecodingStreamReader(soapPartReader[1], new OMAttachmentAccessorMimePartProvider(attachments[1])), contentIDGenerator, false);
new XMLStreamReaderComparator(soapPartReader[0], actual).compare();
}