⇒ Index (Frames) |  ⇒ Index (No Frames) |  ⇒ Package |  ⇒ Package Tree |  ⇒ Full Tree 
javax.mail

Class Multipart

java.lang.Object
|
+--javax.mail.Multipart

Known Direct Subclasses:
MimeMultipart


public abstract class Multipart
extends java.lang.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:

Field Summary

String

contentType

This field specifies the content-type of this multipart object.

Part

parent

The Part containing this Multipart, if known.

List

parts

List of BodyPart objects.

Constructor Summary

Multipart()

Default constructor.

Method Summary

synchronized void

addBodyPart(BodyPart part)

Adds a Part to the multipart.

synchronized void

addBodyPart(BodyPart part, int index)

Adds a BodyPart at position index.

BodyPart

getBodyPart(int index)

Get the specified Part.

String

getContentType()

Return the content-type of this Multipart.

int

getCount()

Return the number of enclosed BodyPart objects.

Part

getParent()

Return the Part that contains this Multipart object, or null if not known.

boolean

removeBodyPart(BodyPart part)

Remove the specified part from the multipart message.

void

removeBodyPart(int index)

Remove the part at specified location (starting from 0).

void

setMultipartDataSource(MultipartDataSource mp)

Setup this Multipart object from the given MultipartDataSource.

void

setParent(Part part)

Set the parent of this Multipart to be the specified Part.

void

writeTo(OutputStream os)

Output an appropriately encoded bytestream to the given OutputStream.

Field Details

contentType

protected String contentType

This field specifies the content-type of this multipart object. It defaults to "multipart/mixed".


parent

protected Part parent

The Part containing this Multipart, if known.


parts

protected List parts

List of BodyPart objects.

Constructor Details

Multipart

protected Multipart()

Default constructor. An empty Multipart object is created.

Method Details

addBodyPart

public synchronized void addBodyPart(BodyPart part)

Adds a Part to the multipart. The BodyPart is appended to the list of existing Parts.

Parameters:
part - The Part to be appended
Throws:
IllegalWriteException - if the underlying implementation does not support modification of existing values

addBodyPart

public synchronized void addBodyPart(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.

Parameters:
part - The BodyPart to be inserted
index - Location where to insert the part
Throws:
IllegalWriteException - if the underlying implementation does not support modification of existing values

getBodyPart

public BodyPart getBodyPart(int index)

Get the specified Part. Parts are numbered starting at 0.

Parameters:
index - the index of the desired Part
Throws:
- if the given index is out of range.

getContentType

public String getContentType()

Return the content-type of this Multipart.

This implementation just returns the value of the contentType field.


getCount

public int getCount()

Return the number of enclosed BodyPart objects.


getParent

public Part getParent()

Return the Part that contains this Multipart object, or null if not known.


removeBodyPart

public void removeBodyPart(int index)

Remove the part at specified location (starting from 0). Shifts all the parts after the removed part down one.

Parameters:
index - Index of the part to remove
Throws:
- if the given index is out of range.
IllegalWriteException - if the underlying implementation does not support modification of existing values

removeBodyPart

public boolean removeBodyPart(BodyPart part)

Remove the specified part from the multipart message. Shifts all the parts after the removed part down one.

Parameters:
part - The part to remove
Returns:
true if part removed, false otherwise
Throws:
MessagingException - if no such Part exists
IllegalWriteException - if the underlying implementation does not support modification of existing values

setMultipartDataSource

protected void setMultipartDataSource(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.

Parameters:
mp - Multipart datasource

setParent

public void setParent(Part part)

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.

Parameters:
part

writeTo

public void writeTo(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.

Parameters:
os