javax.mail

Class Service

public abstract class Service extends Object

Field Summary
protected booleandebug
Debug flag for this service, set from the Session's debug flag.
protected Sessionsession
The session from which this service was created.
protected URLNameurl
The URLName of this service
Constructor Summary
protected Service(Session session, URLName url)
Construct a new Service.
Method Summary
voidaddConnectionListener(ConnectionListener listener)
voidclose()
Close this service and terminate its physical connection.
voidconnect()
A generic connect method that takes no parameters allowing subclasses to implement an appropriate authentication scheme.
voidconnect(String host, String user, String password)
Connect to the specified host using a simple username/password authenticaion scheme and the default port.
voidconnect(String host, int port, String user, String password)
Connect to the specified host at the specified port using a simple username/password authenticaion scheme.
protected voidfinalize()
URLNamegetURLName()
Return a copy of the URLName representing this service with the password and file information removed.
booleanisConnected()
Check if this service is currently connected.
protected voidnotifyConnectionListeners(int type)
protected booleanprotocolConnect(String host, int port, String user, String password)
Attempt the protocol-specific connection; subclasses should override this to establish a connection in the appropriate manner.
protected voidqueueEvent(MailEvent event, Vector listeners)
voidremoveConnectionListener(ConnectionListener listener)
protected voidsetConnected(boolean connected)
Notification to subclasses that the connection state has changed.
protected voidsetURLName(URLName url)
Set the url field.
StringtoString()

Field Detail

debug

protected boolean debug
Debug flag for this service, set from the Session's debug flag.

session

protected Session session
The session from which this service was created.

url

protected URLName url
The URLName of this service

Constructor Detail

Service

protected Service(Session session, URLName url)
Construct a new Service.

Parameters: session the session from which this service was created url the URLName of this service

Method Detail

addConnectionListener

public void addConnectionListener(ConnectionListener listener)

close

public void close()
Close this service and terminate its physical connection. The default implementation simply calls setConnected(false) and then sends a CLOSED event to all registered ConnectionListeners. Subclasses overriding this method should still ensure it is closed; they should also ensure that it is called if the connection is closed automatically, for for example in a finalizer.

Throws: MessagingException if there were errors closing; the connection is still closed

connect

public void connect()
A generic connect method that takes no parameters allowing subclasses to implement an appropriate authentication scheme. The default implementation calls connect(null, null, null)

Throws: AuthenticationFailedException if authentication fails MessagingException for other failures

connect

public void connect(String host, String user, String password)
Connect to the specified host using a simple username/password authenticaion scheme and the default port. The default implementation calls connect(host, -1, user, password)

Parameters: host the host to connect to user the user name password the user's password

Throws: AuthenticationFailedException if authentication fails MessagingException for other failures

connect

public void connect(String host, int port, String user, String password)
Connect to the specified host at the specified port using a simple username/password authenticaion scheme. If this Service is already connected, an IllegalStateException is thrown.

Parameters: host the host to connect to port the port to connect to; pass -1 to use the default for the protocol user the user name password the user's password

Throws: AuthenticationFailedException if authentication fails MessagingException for other failures IllegalStateException if this service is already connected

finalize

protected void finalize()

getURLName

public URLName getURLName()
Return a copy of the URLName representing this service with the password and file information removed.

Returns: the URLName for this service

isConnected

public boolean isConnected()
Check if this service is currently connected. The default implementation simply returns the value of a private boolean field; subclasses may wish to override this method to verify the physical connection.

Returns: true if this service is connected

notifyConnectionListeners

protected void notifyConnectionListeners(int type)

protocolConnect

protected boolean protocolConnect(String host, int port, String user, String password)
Attempt the protocol-specific connection; subclasses should override this to establish a connection in the appropriate manner. This method should return true if the connection was established. It may return false to cause the Service method to reattempt the connection after trying to obtain user and password information from the user. Alternatively it may throw a AuthenticatedFailedException to abandon the conection attempt.

Parameters: host port user password

Returns:

Throws: AuthenticationFailedException if authentication fails MessagingException for other failures

queueEvent

protected void queueEvent(MailEvent event, Vector listeners)

removeConnectionListener

public void removeConnectionListener(ConnectionListener listener)

setConnected

protected void setConnected(boolean connected)
Notification to subclasses that the connection state has changed. This method is called by the connect() and close() methods to indicate state change; subclasses should also call this method if the connection is automatically closed for some reason.

Parameters: connected the connection state

setURLName

protected void setURLName(URLName url)
Set the url field.

Parameters: url the new value

toString

public String toString()