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 2011/12/02 23:14:21 UTC
svn commit: r1209729 -
/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/attachments/
Author: veithen
Date: Fri Dec 2 22:14:21 2011
New Revision: 1209729
URL: http://svn.apache.org/viewvc?rev=1209729&view=rev
Log:
AXIOM-377: Some code and Javadoc cleanup.
Added:
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/attachments/PartContent.java
- copied, changed from r1209288, webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/attachments/ContentStore.java
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/attachments/PartContentFactory.java
- copied, changed from r1209288, webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/attachments/ContentStoreFactory.java
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/attachments/PartContentOnFile.java
- copied, changed from r1209288, webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/attachments/ContentOnFile.java
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/attachments/PartContentOnMemory.java
- copied, changed from r1209288, webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/attachments/ContentOnMemory.java
Removed:
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/attachments/ContentOnFile.java
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/attachments/ContentOnMemory.java
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/attachments/ContentStore.java
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/attachments/ContentStoreFactory.java
Modified:
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/attachments/Part.java
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/attachments/PartDataHandler.java
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/attachments/PartImpl.java
Modified: webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/attachments/Part.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/attachments/Part.java?rev=1209729&r1=1209728&r2=1209729&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/attachments/Part.java (original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/attachments/Part.java Fri Dec 2 22:14:21 2011
@@ -16,24 +16,16 @@
* specific language governing permissions and limitations
* under the License.
*/
-
package org.apache.axiom.attachments;
import javax.activation.DataHandler;
import javax.mail.MessagingException;
/**
- * Abstract for Part. A Part can be the SOAP Part or an Attachment Part.
- * There are several implementations for part, which are optimized for
- * space and time.
- *
- * A Part is created with the PartFactory.
- *
- * @see org.apache.axiom.attachments.ContentStoreFactory
+ * Interface representing a MIME part. A part can be the SOAP part (or more generally the root part
+ * for non-MTOM XOP encoded messages) or an attachment part.
*/
public interface Part {
-
-
/**
* @return DataHandler representing this part
*/
@@ -61,5 +53,4 @@ public interface Part {
* @throws MessagingException
*/
public String getHeader(String name) throws MessagingException;
-
}
Copied: webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/attachments/PartContent.java (from r1209288, webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/attachments/ContentStore.java)
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/attachments/PartContent.java?p2=webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/attachments/PartContent.java&p1=webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/attachments/ContentStore.java&r1=1209288&r2=1209729&rev=1209729&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/attachments/ContentStore.java (original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/attachments/PartContent.java Fri Dec 2 22:14:21 2011
@@ -16,7 +16,6 @@
* specific language governing permissions and limitations
* under the License.
*/
-
package org.apache.axiom.attachments;
import java.io.IOException;
@@ -26,22 +25,45 @@ import java.io.OutputStream;
import javax.activation.DataSource;
/**
- * Stores the content of a MIME part.
+ * Stores the content of a MIME part using a particular buffering strategy.
*/
-abstract class ContentStore {
+abstract class PartContent {
+ /**
+ * Get an {@link InputStream} representing the buffered MIME part content. Note that a new
+ * {@link InputStream} object must be returned each time this method is called, and the stream
+ * must be positioned at the beginning of the data.
+ *
+ * @return the stream representing the content of this MIME part
+ * @throws IOException
+ * if an error occurs while accessing the buffered content
+ */
abstract InputStream getInputStream() throws IOException;
/**
- * Get a {@link DataSource} implementation specific for this buffering strategy.
- * @param contentType TODO
+ * Get a {@link DataSource} implementation specific for this buffering strategy, if supported.
*
+ * @param contentType
+ * the content type for the {@link DataSource}, which must be returned by
+ * {@link DataSource#getContentType()}
* @return the {@link DataSource} implementation or <code>null</code> if a default
* {@link DataSource} implementation should be used
*/
abstract DataSource getDataSource(String contentType);
+ /**
+ * Write the buffered MIME part content to the given output stream. Note that the implementation
+ * must not consume the content, i.e. the content must still be available after this method
+ * completes.
+ *
+ * @param out
+ * the output stream to write the content to
+ * @throws IOException
+ * if an I/O error occurs (either while reading the buffered content or while
+ * writing to the output stream)
+ */
abstract void writeTo(OutputStream out) throws IOException;
+ // TODO: currently not used; all our DataSources should implement SizeAwareDataSource!
abstract long getSize();
abstract void destroy() throws IOException;
Copied: webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/attachments/PartContentFactory.java (from r1209288, webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/attachments/ContentStoreFactory.java)
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/attachments/PartContentFactory.java?p2=webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/attachments/PartContentFactory.java&p1=webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/attachments/ContentStoreFactory.java&r1=1209288&r2=1209729&rev=1209729&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/attachments/ContentStoreFactory.java (original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/attachments/PartContentFactory.java Fri Dec 2 22:14:21 2011
@@ -16,7 +16,6 @@
* specific language governing permissions and limitations
* under the License.
*/
-
package org.apache.axiom.attachments;
import org.apache.axiom.attachments.impl.BufferUtils;
@@ -30,42 +29,41 @@ import org.apache.commons.logging.LogFac
import java.io.InputStream;
/**
- * The PartFactory creates an object that represents a Part
- * (implements the Part interface). There are different ways
- * to represent a part (backing file or backing array etc.).
- * These different implementations should not be exposed to the
- * other layers of the code. The PartFactory helps maintain this
- * abstraction, and makes it easier to add new implementations.
+ * Factory for {@link PartContent} objects. There are different ways to store the content of a part
+ * (backing file or backing array etc.). These different implementations should not be exposed to
+ * the other layers of the code. The {@link PartContentFactory} helps maintain this abstraction, and
+ * makes it easier to add new implementations.
*/
-class ContentStoreFactory {
+class PartContentFactory {
private static int inflight = 0; // How many attachments are currently being built.
- private static String semifore = "PartFactory.semifore";
+ private static final String semifore = "PartFactory.semifore";
- private static Log log = LogFactory.getLog(ContentStoreFactory.class);
+ private static final Log log = LogFactory.getLog(PartContentFactory.class);
// Maximum number of threads allowed through createPart
- private static int INFLIGHT_MAX = 4;
+ private static final int INFLIGHT_MAX = 4;
// Constants for dynamic threshold
// Dynamic Threshold = availMemory / THRESHOLD_FACTOR
private static final int THRESHOLD_FACTOR = 5;
/**
- * Creates a part from the input stream.
- * The remaining parameters are used to determine if the
- * part should be represented in memory (byte buffers) or
- * backed by a file.
+ * Creates a {@link PartContent} object from a given input stream. The remaining parameters are
+ * used to determine if the content should be stored in memory (byte buffers) or backed by a
+ * file.
*
- * @param in MIMEBodyPartInputStream
+ * @param manager
+ * @param in
* @param isSOAPPart
* @param thresholdSize
* @param attachmentDir
* @param messageContentLength
* @return Part
- * @throws OMException if any exception is encountered while processing.
+ * @throws OMException
+ * if any exception is encountered while processing.
*/
- static ContentStore createContentStore(LifecycleManager manager, InputStream in,
+ static PartContent createPartContent(LifecycleManager manager, InputStream in,
boolean isSOAPPart,
int thresholdSize,
String attachmentDir,
@@ -80,7 +78,7 @@ class ContentStoreFactory {
}
try {
- ContentStore part;
+ PartContent partContent;
try {
// Message throughput is increased if the number of threads in this
@@ -119,7 +117,7 @@ class ContentStoreFactory {
// keeps the data in non-contiguous byte buffers.
BAAOutputStream baaos = new BAAOutputStream();
BufferUtils.inputStream2OutputStream(in, baaos);
- part = new ContentOnMemory(baaos.buffers(), baaos.length());
+ partContent = new PartContentOnMemory(baaos.buffers(), baaos.length());
} else {
// We need to read the input stream to determine whether
// the size is bigger or smaller than the threshold.
@@ -127,13 +125,13 @@ class ContentStoreFactory {
int count = BufferUtils.inputStream2OutputStream(in, baaos, thresholdSize);
if (count < thresholdSize) {
- part = new ContentOnMemory(baaos.buffers(), baaos.length());
+ partContent = new PartContentOnMemory(baaos.buffers(), baaos.length());
} else {
// A BAAInputStream is an input stream over a list of non-contiguous 4K buffers.
BAAInputStream baais =
new BAAInputStream(baaos.buffers(), baaos.length());
- part = new ContentOnFile(manager,
+ partContent = new PartContentOnFile(manager,
baais,
in,
attachmentDir);
@@ -149,7 +147,7 @@ class ContentStoreFactory {
}
}
- return part;
+ return partContent;
} catch (Exception e) {
throw new OMException(e);
Copied: webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/attachments/PartContentOnFile.java (from r1209288, webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/attachments/ContentOnFile.java)
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/attachments/PartContentOnFile.java?p2=webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/attachments/PartContentOnFile.java&p1=webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/attachments/ContentOnFile.java&r1=1209288&r2=1209729&rev=1209729&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/attachments/ContentOnFile.java (original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/attachments/PartContentOnFile.java Fri Dec 2 22:14:21 2011
@@ -16,7 +16,6 @@
* specific language governing permissions and limitations
* under the License.
*/
-
package org.apache.axiom.attachments;
import org.apache.axiom.attachments.impl.BufferUtils;
@@ -30,26 +29,24 @@ import java.io.InputStream;
import java.io.OutputStream;
/**
- * PartOnFile stores that attachment in a file.
- * This implementation is used for very large attachments to reduce
- * the in-memory footprint.
+ * Stores the content of a MIME part in a file. This implementation is used for very large
+ * attachments to reduce the in-memory footprint.
*
- * The PartOnFile object is created by the PartFactory
- * @see ContentStoreFactory
+ * @see PartContentFactory
*/
-class ContentOnFile extends ContentStore {
-
- FileAccessor fileAccessor;
- LifecycleManager manager;
-
+class PartContentOnFile extends PartContent {
+ private final FileAccessor fileAccessor;
+ private final LifecycleManager manager;
/**
- * Create a PartOnFile from the specified InputStream
+ * Constructor.
+ *
+ * @param manager TODO
* @param in1 InputStream containing data
* @param in2 InputStream containing data
* @param attachmentDir String
*/
- ContentOnFile(LifecycleManager manager, InputStream is1, InputStream is2, String attachmentDir) throws IOException {
+ PartContentOnFile(LifecycleManager manager, InputStream is1, InputStream is2, String attachmentDir) throws IOException {
this.manager = manager;
fileAccessor = manager.create(attachmentDir);
@@ -91,9 +88,6 @@ class ContentOnFile extends ContentStore
}
}
- /* (non-Javadoc)
- * @see org.apache.axiom.attachments.impl.AbstractPart#getSize()
- */
long getSize() {
return fileAccessor.getSize();
}
Copied: webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/attachments/PartContentOnMemory.java (from r1209288, webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/attachments/ContentOnMemory.java)
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/attachments/PartContentOnMemory.java?p2=webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/attachments/PartContentOnMemory.java&p1=webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/attachments/ContentOnMemory.java&r1=1209288&r2=1209729&rev=1209729&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/attachments/ContentOnMemory.java (original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/attachments/PartContentOnMemory.java Fri Dec 2 22:14:21 2011
@@ -16,7 +16,6 @@
* specific language governing permissions and limitations
* under the License.
*/
-
package org.apache.axiom.attachments;
import org.apache.axiom.attachments.utils.BAAInputStream;
@@ -29,24 +28,24 @@ import java.util.ArrayList;
import javax.activation.DataSource;
/**
- * PartOnMemoryEnhanced stores the attachment in memory (in non-contigous byte arrays)
- * This implementation is used for smaller attachments to enhance
- * performance.
+ * Stores the content of a MIME part in memory (in non-contiguous byte arrays). This implementation
+ * is used for smaller attachments to enhance performance.
*
- * The PartOnMemoryEnhanced object is created by the PartFactory
- * @see ContentStoreFactory
+ * @see PartContentFactory
*/
-class ContentOnMemory extends ContentStore {
-
- ArrayList data; // Arrays of 4K buffers
- int length; // total length of data
+class PartContentOnMemory extends PartContent {
+ private final ArrayList data; // Arrays of 4K buffers
+ private final int length; // total length of data
/**
- * Construct a PartOnMemory
- * @param data array list of 4K byte[]
- * @param length (length of data in bytes)
+ * Constructor.
+ *
+ * @param data
+ * a list of 4K byte arrays
+ * @param length
+ * the total length of the data in bytes
*/
- ContentOnMemory(ArrayList data, int length) {
+ PartContentOnMemory(ArrayList data, int length) {
this.data = data;
this.length = length;
}
Modified: webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/attachments/PartDataHandler.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/attachments/PartDataHandler.java?rev=1209729&r1=1209728&r2=1209729&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/attachments/PartDataHandler.java (original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/attachments/PartDataHandler.java Fri Dec 2 22:14:21 2011
@@ -26,6 +26,7 @@ import javax.activation.DataSource;
import org.apache.axiom.attachments.lifecycle.DataHandlerExt;
+// TODO: we should override writeTo and delegate to PartImpl#writeTo
class PartDataHandler extends DataHandler implements DataHandlerExt {
private final PartImpl part;
private DataSource dataSource;
Modified: webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/attachments/PartImpl.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/attachments/PartImpl.java?rev=1209729&r1=1209728&r2=1209729&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/attachments/PartImpl.java (original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/attachments/PartImpl.java Fri Dec 2 22:14:21 2011
@@ -83,13 +83,13 @@ final class PartImpl implements Part {
/**
* The content of this part. This is only set if the state is {@link #STATE_BUFFERED}.
*/
- private ContentStore content;
+ private PartContent content;
private final DataHandler dataHandler;
/**
* The actual parts are constructed with the PartFactory.
- * @see org.apache.axiom.attachments.ContentStoreFactory
+ * @see org.apache.axiom.attachments.PartContentFactory
* @param headers
*/
PartImpl(MIMEMessage message, boolean isSOAPPart, List headers, MimeTokenStream parser) {
@@ -178,7 +178,7 @@ final class PartImpl implements Part {
return getContent().getSize();
}
- private ContentStore getContent() {
+ private PartContent getContent() {
switch (state) {
case STATE_UNREAD:
fetch();
@@ -208,7 +208,7 @@ final class PartImpl implements Part {
checkParserState(parser.getState(), EntityState.T_BODY);
// The PartFactory will determine which Part implementation is most appropriate.
- content = ContentStoreFactory.createContentStore(message.getLifecycleManager(),
+ content = PartContentFactory.createPartContent(message.getLifecycleManager(),
parser.getDecodedInputStream(),
isSOAPPart,
message.getThreshold(),
@@ -248,7 +248,7 @@ final class PartImpl implements Part {
state = STATE_STREAMING;
return parser.getDecodedInputStream();
} else {
- ContentStore content = getContent();
+ PartContent content = getContent();
InputStream stream = content.getInputStream();
if (!preserve) {
stream = new ReadOnceInputStreamWrapper(this, stream);