10.07.2015 Views

Lotus Instant Messaging/ Web Conferencing ... - IBM Redbooks

Lotus Instant Messaging/ Web Conferencing ... - IBM Redbooks

Lotus Instant Messaging/ Web Conferencing ... - IBM Redbooks

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

We also modify the imClosed() method to remove the user’s Im object from theHashtable, if it still contains it (see Example 3-16). It is at this point that you couldimplement logic to store the user’s preferences persistently, if required.Example 3-16 Modified imClosed() methodpublic void imClosed(ImEvent event){Im im = event.getIm();Im currentIm = null;for (int i = 0; i < m_imOpened.size(); i++){currentIm = (Im) m_imOpened.elementAt(i);if (currentIm.getPartner().getId().equals(im.getPartner().getId())){// If the Hashtable still contains the Im objectif (imState.contains(im)){// Remove itimState.remove(im);}m_imOpened.removeElement(im);im.close(0);im.removeImListener(this);break;}}}TranslatorBotThe TranslatorBot class extends the SametimeBot class and overrides thedoTextReceived() method. This method is called when the user sends amessage to the bot, and is indicative of one of four possible events:1. The user is sending the details of the language they are using.2. The user is sending the details of the language in which they wish to receivethe translation.3. The user is sending a word or phrase to be translated.4. The user is requesting to change their language preferences.Each one of these events corresponds to a particular ‘state’ that the user is in.This state is stored in the Hashtable created in the SametimeBot superclass.When the doTextReceived() method is called (Example 3-17 on page 76), theTranslatorBot retrieves the user’s current state from the Hashtable and respondsaccordingly.Chapter 3. Sametime Bots 75

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!