javax.mail

Class Service

public abstract class Service extends Object

An abstract messaging service (store or transport).

Version: 1.4

Author: Chris Burdess

Field Summary
protected booleandebug
The debug flag for this service.
protected Sessionsession
The session context for this service.
protected URLNameurl
The URLName of this service.
Constructor Summary
protected Service(Session session, URLName url)
Constructor.
Method Summary
voidaddConnectionListener(ConnectionListener l)
Adds a listener for connection events on this service.
voidclose()
Closes this service, terminating any underlying connections.
voidconnect()
Connects to this service.
voidconnect(String user, String password)
Connects to this service.
voidconnect(String host, String user, String password)
Connects to this service using the specified details.
voidconnect(String host, int port, String user, String password)
Connects to this service using the specified details.
URLNamegetURLName()
Return a URLName representing this service.
booleanisConnected()
Indicates whether this service is currently connected.
protected voidnotifyConnectionListeners(int type)
Notify all connection listeners.
protected booleanprotocolConnect(String host, int port, String user, String password)
Provider implementation for a service.
protected voidqueueEvent(MailEvent event, Vector vector)
Adds the event and vector of listeners to be notified.
voidremoveConnectionListener(ConnectionListener l)
Removes a connection event listener.
protected voidsetConnected(boolean connected)
Sets the connection state of this service.
protected voidsetURLName(URLName url)
Set the URLName representing this service.
StringtoString()
Returns getURLName.toString if this service has a URLName, otherwise returns the default toString.

Field Detail

debug

protected boolean debug
The debug flag for this service. Initialised from the session's debug flag when this service is created.

session

protected Session session
The session context for this service.

url

protected URLName url
The URLName of this service.

Constructor Detail

Service

protected Service(Session session, URLName url)
Constructor.

Parameters: session the session context for this service url the URLName of this service

Method Detail

addConnectionListener

public void addConnectionListener(ConnectionListener l)
Adds a listener for connection events on this service.

close

public void close()
Closes this service, terminating any underlying connections.

connect

public void connect()
Connects to this service. If additional information is required, the provider can determine them from session properties or via a callback to the UI.

Throws: AuthenticationFailedException on authentication failure MessagingException for other failures IllegalStateException if the service is already connected

connect

public void connect(String user, String password)
Connects to this service. This method provides a simple authentication scheme requiring a username and password. The host is determined from the inital URLName.

Parameters: user the username password the password

Throws: AuthenticationFailedException on authentication failure MessagingException for other failures IllegalStateException if the service is already connected

Since: JavaMail 1.4

connect

public void connect(String host, String user, String password)
Connects to this service using the specified details. This method provides a simple authentication scheme requiring a username and password.

Parameters: host the host to connect to user the username password the password

Throws: AuthenticationFailedException on authentication failure MessagingException for other failures IllegalStateException if the service is already connected

connect

public void connect(String host, int port, String user, String password)
Connects to this service using the specified details. This method provides a simple authentication scheme requiring a username and password.

Parameters: host the host to connect to port the port to use (-1 for the default port) user the username password the password

Throws: AuthenticationFailedException on authentication failure MessagingException for other failures IllegalStateException if the service is already connected

getURLName

public URLName getURLName()
Return a URLName representing this service. The password field will not be returned.

isConnected

public boolean isConnected()
Indicates whether this service is currently connected.

notifyConnectionListeners

protected void notifyConnectionListeners(int type)
Notify all connection listeners.

protocolConnect

protected boolean protocolConnect(String host, int port, String user, String password)
Provider implementation for a service.

This method should return false if authentication fails, due to the username or password being unavailable or incorrect, or may throw AuthenticationFailedException for further details.

In the case of failures not related to authentication, such as an invalid configuration or network error, this method should throw an appropriate MessagingException.

Parameters: host the name of the host to connect to port the port to use (-1 for the default port) user the username password the password

Returns: true on success, false if authentication failed

Throws: AuthenticationFailedException on authentication failure MessagingException for non-authentication failures

queueEvent

protected void queueEvent(MailEvent event, Vector vector)
Adds the event and vector of listeners to be notified.

removeConnectionListener

public void removeConnectionListener(ConnectionListener l)
Removes a connection event listener.

setConnected

protected void setConnected(boolean connected)
Sets the connection state of this service.

setURLName

protected void setURLName(URLName url)
Set the URLName representing this service. This method is called when the service has successfully connected.

toString

public String toString()
Returns getURLName.toString if this service has a URLName, otherwise returns the default toString.
© Copyright 2003, 2004 The Free Software Foundation, All rights reserved