FileDocCategorySizeDatePackage
Multipart.javaAPI DocJavaMail 1.4.39425Tue Nov 17 10:38:12 GMT 2009javax.mail

Multipart

public abstract class Multipart extends Object
Multipart is a container that holds multiple body parts. Multipart provides methods to retrieve and set its subparts.

Multipart also acts as the base class for the content object returned by most Multipart DataContentHandlers. For example, invoking getContent() on a DataHandler whose source is a "multipart/signed" data source may return an appropriate subclass of Multipart.

Some messaging systems provide different subtypes of Multiparts. For example, MIME specifies a set of subtypes that include "alternative", "mixed", "related", "parallel", "signed", etc.

Multipart is an abstract class. Subclasses provide actual implementations.

author
John Mani

Fields Summary
protected Vector
parts
Vector of BodyPart objects.
protected String
contentType
This field specifies the content-type of this multipart object. It defaults to "multipart/mixed".
protected Part
parent
The Part containing this Multipart, if known.
Constructors Summary
protected Multipart()
Default constructor. An empty Multipart object is created.


                  
       
Methods Summary
public synchronized voidaddBodyPart(javax.mail.BodyPart part)
Adds a Part to the multipart. The BodyPart is appended to the list of existing Parts.

param
part The Part to be appended
exception
MessagingException
exception
IllegalWriteException if the underlying implementation does not support modification of existing values

	if (parts == null)
	    parts = new Vector();

	parts.addElement(part);
	part.setParent(this);
    
public synchronized voidaddBodyPart(javax.mail.BodyPart part, int index)
Adds a BodyPart at position index. If index is not the last one in the list, the subsequent parts are shifted up. If index is larger than the number of parts present, the BodyPart is appended to the end.

param
part The BodyPart to be inserted
param
index Location where to insert the part
exception
MessagingException
exception
IllegalWriteException if the underlying implementation does not support modification of existing values

	if (parts == null)
	    parts = new Vector();

	parts.insertElementAt(part, index);
	part.setParent(this);
    
public synchronized javax.mail.BodyPartgetBodyPart(int index)
Get the specified Part. Parts are numbered starting at 0.

param
index the index of the desired Part
return
the Part
exception
IndexOutOfBoundsException if the given index is out of range.
exception
MessagingException

	if (parts == null)
	    throw new IndexOutOfBoundsException("No such BodyPart");

	return (BodyPart)parts.elementAt(index);
    
public java.lang.StringgetContentType()
Return the content-type of this Multipart.

This implementation just returns the value of the contentType field.

return
content-type
see
#contentType

	return contentType;
    
public synchronized intgetCount()
Return the number of enclosed BodyPart objects.

return
number of parts
see
#parts

	if (parts == null)
	    return 0;

	return parts.size();
    
public synchronized javax.mail.PartgetParent()
Return the Part that contains this Multipart object, or null if not known.

since
JavaMail 1.1

	return parent;
    
public synchronized booleanremoveBodyPart(javax.mail.BodyPart part)
Remove the specified part from the multipart message. Shifts all the parts after the removed part down one.

param
part The part to remove
return
true if part removed, false otherwise
exception
MessagingException if no such Part exists
exception
IllegalWriteException if the underlying implementation does not support modification of existing values

	if (parts == null)
	    throw new MessagingException("No such body part");

	boolean ret = parts.removeElement(part);
	part.setParent(null);
	return ret;
    
public synchronized voidremoveBodyPart(int index)
Remove the part at specified location (starting from 0). Shifts all the parts after the removed part down one.

param
index Index of the part to remove
exception
MessagingException
exception
IndexOutOfBoundsException if the given index is out of range.
exception
IllegalWriteException if the underlying implementation does not support modification of existing values

	if (parts == null)
	    throw new IndexOutOfBoundsException("No such BodyPart");

	BodyPart part = (BodyPart)parts.elementAt(index);
	parts.removeElementAt(index);
	part.setParent(null);
    
protected synchronized voidsetMultipartDataSource(javax.mail.MultipartDataSource mp)
Setup this Multipart object from the given MultipartDataSource.

The method adds the MultipartDataSource's BodyPart objects into this Multipart. This Multipart's contentType is set to that of the MultipartDataSource.

This method is typically used in those cases where one has a multipart data source that has already been pre-parsed into the individual body parts (for example, an IMAP datasource), but needs to create an appropriate Multipart subclass that represents a specific multipart subtype.

param
mp Multipart datasource

	contentType = mp.getContentType();

	int count = mp.getCount();
	for (int i = 0; i < count; i++)
	    addBodyPart(mp.getBodyPart(i));
    
public synchronized voidsetParent(javax.mail.Part parent)
Set the parent of this Multipart to be the specified Part. Normally called by the Message or BodyPart setContent(Multipart) method. parent may be null if the Multipart is being removed from its containing Part.

since
JavaMail 1.1

	this.parent = parent;
    
public abstract voidwriteTo(java.io.OutputStream os)
Output an appropriately encoded bytestream to the given OutputStream. The implementation subclass decides the appropriate encoding algorithm to be used. The bytestream is typically used for sending.

exception
IOException if an IO related exception occurs
exception
MessagingException