|
Java EE 5 SDK 深圳电信培训中心.徐海蛟老师. |
||||||||
上一个类 下一个类 | 框架 无框架 | ||||||||
摘要: 嵌套 | 字段 | 构造器 | 方法 | 详细信息: 字段 | 构造器 | 方法 |
javax.mail Class Service
java.lang.Object javax.mail.Service
public abstract class Service
- extends Object
An abstract class that contains the functionality common to messaging services, such as stores and transports.
A messaging service is created from a Session
and is
named using a URLName
. A service must be connected
before it can be used. Connection events are sent to reflect
its connection status.
- 版本:
- 1.33, 07/05/14
- 作者:
- Christopher Cotton, Bill Shannon, Kanwar Oberoi
字段摘要 | |
---|---|
protected boolean |
debug
Debug flag for this service. |
protected Session |
session
The session from which this service was created. |
protected URLName |
url
The URLName of this service. |
构造器摘要 | |
---|---|
protected |
Service(Session session,
URLName urlname)
Constructor. |
方法摘要 | |
---|---|
void |
addConnectionListener(ConnectionListener l)
Add a listener for Connection events on this service. |
void |
close()
Close this service and terminate its connection. |
void |
connect()
A generic connect method that takes no parameters. |
void |
connect(String host,
int port,
String user,
String password)
Similar to connect(host, user, password) except a specific port can be specified. |
void |
connect(String user,
String password)
Connect to the current host using the specified username and password. |
void |
connect(String host,
String user,
String password)
Connect to the specified address. |
protected void |
finalize()
Stop the event dispatcher thread so the queue can be garbage collected. |
URLName |
getURLName()
Return a URLName representing this service. |
boolean |
isConnected()
Is this service currently connected? |
protected void |
notifyConnectionListeners(int type)
Notify all ConnectionListeners. |
protected 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. |
protected void |
queueEvent(MailEvent event,
Vector vector)
Add the event and vector of listeners to the queue to be delivered. |
void |
removeConnectionListener(ConnectionListener l)
Remove a Connection event listener. |
protected void |
setConnected(boolean connected)
Set the connection state of this service. |
protected 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 . |
类方法继承 java.lang.Object |
---|
clone, equals, getClass, hashCode, notify, notifyAll, wait, wait, wait |
字段详细信息 |
---|
session
protected Session session
- The session from which this service was created.
url
protected URLName url
- The
URLName
of this service.
debug
protected boolean debug
- Debug flag for this service. Set from the session's debug
flag when this service is created.
构造器详细信息 |
---|
Service
protected Service(Session session, URLName urlname)
- Constructor.
- 参数:
session
- Session object for this serviceurlname
- URLName object to be used for this service
方法详细信息 |
---|
connect
public void connect() throws MessagingException
- A generic connect method that takes no parameters. Subclasses
can implement the appropriate authentication schemes. Subclasses
that need additional information might want to use some properties
or might get it interactively using a popup window.
If the connection is successful, an "open"
ConnectionEvent
is delivered to anyConnectionListeners
on this service.Most clients should just call this method to connect to the service.
It is an error to connect to an already connected service.
The implementation provided here simply calls the following
connect(String, String, String)
method with nulls. - 抛出异常:
AuthenticationFailedException
- for authentication failuresMessagingException
- for other failuresIllegalStateException
- if the service is already connected- 另请参见:
ConnectionEvent
connect
public void connect(String host, String user, String password) throws MessagingException
- Connect to the specified address. This method provides a simple
authentication scheme that requires a username and password.
If the connection is successful, an "open"
ConnectionEvent
is delivered to anyConnectionListeners
on this service.It is an error to connect to an already connected service.
The implementation in the Service class will collect defaults for the host, user, and password from the session, from the
URLName
for this service, and from the supplied parameters and then call theprotocolConnect
method. If theprotocolConnect
method returnsfalse
, the user will be prompted for any missing information and theprotocolConnect
method will be called again. The subclass should override theprotocolConnect
method. The subclass should also implement thegetURLName
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 username passed in is null, a default value will be chosen as described above. 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
setPasswordAuthentication
. If the password passed in is not null, it is not saved, on the assumption that the application is managing passwords explicitly. - 参数:
host
- the host to connect touser
- the user namepassword
- this user's password- 抛出异常:
AuthenticationFailedException
- for authentication failuresMessagingException
- for other failuresIllegalStateException
- if the service is already connected- 另请参见:
ConnectionEvent
,Session.setPasswordAuthentication(javax.mail.URLName, javax.mail.PasswordAuthentication)
connect
public void connect(String user, String password) throws MessagingException
- Connect to the current host using the specified username
and password. This method is equivalent to calling the
connect(host, user, password)
method with null for the host name. - 参数:
user
- the user namepassword
- this user's password- 抛出异常:
AuthenticationFailedException
- for authentication failuresMessagingException
- for other failuresIllegalStateException
- if the service is already connected- 从以下版本开始:
- JavaMail 1.4
- 另请参见:
ConnectionEvent
,Session.setPasswordAuthentication(javax.mail.URLName, javax.mail.PasswordAuthentication)
,connect(java.lang.String, java.lang.String, java.lang.String)
connect
public void connect(String host, int port, String user, String password) throws MessagingException
- Similar to connect(host, user, password) except a specific port
can be specified.
- 参数:
host
- the host to connect toport
- the port to connect to (-1 means the default port)user
- the user namepassword
- this user's password- 抛出异常:
AuthenticationFailedException
- for authentication failuresMessagingException
- for other failuresIllegalStateException
- if the service is already connected- 另请参见:
connect(java.lang.String, java.lang.String, java.lang.String)
,ConnectionEvent
protocolConnect
protected boolean protocolConnect(String host, int port, String user, String password) throws MessagingException
- The service implementation should override this method to
perform the actual protocol-specific connection attempt.
The default implementation of the
connect
method calls this method as needed.The
protocolConnect
method should returnfalse
if a user name or password is required for authentication but the corresponding parameter is null; theconnect
method will prompt the user when needed to supply missing information. This method may also returnfalse
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. - 参数:
host
- the name of the host to connect toport
- the port to use (-1 means use default port)user
- the name of the user to login aspassword
- the user's password- 返回:
- true if connection successful, false if authentication failed
- 抛出异常:
AuthenticationFailedException
- for authentication failuresMessagingException
- for non-authentication failures
isConnected
public boolean isConnected()
- Is this service currently connected?
This implementation uses a private boolean field to store the connection state. This method returns the value of that field.
Subclasses may want to override this method to verify that any connection to the message store is still alive.
- 返回:
- true if the service is connected, false if it is not connected
setConnected
protected void setConnected(boolean connected)
- Set the connection state of this service. The connection state
will automatically be set by the service implementation during the
connect
andclose
methods. Subclasses will need to call this method to set the state if the service was automatically disconnected.The implementation in this class merely sets the private field returned by the
isConnected
method. - 参数:
connected
- true if the service is connected, false if it is not connected
close
public void close() throws MessagingException
- Close this service and terminate its connection. A close
ConnectionEvent is delivered to any ConnectionListeners. Any
Messaging components (Folders, Messages, etc.) belonging to this
service are invalid after this service is closed. Note that the service
is closed even if this method terminates abnormally by throwing
a MessagingException.
This implementation uses
setConnected(false)
to set this service's connected state tofalse
. 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 tosuper.close()
in afinally
clause. - 抛出异常:
MessagingException
- for errors while closing- 另请参见:
ConnectionEvent
getURLName
public URLName getURLName()
- Return a URLName representing this service. The returned URLName
does not include the password field.
Subclasses should only override this method if their URLName does not follow the standard format.
The implementation in the Service class returns (usually a copy of) the
url
field with the password and file information stripped out. - 返回:
- the URLName representing this service
- 另请参见:
URLName
setURLName
protected void setURLName(URLName url)
- Set the URLName representing this service.
Normally used to update the
url
field after a service has successfully connected.Subclasses should only override this method if their URL does not follow the standard format. In particular, subclasses should override this method if their URL does not require all the possible fields supported by
URLName
; a newURLName
should be constructed with any unneeded fields removed.The implementation in the Service class simply sets the
url
field. - 另请参见:
URLName
addConnectionListener
public void addConnectionListener(ConnectionListener l)
- Add a listener for Connection events on this service.
The default implementation provided here adds this listener to an internal list of ConnectionListeners.
- 参数:
l
- the Listener for Connection events- 另请参见:
ConnectionEvent
removeConnectionListener
public void removeConnectionListener(ConnectionListener l)
- Remove a Connection event listener.
The default implementation provided here removes this listener from the internal list of ConnectionListeners.
- 参数:
l
- the listener- 另请参见:
addConnectionListener(javax.mail.event.ConnectionListener)
notifyConnectionListeners
protected void notifyConnectionListeners(int type)
- Notify all ConnectionListeners. Service implementations are
expected to use this method to broadcast connection events.
The provided default implementation queues the event into an internal event queue. An event dispatcher thread dequeues events from the queue and dispatches them to the registered ConnectionListeners. Note that the event dispatching occurs in a separate thread, thus avoiding potential deadlock problems.
toString
public String toString()
- Return
getURLName.toString()
if this service has a URLName, otherwise it will return the defaulttoString
.
queueEvent
protected void queueEvent(MailEvent event, Vector vector)
- Add the event and vector of listeners to the queue to be delivered.
finalize
protected void finalize() throws Throwable
- Stop the event dispatcher thread so the queue can be garbage collected.
- 抛出异常:
Throwable
|
Java EE 5 SDK 深圳电信培训中心.徐海蛟老师. |
||||||||
上一个类 下一个类 | 框架 无框架 | ||||||||
摘要: 嵌套 | 字段 | 构造器 | 方法 | 详细信息: 字段 | 构造器 | 方法 |
提交错误或意见
版权所有 2007 Sun Microsystems, Inc. 保留所有权利。 请遵守许可证条款。深圳电信培训中心.徐海蛟老师教学参考.