Java Doc for Service.java in  » EJB-Server-GlassFish » mail » javax » mail » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » EJB Server GlassFish » mail » javax.mail 
Source Cross Reference  Class Diagram Java Document (Java Doc) 


java.lang.Object
   javax.mail.Service

All known Subclasses:   javax.mail.Store,  javax.mail.Transport,
Service
abstract public class Service (Code)
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.
author:
   Christopher Cotton
author:
   Bill Shannon
author:
   Kanwar Oberoi
version:
   1.33, 07/05/14


Inner Class :static class TerminatorEvent extends MailEvent

Field Summary
protected  booleandebug
     Debug flag for this service.
protected  Sessionsession
     The session from which this service was created.
protected  URLNameurl
     The URLName of this service.

Constructor Summary
protected  Service(Session session, URLName urlname)
     Constructor.

Method Summary
public synchronized  voidaddConnectionListener(ConnectionListener l)
     Add a listener for Connection events on this service.
public synchronized  voidclose()
     Close this service and terminate its connection.
public  voidconnect()
     A generic connect method that takes no parameters.
public  voidconnect(String host, String user, String password)
     Connect to the specified address.
public  voidconnect(String user, String password)
     Connect to the current host using the specified username and password.
public synchronized  voidconnect(String host, int port, String user, String password)
     Similar to connect(host, user, password) except a specific port can be specified.
protected  voidfinalize()
     Stop the event dispatcher thread so the queue can be garbage collected.
public synchronized  URLNamegetURLName()
     Return a URLName representing this service.
public synchronized  booleanisConnected()
     Is this service currently connected?

This implementation uses a private boolean field to store the connection state.

protected synchronized  voidnotifyConnectionListeners(int type)
     Notify all ConnectionListeners.
protected  booleanprotocolConnect(String host, int port, String user, String password)
     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.
protected  voidqueueEvent(MailEvent event, Vector vector)
     Add the event and vector of listeners to the queue to be delivered.
public synchronized  voidremoveConnectionListener(ConnectionListener l)
     Remove a Connection event listener.
protected synchronized  voidsetConnected(boolean connected)
     Set the connection state of this service.
protected synchronized  voidsetURLName(URLName url)
     Set the URLName representing this service. Normally used to update the url field after a service has successfully connected.
public  StringtoString()
     Return getURLName.toString() if this service has a URLName, otherwise it will return the default toString.

Field Detail
debug
protected boolean debug(Code)
Debug flag for this service. Set from the session's debug flag when this service is created.



session
protected Session session(Code)
The session from which this service was created.



url
protected URLName url(Code)
The URLName of this service.




Constructor Detail
Service
protected Service(Session session, URLName urlname)(Code)
Constructor.
Parameters:
  session - Session object for this service
Parameters:
  urlname - URLName object to be used for this service




Method Detail
addConnectionListener
public synchronized void addConnectionListener(ConnectionListener l)(Code)
Add a listener for Connection events on this service.

The default implementation provided here adds this listener to an internal list of ConnectionListeners.
Parameters:
  l - the Listener for Connection events
See Also:   javax.mail.event.ConnectionEvent




close
public synchronized void close() throws MessagingException(Code)
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 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.
See Also:   javax.mail.event.ConnectionEvent
throws:
  MessagingException - for errors while closing




connect
public void connect() throws MessagingException(Code)
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 any ConnectionListeners 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.
exception:
  AuthenticationFailedException - for authentication failures
exception:
  MessagingException - for other failures
exception:
  IllegalStateException - if the service is already connected
See Also:   javax.mail.event.ConnectionEvent




connect
public void connect(String host, String user, String password) throws MessagingException(Code)
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 any ConnectionListeners 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 the 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 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.
Parameters:
  host - the host to connect to
Parameters:
  user - the user name
Parameters:
  password - this user's password
exception:
  AuthenticationFailedException - for authentication failures
exception:
  MessagingException - for other failures
exception:
  IllegalStateException - if the service is already connected
See Also:   javax.mail.event.ConnectionEvent
See Also:   javax.mail.Session.setPasswordAuthentication




connect
public void connect(String user, String password) throws MessagingException(Code)
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.
Parameters:
  user - the user name
Parameters:
  password - this user's password
exception:
  AuthenticationFailedException - for authentication failures
exception:
  MessagingException - for other failures
exception:
  IllegalStateException - if the service is already connected
See Also:   javax.mail.event.ConnectionEvent
See Also:   javax.mail.Session.setPasswordAuthentication
See Also:   Service.connect(java.lang.String,java.lang.String,java.lang.String)
since:
   JavaMail 1.4



connect
public synchronized void connect(String host, int port, String user, String password) throws MessagingException(Code)
Similar to connect(host, user, password) except a specific port can be specified.
Parameters:
  host - the host to connect to
Parameters:
  port - the port to connect to (-1 means the default port)
Parameters:
  user - the user name
Parameters:
  password - this user's password
exception:
  AuthenticationFailedException - for authentication failures
exception:
  MessagingException - for other failures
exception:
  IllegalStateException - if the service is already connected
See Also:   Service.connect(java.lang.String,java.lang.String,java.lang.String)
See Also:   javax.mail.event.ConnectionEvent



finalize
protected void finalize() throws Throwable(Code)
Stop the event dispatcher thread so the queue can be garbage collected.



getURLName
public synchronized URLName getURLName()(Code)
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
See Also:   URLName




isConnected
public synchronized boolean isConnected()(Code)
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




notifyConnectionListeners
protected synchronized void notifyConnectionListeners(int type)(Code)
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.




protocolConnect
protected boolean protocolConnect(String host, int port, String user, String password) throws MessagingException(Code)
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 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.
Parameters:
  host - the name of the host to connect to
Parameters:
  port - the port to use (-1 means use default port)
Parameters:
  user - the name of the user to login as
Parameters:
  password - the user's password true if connection successful, false if authentication failed
exception:
  AuthenticationFailedException - for authentication failures
exception:
  MessagingException - for non-authentication failures




queueEvent
protected void queueEvent(MailEvent event, Vector vector)(Code)
Add the event and vector of listeners to the queue to be delivered.



removeConnectionListener
public synchronized void removeConnectionListener(ConnectionListener l)(Code)
Remove a Connection event listener.

The default implementation provided here removes this listener from the internal list of ConnectionListeners.
Parameters:
  l - the listener
See Also:   Service.addConnectionListener




setConnected
protected synchronized void setConnected(boolean connected)(Code)
Set the connection state of this service. The connection state will automatically be set by the service implementation during the connect and close 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.
Parameters:
  connected - true if the service is connected,false if it is not connected




setURLName
protected synchronized void setURLName(URLName url)(Code)
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 new URLName should be constructed with any unneeded fields removed.

The implementation in the Service class simply sets the url field.
See Also:   URLName




toString
public String toString()(Code)
Return getURLName.toString() if this service has a URLName, otherwise it will return the default toString.



Methods inherited from java.lang.Object
native protected Object clone() throws CloneNotSupportedException(Code)(Java Doc)
public boolean equals(Object obj)(Code)(Java Doc)
protected void finalize() throws Throwable(Code)(Java Doc)
final native public Class getClass()(Code)(Java Doc)
native public int hashCode()(Code)(Java Doc)
final native public void notify()(Code)(Java Doc)
final native public void notifyAll()(Code)(Java Doc)
public String toString()(Code)(Java Doc)
final native public void wait(long timeout) throws InterruptedException(Code)(Java Doc)
final public void wait(long timeout, int nanos) throws InterruptedException(Code)(Java Doc)
final public void wait() throws InterruptedException(Code)(Java Doc)

www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.