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 2016/04/28 23:13:22 UTC
svn commit: r1741516 - in
/webservices/axiom/trunk/axiom-api/src/main/java/org/apache/axiom/attachments:
MIMEMessage.java MIMEMessageAdapter.java
Author: veithen
Date: Thu Apr 28 21:13:22 2016
New Revision: 1741516
URL: http://svn.apache.org/viewvc?rev=1741516&view=rev
Log:
AXIOM-31: Store Part objects instead of DataHandlers internally.
Modified:
webservices/axiom/trunk/axiom-api/src/main/java/org/apache/axiom/attachments/MIMEMessage.java
webservices/axiom/trunk/axiom-api/src/main/java/org/apache/axiom/attachments/MIMEMessageAdapter.java
Modified: webservices/axiom/trunk/axiom-api/src/main/java/org/apache/axiom/attachments/MIMEMessage.java
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/axiom-api/src/main/java/org/apache/axiom/attachments/MIMEMessage.java?rev=1741516&r1=1741515&r2=1741516&view=diff
==============================================================================
--- webservices/axiom/trunk/axiom-api/src/main/java/org/apache/axiom/attachments/MIMEMessage.java (original)
+++ webservices/axiom/trunk/axiom-api/src/main/java/org/apache/axiom/attachments/MIMEMessage.java Thu Apr 28 21:13:22 2016
@@ -66,10 +66,10 @@ class MIMEMessage {
private final MimeTokenStream parser;
/**
- * Stores the Data Handlers of the already parsed Mime Body Parts in the order that the attachments
+ * Stores the already parsed Mime Body Parts in the order that the attachments
* occur in the message. This map is keyed using the content-ID's.
*/
- private final Map<String,DataHandler> attachmentsMap = new LinkedHashMap<String,DataHandler>();
+ private final Map<String,PartImpl> partMap = new LinkedHashMap<String,PartImpl>();
/**
* The MIME part currently being processed.
@@ -134,11 +134,11 @@ class MIMEMessage {
DataHandler getDataHandler(String contentID) {
do {
- DataHandler dataHandler = attachmentsMap.get(contentID);
- if (dataHandler != null) {
- return dataHandler;
+ PartImpl part = partMap.get(contentID);
+ if (part != null) {
+ return part.getDataHandler();
}
- } while (getNextPartDataHandler() != null);
+ } while (getNextPart() != null);
return null;
}
@@ -164,8 +164,8 @@ class MIMEMessage {
String getRootPartContentID() {
// to handle the Start parameter not mentioned situation
if (rootPartContentID == null) {
- if (attachmentsMap.isEmpty()) {
- getNextPartDataHandler();
+ if (partMap.isEmpty()) {
+ getNextPart();
}
return firstPartId;
} else {
@@ -205,7 +205,7 @@ class MIMEMessage {
* Force reading of all attachments.
*/
void fetchAllParts() {
- while (getNextPartDataHandler() != null) {
+ while (getNextPart() != null) {
// Just loop until getNextPartDataHandler returns null
}
}
@@ -214,15 +214,15 @@ class MIMEMessage {
if (fetchAll) {
fetchAllParts();
}
- return attachmentsMap.keySet();
+ return partMap.keySet();
}
- Map<String,DataHandler> getMap() {
+ Map<String,Part> getMap() {
fetchAllParts();
- return Collections.unmodifiableMap(attachmentsMap);
+ return Collections.<String,Part>unmodifiableMap(partMap);
}
- private DataHandler getNextPartDataHandler() throws OMException {
+ private PartImpl getNextPart() throws OMException {
if (streamsRequested) {
throw new IllegalStateException("The attachments stream can only be accessed once; either by using the IncomingAttachmentStreams class or by getting a collection of AttachmentPart objects. They cannot both be called within the life time of the same service request.");
}
@@ -259,7 +259,7 @@ class MIMEMessage {
checkParserState(parser.next(), EntityState.T_BODY);
if (rootPartContentID == null) {
- isRootPart = attachmentsMap.isEmpty();
+ isRootPart = partMap.isEmpty();
} else {
isRootPart = rootPartContentID.equals(partContentID);
}
@@ -280,16 +280,15 @@ class MIMEMessage {
// We only get here if isRootPart is true
partContentID = "firstPart_" + UIDGenerator.generateContentId();
}
- if (attachmentsMap.isEmpty()) {
+ if (partMap.isEmpty()) {
firstPartId = partContentID;
}
- if (attachmentsMap.containsKey(partContentID)) {
+ if (partMap.containsKey(partContentID)) {
throw new OMException(
"Two MIME parts with the same Content-ID not allowed.");
}
- DataHandler dataHandler = currentPart.getDataHandler();
- attachmentsMap.put(partContentID, dataHandler);
- return dataHandler;
+ partMap.put(partContentID, currentPart);
+ return currentPart;
}
}
Modified: webservices/axiom/trunk/axiom-api/src/main/java/org/apache/axiom/attachments/MIMEMessageAdapter.java
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/axiom-api/src/main/java/org/apache/axiom/attachments/MIMEMessageAdapter.java?rev=1741516&r1=1741515&r2=1741516&view=diff
==============================================================================
--- webservices/axiom/trunk/axiom-api/src/main/java/org/apache/axiom/attachments/MIMEMessageAdapter.java (original)
+++ webservices/axiom/trunk/axiom-api/src/main/java/org/apache/axiom/attachments/MIMEMessageAdapter.java Thu Apr 28 21:13:22 2016
@@ -120,8 +120,13 @@ final class MIMEMessageAdapter extends A
@Override
Map<String,DataHandler> getMap() {
- Map<String,DataHandler> result = new LinkedHashMap<String,DataHandler>(message.getMap());
- result.keySet().removeAll(removedDataHandlers);
+ Map<String,DataHandler> result = new LinkedHashMap<String,DataHandler>();
+ for (Map.Entry<String,Part> entry : message.getMap().entrySet()) {
+ String contentID = entry.getKey();
+ if (!removedDataHandlers.contains(contentID)) {
+ result.put(contentID, entry.getValue().getDataHandler());
+ }
+ }
result.putAll(addedDataHandlers);
return Collections.unmodifiableMap(result);
}