63a64
> import org.apache.axis.SOAPPart;
66a68
> import java.util.*;
74,76c77,79
<     private Message msg;
<     private java.util.HashMap attachments = new java.util.HashMap();
<     protected org.apache.axis.SOAPPart soapPart = null;
---
>     private HashMap attachments = new java.util.HashMap();
> 	private LinkedList orderedAttachments=new LinkedList();
>     protected SOAPPart soapPart = null;
77,80d79
<     /**
<      * The actual stream to manage the multi-related input stream.
<      */
<     protected org.apache.axis.attachments.MultiPartRelatedInputStream mpartStream = null;
91d89
<      * @param msg the message associated 
97c95
<     public AttachmentsImpl(Message msg, 
---
>     public AttachmentsImpl(Object intialContents,
98d95
<                            Object intialContents, 
109d105
<         this.msg = msg;
122c118
<                         mpartStream = 
---
>                         MultiPartRelatedInputStream mpartStream =
137c133
<                         soapPart = new org.apache.axis.SOAPPart(msg, 
---
>                         soapPart = new org.apache.axis.SOAPPart(null,
139a136,137
> 						Collection atts=mpartStream.getAttachments();
> 						setAttachmentParts(atts);
148a147,182
>      * This method uses getAttacmentByReference() to look for attachment.
> 	 * If attachment has been found, it will be removed from the list, and
> 	 * returned to the user.
>      * @param  The reference that referers to an attachment.
>      * @return The part associated with the removed attachment, or null.
>      */
> 	public Part removeAttachmentPart(String reference) throws org.apache.axis.AxisFault{
> 		Part removedPart=getAttachmentByReference(reference);
> 		if(removedPart!=null){
> 			attachments.remove(removedPart.getContentId());
> 			attachments.remove(removedPart.getContentLocation());
> 			orderedAttachments.remove(removedPart);
> 		}
> 		return removedPart;
> 	}
> 
> 	/**
> 	 * Adds an existing attachment to this list.
> 	 * Note: Passed part will be bound to this message.
> 	 * @param newPart new part to add
> 	 * @returns Part old attachment with the same Content-ID, or null.
> 	 */
> 	public Part addAttachmentPart(Part newPart) throws org.apache.axis.AxisFault{
> 		Part oldPart=(Part)attachments.put(newPart.getContentId(),newPart);
> 		if(oldPart!=null){
> 			orderedAttachments.remove(oldPart);
> 			attachments.remove(oldPart.getContentLocation());
> 		}
> 		orderedAttachments.add(newPart);
> 		if(newPart.getContentLocation()!=null){
> 			attachments.put(newPart.getContentLocation(),newPart);
> 		}
> 		return oldPart;
> 	}
> 
>     /**
159,160c193,194
<         Part ret = new AttachmentPart(msg, 
<                                       (javax.activation.DataHandler)datahandler);
---
>         Part ret = new AttachmentPart((javax.activation.DataHandler)datahandler);
>         addAttachmentPart(ret);
161d194
<         attachments.put(ret.getContentId(), ret);
170a204
> 		orderedAttachments.clear();
175c209
<                     part.setMessage(msg);
---
> 					addAttachmentPart(part);
176d209
<                     attachments.put(part.getContentId(), part);
184a218,221
> 	 * <br>
> 	 * Note: if Content-Id or Content-Location headers have changed by outside
> 	 * code, lookup will not return proper values. In order to change these
> 	 * values attachment should be removed, then added again.
194c231
<         String[] id = null;
---
> 		Part ret = (Part) attachments.get(reference);
194a232,234
> 		if(ret!=null)
> 			return ret;
> 
203,204c243,244
<             id = new String[]{reference, fqreference};
<         } else {
---
> 			//lets see if we can get it as Content-Location
> 			ret = (AttachmentPart) attachments.get(fqreference);
205d244
<             id = new String[]{reference};
207,211d245
<         Part ret = (AttachmentPart) attachments.get(id);
<         if (ret == null && mpartStream != null) {
<             //We need to still check if this coming in the input stream;
<             ret = mpartStream.getAttachmentByReference(id);
<         }
222,227d255
<         java.util.Collection ret = new java.util.LinkedList();
< 
<         if (null != mpartStream) {
<             java.util.Collection mc = mpartStream.getAttachments();
<             ret = new java.util.LinkedList(mc); // make a copy.
<         }
229c257
<         return ret;
---
> 		return new LinkedList(orderedAttachments);
239a268,280
>     /**
>      * Sets the root part of this multipart block
>      */
>     public void setRootPart(Part newRoot){
> 		try{
> 			this.soapPart=(SOAPPart)newRoot;
> 		}catch(ClassCastException e){
> 			throw new ClassCastException("This attachment implementation "+
> 				  "accepts only SOAPPart objects as root part.");
> 		}
>     }
> 
> 
248c289
<                               multipart != null ? multipart : (multipart = org.apache.axis.attachments.MimeUtils.createMP(msg.getSOAPPart().getAsString(), attachments)));
---
>                               multipart != null ? multipart : (multipart = org.apache.axis.attachments.MimeUtils.createMP(soapPart.getAsString(), orderedAttachments)));
260,261c301,302
<                                                                          (multipart = org.apache.axis.attachments.MimeUtils.createMP(msg.getSOAPPart().getAsString(), attachments)));
<         for( java.util.Iterator i= attachments.values().iterator(); i.hasNext(); ){
---
>                                                                          (multipart = org.apache.axis.attachments.MimeUtils.createMP(soapPart.getAsString(), orderedAttachments)));
>         for( java.util.Iterator i= orderedAttachments.iterator(); i.hasNext(); ){
276c317
<                 (multipart = org.apache.axis.attachments.MimeUtils.createMP(msg.getSOAPPart().getAsString(), attachments)));
---
>                 (multipart = org.apache.axis.attachments.MimeUtils.createMP(soapPart.getAsString(), orderedAttachments)));
283c324
<         return attachments.size();
---
>         return orderedAttachments.size();
