|
||||||||||
PREV NEXT | FRAMES NO FRAMES |
See:
Description
Packages | |
com.sun.im.desktop | Sun Messenger Beans API Overview The goal of the Sun Messenger Beans API is to allow developers to extend the Sun Messenger user interface. |
com.sun.im.provider | Sun ONE Instant Messaging Service Provider Interfaces
Sun ONE Instant Messaging supports the following types of service provider modules: Authentication/SSO providers and message archive providers. |
com.sun.im.service | Sun ONE IM Service API Overview Sun ONE Instant Messaging allows users to communicate in real-time, using the Conference, Presence, News and Notification services. |
In order to create sessions, an application must fisrt instantiate CollaborationSessionFactory. Then the factory can be used to create session objects for specific users. Example:
CollaborationSessionFactory fac = new CollaborationSessionFactory();
// create a session listener for asynchronous session events
CollaborationSessionListener listener = new MyCollaborationSessionListener();
// create a session
Session session = fac.getSession("myserver.example.com:9909",
"fred@example.com", "secret",
listener);
Accessing a service
Once a Session is created, individual services can be accessed using the accessService method. So for example with the Conference service:
// access the Conference ServiceNote that it is important to make sure that the session listener associated with a Session implements all the relevant methods for accessed services.
ConferenceSession cSession = (ConferenceSession)session.accessService(CollaborationSessionFactory.CONFERENCE);
// create a Conference Listener for asynchronous chat events (e.g. messages).To invite users to this conference, one needs to setup an invite message and call invite using this message.
MyConferenceListener cListener = new MyConferenceListener();
// create the conference.
Conference c = cSession.setupConference(cListener, Conference.MANAGE)
One can also join an already existing public conference, by using its well-known address:
// create invite message
Message newMsg = c.createInviteMessage();
newMsg.addRecipient("roscoe@example.com");
newMsg.addRecipient("yolanda@example.com");
MessagePart part = newMsg.newPart();
part.setContent("Let's talk");
newMsg.addPart(part);
// send the invite
e.invite(newMsg);
// join public conference conf123@example.comOnce a Conference object is created, it can be used to build and send messages, as if it was a private conference.
Conference c = cSession.join("conf123@example.com", cListener);
// create a news channel listener for asynchronous events (e.g. messages added or removed).
// note: MyNewsChannelListener implements the NewsChannelListener interface.
MyNewsChannelListener bbListener = new MyNewsChannelListener();
// subscribe to the news channel. news channel messages are received
// asynchronously, through the listener. One may also pass a null
NewsChannel bb = nSession.getNewsChannel("hugo@example.com", bbListener)
Once created, the NewsChannel object can be used to generate,
add or remove messages.
// generate a new message
Message message = bb.createMessage();
// add content to message
// publish it
bb.addMessage(message);
To find out which news channels are available, use the listNewsChannels
method:
// get a Collection of news channels.Finally, it is also possible to create new news channels, as follows:
java.util.Collection bbList = session.listNewsChannels();// loop through the list until you find the one you want
if (bbList != null) {
java.util.Iterator bbIter = bbList.iterator();
while (bbIter.hasNext()) {
NewsChannel bb = (NewsChannel)bbIter.next();
if (bb.getDestination.equals("theOneIWant")) {
break;
}
}
}// subscribe to it to get messages
bb.subscribe(bbListener);
bb = session.newNewsChannel("hugo@example.com", bbListener,
Conference.PUBLISH);
// start a message to noah@example.comfill it with appropriate content and headers,
Message message = nSession.createMessage("noah@example.com");
message.setHeader("Subject", "just a demo");create a message status listener if you expect status or replies,
MessagePart part = message.newPart();
String content = "the body of the message";
part.setContentType("text/plain");
part.setContent(content.bytes());
MyMessageStatusListener mListener = new MyMessageStatusListener();and send it:
session.sendMessage(message, mListener);
Messages can also be received. This is done through the NotificationSessionListener.onMessage
method. Received messages may be acknowledged or replied-to through
the MessageHandler argument to onMessage.
// mark a message read.
handler.sendStatus(MessageStatus.READ);// reply to a message
replyMessage = nSession.createMessage();
...
handler.sendReply(replayMessage);
To access the presence information of a user of the service, use the fetch or subscribe methods
// subscribe to hugo's presentity // Note: MyPresenceInfoListener implements PresenceInfoListener
MyPresenceInfoListener piListener = new MyPresenceInfoListener();
java.util.Date expiration =
PresenceSubscription subs = pSession.subscribe("hugo@example.com", piListener, expiration);
...// unsubscribe
subs.cancel();
Presence information is received asynchronously by the presence info listener in the form of an XML String. This String may be parsed using the PresenceHelper class. The following prints out presence info.
PresenceHelper ph = new PresenceHelper(pi /* XML string */);
for (Iterator i = ph.getTuples().iterator(); i.hasNext() ; ) {
PresenceTuple t = (PresenceTuple)i.next();
System.out.println(t.destination + " " + t.status + " " + t.note);
}
To publish presence information updates, use the publish method. The argument is an XML String which can be genberated with the help of the PresenceHelper class.
PresenceTuple pt = new PresenceTuple("hugo@example.com",
PresenceSession.STATUS_AWAY);
PresenceHelper ph = new PresenceHelper();
ph.addTuple(pt);
pSession.publish(ph.toString());
To retrieve the contact list of the user who owns the current session, retrieve the contact folders
Collection folders = psSession.getFolders(PersonalStoreFolder.CONTACT_FOLDER);For each folder fthe list of contacts can be obtained as follows:
Collection entries = f.getEntries();
System.out.println(" - " + f.getDisplayName());
for (Iterator j = entries.iterator() ; j.hasNext() ;) {
PersonalContact c = (PersonalContact)j.next();
System.out.println("Found " + c.getDisplayName() + " in " + f.getDisplayName());
}
To create an administrative set of credentials, follow these steps
|
||||||||||
PREV NEXT | FRAMES NO FRAMES |