Author: veithen
Date: Wed May 19 21:42:35 2010
New Revision: 946418
URL: http://svn.apache.org/viewvc?rev=946418&view=rev
Log:
Changed XOPEncodingStreamWrapper to implement MimePartProvider and added a new
test case.
Added:
webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/util/stax/xop/
webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/util/stax/xop/XOPRoundtripTest.java
(with props)
Modified:
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/builder/OMAttachmentAccessorMimePartProvider.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/XOPEncodingStreamWrapper.java
Modified:
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/builder/OMAttachmentAccessorMimePartProvider.java
URL:
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/builder/OMAttachmentAccessorMimePartProvider.java?rev=946418&r1=946417&r2=946418&view=diff
==============================================================================
---
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/builder/OMAttachmentAccessorMimePartProvider.java
(original)
+++
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/builder/OMAttachmentAccessorMimePartProvider.java
Wed May 19 21:42:35 2010
@@ -41,7 +41,7 @@ public class OMAttachmentAccessorMimePar
return false;
}
- public DataHandler getMimePart(String contentID) throws IOException {
+ public DataHandler getDataHandler(String contentID) throws IOException {
DataHandler dh = attachments.getDataHandler(contentID);
if (dh == null) {
throw new IOException("No attachment found for content ID '" +
contentID + "'");
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=946418&r1=946417&r2=946418&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
Wed May 19 21:42:35 2010
@@ -30,7 +30,7 @@ import javax.activation.DataHandler;
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
+ * return value of <code>true</code> means that a call to {...@link
#getDataHandler(String)} (for
* the same content ID) will not block or will retrieve the {...@link
DataHandler} without
* overhead.
*
@@ -42,11 +42,11 @@ public interface MimePartProvider {
/**
* Get the {...@link DataHandler} for the MIME part identified by a given
content ID.
*
- * @param contentID the content ID
+ * @param contentID a content ID referenced in an <tt>xop:Include</tt>
element
* @return the {...@link DataHandler} for the MIME part identified by the
content ID; may not
* be <code>null</code>
* @throws IOException if the MIME part was not found or if an error
occurred while
* loading the part
*/
- DataHandler getMimePart(String contentID) throws IOException;
+ DataHandler getDataHandler(String contentID) throws IOException;
}
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=946418&r1=946417&r2=946418&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
Wed May 19 21:42:35 2010
@@ -78,7 +78,7 @@ public class XOPDecodingStreamReader ext
}
public DataHandler getDataHandler() throws IOException {
- return mimePartProvider.getMimePart(contentID);
+ return mimePartProvider.getDataHandler(contentID);
}
}
@@ -227,7 +227,7 @@ public class XOPDecodingStreamReader ext
&& super.getNamespaceURI().equals(XOPConstants.NAMESPACE_URI))
{
String contentID = processXopInclude();
try {
- return toBase64(mimePartProvider.getMimePart(contentID));
+ return toBase64(mimePartProvider.getDataHandler(contentID));
} catch (IOException ex) {
throw new XMLStreamException("Failed to load MIME part '" +
contentID + "'", ex);
}
Modified:
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/util/stax/xop/XOPEncodingStreamWrapper.java
URL:
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/util/stax/xop/XOPEncodingStreamWrapper.java?rev=946418&r1=946417&r2=946418&view=diff
==============================================================================
---
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/util/stax/xop/XOPEncodingStreamWrapper.java
(original)
+++
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/util/stax/xop/XOPEncodingStreamWrapper.java
Wed May 19 21:42:35 2010
@@ -26,14 +26,13 @@ import java.util.Map;
import java.util.Set;
import javax.activation.DataHandler;
-import javax.xml.stream.XMLStreamException;
import org.apache.axiom.ext.stax.datahandler.DataHandlerProvider;
/**
* Base class for {...@link XOPEncodingStreamReader} and {...@link
XOPEncodingStreamWriter}.
*/
-public abstract class XOPEncodingStreamWrapper {
+public abstract class XOPEncodingStreamWrapper implements MimePartProvider {
private final Map dataHandlerObjects = new LinkedHashMap();
private final ContentIDGenerator contentIDGenerator;
private final OptimizationPolicy optimizationPolicy;
@@ -82,15 +81,18 @@ public abstract class XOPEncodingStreamW
return Collections.unmodifiableSet(dataHandlerObjects.keySet());
}
- /**
- * Get the data handler for a given content ID.
- *
- * @param contentID a content ID referenced in an <tt>xop:Include</tt>
element
- * produced by this wrapper
- * @return the corresponding data handler; may not be <code>null</code>
- * @throws XMLStreamException if the content ID is unknown or an error
occurred while loading
- * the data handler
- */
+ public boolean isLoaded(String contentID) {
+ Object dataHandlerObject = dataHandlerObjects.get(contentID);
+ if (dataHandlerObject == null) {
+ // We should never get here, so the return value actually doesn't
matter
+ return false;
+ } else if (dataHandlerObject instanceof DataHandler) {
+ return true;
+ } else {
+ return ((DataHandlerProvider)dataHandlerObject).isLoaded();
+ }
+ }
+
public DataHandler getDataHandler(String contentID) throws IOException {
Object dataHandlerObject = dataHandlerObjects.get(contentID);
if (dataHandlerObject == null) {
Added:
webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/util/stax/xop/XOPRoundtripTest.java
URL:
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/util/stax/xop/XOPRoundtripTest.java?rev=946418&view=auto
==============================================================================
---
webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/util/stax/xop/XOPRoundtripTest.java
(added)
+++
webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/util/stax/xop/XOPRoundtripTest.java
Wed May 19 21:42:35 2010
@@ -0,0 +1,66 @@
+/*
+ * 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.util.stax.xop;
+
+import javax.activation.DataHandler;
+import javax.xml.namespace.QName;
+import javax.xml.stream.XMLStreamReader;
+
+import junit.framework.TestCase;
+
+import org.apache.axiom.om.OMAbstractFactory;
+import org.apache.axiom.om.OMElement;
+import org.apache.axiom.om.OMFactory;
+import org.apache.axiom.om.OMText;
+import org.apache.axiom.om.impl.builder.StAXOMBuilder;
+import org.apache.axiom.om.util.UUIDGenerator;
+import org.apache.axiom.util.activation.TestDataSource;
+
+public class XOPRoundtripTest extends TestCase {
+ // TODO: copy & paste from OMStAXWrapper; needs to be clarified
+ private static final ContentIDGenerator contentIDGenerator = new
ContentIDGenerator() {
+ public String generateContentID(String existingContentID) {
+ if (existingContentID == null) {
+ // TODO: This is what we do in OMTextImpl#getContentID(); note
that this doesn't
+ // generate a content ID that strictly conforms to the
specs
+ return UUIDGenerator.getUUID() + "@apache.org";
+ } else {
+ return existingContentID;
+ }
+ }
+ };
+
+ public void test() {
+ OMFactory factory = OMAbstractFactory.getOMFactory();
+ DataHandler dh = new DataHandler(new TestDataSource('x',
Runtime.getRuntime().maxMemory()));
+ OMElement element1 = factory.createOMElement(new QName("test"));
+ element1.addChild(factory.createOMText(dh, true));
+ XMLStreamReader originalReader = element1.getXMLStreamReader();
+ XOPEncodingStreamReader encodedReader = new
XOPEncodingStreamReader(originalReader,
+ contentIDGenerator, OptimizationPolicy.DEFAULT);
+ XMLStreamReader decodedReader = new
XOPDecodingStreamReader(encodedReader, encodedReader);
+ OMElement element2 = new
StAXOMBuilder(decodedReader).getDocumentElement();
+ OMText child = (OMText)element2.getFirstOMChild();
+ assertNotNull(child);
+ assertTrue(child.isBinary());
+ assertTrue(child.isOptimized());
+ assertSame(dh, child.getDataHandler());
+ }
+}
Propchange:
webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/util/stax/xop/XOPRoundtripTest.java
------------------------------------------------------------------------------
svn:eol-style = native