java.lang.Object | +--javax.mail.ServiceKnown Direct Subclasses:
boolean | Debug flag for this service. |
The session from which this service was created. | |
The URLName of this service. |
Service(Session session, URLName url) Constructor. |
void | addConnectionListener(ConnectionListener l) Add a listener for Connection events on this service. |
synchronized void | close() Close this service and terminate its connection. |
void | connect() A generic connect method that takes no parameters. |
void | connect(String host, String user, String password) Connect to the specified address. |
void | connect(String host, int port, String user, String password) Similar to connect(host, user, password) except a specific port can be specified. |
Return a URLName representing this service. | |
boolean | Is this service currently connected? This implementation uses a private boolean field to store the connection state. |
void | notifyConnectionListeners(int type) Notify all ConnectionListeners. |
boolean | protocolConnect(String host, int port, String user, String password) The service implementation should override this method to perform the actual protocol-specific connection attempt. |
void | removeConnectionListener(ConnectionListener l) Remove a Connection event listener. |
void | setConnected(boolean connected) Set the connection state of this service. |
void | setURLName(URLName url) Set the URLName representing this service. |
String | toString() Return getURLName.toString() if this service has a URLName, otherwise it will return the default toString. |
protected boolean debug
protected Session session
protected URLName url
protected Service(Session session, URLName url)
public void addConnectionListener(ConnectionListener l)
public synchronized void close()
setConnected(false)
to set
this service's connected state to false. It will then send a close
ConnectionEvent to any registered ConnectionListeners. Subclasses
overriding this method to do implementation specific cleanup should
call this method as a last step to insure event notification,
probably by including a call to super.close()
in
a finally clause.
public void connect()
connect(String, String, String)
method with nulls.
AuthenticationFailedException
- for authentication failuresMessagingException
- for other failures
- if the service is already connectedpublic void connect(String host, String user, String password)
protocolConnect
method. If the protocolConnect
method returns false, the user will be prompted for any missing
information and the protocolConnect
method will be called
again. The subclass should override the protocolConnect
method. The subclass should also implement the getURLName
method, or use the implementation in this class.
On a successful connection, the setURLName
method is called
with a URLName that includes the information used to make the connection,
including the password.
If the password passed in is null and this is the first successful
connection to this service, the user name and the password collected from
the user will be saved as defaults for subsequent connection attempts to
this same service when using other Service object instances (the
connection information is typically always saved within a particular
Service object instance). The password is saved using the Session method
setPasswordAuthenticaiton
. If the password passed in is not
null, it is not saved, on the assumption that the application is managing
passwords explicitly.
AuthenticationFailedException
- for authentication failuresMessagingException
- for other failures
- if the service is already connectedpublic void connect(String host, int port, String user, String password)
AuthenticationFailedException
- for authentication failuresMessagingException
- for other failures
- if the service is already connectedpublic URLName getURLName()
public boolean isConnected()
protected void notifyConnectionListeners(int type)
protected boolean protocolConnect(String host, int port, String user, String password)
connect
method calls
this method as needed.
The protocolConnect
method should return false if a user
name or password is required for authentication but the corresponding
parameter is null; the connect method will prompt the user when needed
to supply missing information. This method may also return false if
authentication fails for the supplied user name or password.
Alternatively, this method may throw an AuthenticationFailedException
when authentication fails. This exception may include a String message
with more detail about the failure.
The protocolConnect
method should throw an exception to
report failures not related to authentication, such as an invalid host
name or port number, loss of a connection during the authentication
process, unavailability of the server, etc.
AuthenticationFailedException
- for authentication failuresMessagingException
- for non-authentication failurespublic void removeConnectionListener(ConnectionListener l)
protected void setConnected(boolean connected)
isConnected
method.
protected void setURLName(URLName url)
public String toString()