Commits the patch of Sebastien Vincent provided on the dev mailing list in an e-mail with the subject "[Patch] Warnings" which fixes multiple warnings about unnecessary casts, missing or incorrect javadocs.

cusax-fix
Lyubomir Marinov 16 years ago
parent d10540987f
commit dfb0c91c94

@ -106,10 +106,11 @@ public Collection<CallRecord> findByStartDate(Date startDate)
History history = this.getHistory(null, null);
HistoryReader reader = history.getReader();
addHistorySearchProgressListeners(reader, 1);
QueryResultSet rs = reader.findByStartDate(startDate);
QueryResultSet<HistoryRecord> rs
= reader.findByStartDate(startDate);
while (rs.hasNext())
{
HistoryRecord hr = (HistoryRecord) rs.next();
HistoryRecord hr = rs.next();
result.add(convertHistoryRecordToCallRecord(hr));
}
removeHistorySearchProgressListeners(reader);
@ -154,10 +155,10 @@ public Collection<CallRecord> findByEndDate(Date endDate) throws RuntimeExceptio
History history = this.getHistory(null, null);
HistoryReader reader = history.getReader();
addHistorySearchProgressListeners(reader, 1);
QueryResultSet rs = reader.findByEndDate(endDate);
QueryResultSet<HistoryRecord> rs = reader.findByEndDate(endDate);
while (rs.hasNext())
{
HistoryRecord hr = (HistoryRecord) rs.next();
HistoryRecord hr = rs.next();
result.add(convertHistoryRecordToCallRecord(hr));
}
removeHistorySearchProgressListeners(reader);
@ -204,10 +205,11 @@ public Collection<CallRecord> findByPeriod(Date startDate, Date endDate) throws
History history = this.getHistory(null, null);
HistoryReader reader = history.getReader();
addHistorySearchProgressListeners(reader, 1);
QueryResultSet rs = reader.findByPeriod(startDate, endDate);
QueryResultSet<HistoryRecord> rs
= reader.findByPeriod(startDate, endDate);
while (rs.hasNext())
{
HistoryRecord hr = (HistoryRecord) rs.next();
HistoryRecord hr = rs.next();
result.add(convertHistoryRecordToCallRecord(hr));
}
removeHistorySearchProgressListeners(reader);
@ -250,10 +252,11 @@ public Collection<CallRecord> findLast(int count) throws RuntimeException
{
// the default ones
History history = this.getHistory(null, null);
QueryResultSet rs = history.getReader().findLast(count);
QueryResultSet<HistoryRecord> rs
= history.getReader().findLast(count);
while (rs.hasNext())
{
HistoryRecord hr = (HistoryRecord) rs.next();
HistoryRecord hr = rs.next();
result.add(convertHistoryRecordToCallRecord(hr));
}
}
@ -281,11 +284,11 @@ public Collection<CallRecord> findByPeer(String address)
History history = this.getHistory(null, null);
HistoryReader reader = history.getReader();
addHistorySearchProgressListeners(reader, 1);
QueryResultSet rs =
reader.findByKeyword(address, "callParticipantIDs");
QueryResultSet<HistoryRecord> rs
= reader.findByKeyword(address, "callParticipantIDs");
while (rs.hasNext())
{
HistoryRecord hr = (HistoryRecord) rs.next();
HistoryRecord hr = rs.next();
result.add(convertHistoryRecordToCallRecord(hr));
}
removeHistorySearchProgressListeners(reader);
@ -679,9 +682,8 @@ private void handleProviderAdded(ProtocolProviderService provider)
logger.debug("Adding protocol provider " + provider.getProtocolName());
// check whether the provider has a basic telephony operation set
OperationSetBasicTelephony opSetTelephony =
(OperationSetBasicTelephony) provider
.getOperationSet(OperationSetBasicTelephony.class);
OperationSetBasicTelephony opSetTelephony
= provider.getOperationSet(OperationSetBasicTelephony.class);
if (opSetTelephony != null)
{
@ -701,9 +703,8 @@ private void handleProviderAdded(ProtocolProviderService provider)
*/
private void handleProviderRemoved(ProtocolProviderService provider)
{
OperationSetBasicTelephony opSetTelephony =
(OperationSetBasicTelephony) provider
.getOperationSet(OperationSetBasicTelephony.class);
OperationSetBasicTelephony opSetTelephony
= provider.getOperationSet(OperationSetBasicTelephony.class);
if (opSetTelephony != null)
{

@ -210,9 +210,8 @@ public void stop(BundleContext bc)
//stop listening to all currently installed providers
for (ProtocolProviderService pp : currentlyInstalledProviders.values())
{
OperationSetPersistentPresence opSetPersPresence
= (OperationSetPersistentPresence)pp
.getOperationSet(OperationSetPersistentPresence.class);
OperationSetPersistentPresence opSetPersPresence =
pp.getOperationSet(OperationSetPersistentPresence.class);
if(opSetPersPresence !=null)
{
@ -226,8 +225,8 @@ public void stop(BundleContext bc)
else
{
//check if a non persistent presence operation set exists.
OperationSetPresence opSetPresence = (OperationSetPresence)pp
.getOperationSet(OperationSetPresence.class);
OperationSetPresence opSetPresence =
pp.getOperationSet(OperationSetPresence.class);
if(opSetPresence != null)
{
@ -357,8 +356,7 @@ private void addNewContactToMetaContact( ProtocolProviderService provider,
throws MetaContactListException
{
OperationSetPersistentPresence opSetPersPresence =
(OperationSetPersistentPresence) provider
.getOperationSet(OperationSetPersistentPresence.class);
provider.getOperationSet(OperationSetPersistentPresence.class);
if (opSetPersPresence == null)
{
/** @todo handle non-persistent presence operation sets as well */
@ -507,8 +505,7 @@ private ContactGroup resolveProtoPath(ProtocolProviderService protoProvider,
}
OperationSetPersistentPresence opSetPersPresence =
(OperationSetPersistentPresence) protoProvider
.getOperationSet(OperationSetPersistentPresence.class);
protoProvider.getOperationSet(OperationSetPersistentPresence.class);
//if persistent presence is not supported - just bail
//we should have verified this earlier anyway
@ -884,9 +881,10 @@ public void moveContact(Contact contact,
currentParentMetaContact.removeProtoContact(contact);
//get a persistent presence operation set
OperationSetPersistentPresence opSetPresence =
(OperationSetPersistentPresence) contact.getProtocolProvider()
.getOperationSet(OperationSetPersistentPresence.class);
OperationSetPersistentPresence opSetPresence
= contact
.getProtocolProvider()
.getOperationSet(OperationSetPersistentPresence.class);
if (opSetPresence == null)
{
@ -985,10 +983,11 @@ public void moveMetaContact(MetaContact metaContact,
.getProtocolProvider(), (MetaContactGroupImpl) newMetaGroup);
//get a persistent or non persistent presence operation set
OperationSetPersistentPresence opSetPresence =
(OperationSetPersistentPresence) protoContact
.getProtocolProvider().getOperationSet(
OperationSetPersistentPresence.class);
OperationSetPersistentPresence opSetPresence
= protoContact
.getProtocolProvider()
.getOperationSet(
OperationSetPersistentPresence.class);
if (opSetPresence == null)
{
@ -1034,9 +1033,10 @@ public void removeContact(Contact contact) throws MetaContactListException
//updating and/or removing the corresponding meta contact would happen
//once a confirmation event is received from the underlying protocol
//provider
OperationSetPresence opSetPresence =
(OperationSetPresence) contact.getProtocolProvider()
.getOperationSet(OperationSetPresence.class);
OperationSetPresence opSetPresence
= contact
.getProtocolProvider()
.getOperationSet(OperationSetPresence.class);
//in case the provider only has a persistent operation set:
if (opSetPresence == null)
@ -1139,10 +1139,11 @@ public void removeMetaContactGroup(
{
ContactGroup protoGroup = protoGroups.next();
OperationSetPersistentPresence opSetPersPresence =
(OperationSetPersistentPresence) protoGroup
.getProtocolProvider().getOperationSet(
OperationSetPersistentPresence.class);
OperationSetPersistentPresence opSetPersPresence
= protoGroup
.getProtocolProvider()
.getOperationSet(
OperationSetPersistentPresence.class);
if (opSetPersPresence == null)
{
@ -1614,8 +1615,7 @@ private synchronized void handleProviderAdded(
// check whether the provider has a persistent presence op set
OperationSetPersistentPresence opSetPersPresence =
(OperationSetPersistentPresence) provider
.getOperationSet(OperationSetPersistentPresence.class);
provider.getOperationSet(OperationSetPersistentPresence.class);
this.currentlyInstalledProviders.put(
provider.getAccountID().getAccountUniqueID(),
@ -1673,9 +1673,8 @@ private void handleProviderRemoved(
remove(provider.getAccountID().getAccountUniqueID());
//get the root group for the provider so that we could remove it.
OperationSetPersistentPresence persPresOpSet
= (OperationSetPersistentPresence)provider
.getOperationSet(OperationSetPersistentPresence.class);
OperationSetPersistentPresence persPresOpSet =
provider.getOperationSet(OperationSetPersistentPresence.class);
//ignore if persistent presence is not supported.
if(persPresOpSet == null)
@ -2708,8 +2707,8 @@ ContactGroup loadStoredContactGroup(MetaContactGroupImpl containingMetaGroup,
//get the presence op set
ProtocolProviderService sourceProvider =
currentlyInstalledProviders.get(accountID);
OperationSetPersistentPresence presenceOpSet =
(OperationSetPersistentPresence) sourceProvider
OperationSetPersistentPresence presenceOpSet
= sourceProvider
.getOperationSet(OperationSetPersistentPresence.class);
ContactGroup newProtoGroup = presenceOpSet.createUnresolvedContactGroup(
@ -2758,8 +2757,8 @@ void loadStoredMetaContact(
//mc
ProtocolProviderService sourceProvider =
currentlyInstalledProviders.get(accountID);
OperationSetPersistentPresence presenceOpSet =
(OperationSetPersistentPresence) sourceProvider
OperationSetPersistentPresence presenceOpSet
= sourceProvider
.getOperationSet(OperationSetPersistentPresence.class);
for (MclStorageManager.StoredProtoContactDescriptor contactDescriptor

@ -387,8 +387,8 @@ public void addProtocolSupportedOperationSets(
}
// Obtain the ad-hoc multi user chat operation set.
OperationSetAdHocMultiUserChat adHocMultiChatOpSet =
(OperationSetAdHocMultiUserChat) protocolProvider
OperationSetAdHocMultiUserChat adHocMultiChatOpSet
= protocolProvider
.getOperationSet(OperationSetAdHocMultiUserChat.class);
if (adHocMultiChatOpSet != null)
@ -403,13 +403,11 @@ public void addProtocolSupportedOperationSets(
// Obtain file transfer operation set.
OperationSetFileTransfer fileTransferOpSet
= (OperationSetFileTransfer) protocolProvider
.getOperationSet(OperationSetFileTransfer.class);
= protocolProvider.getOperationSet(OperationSetFileTransfer.class);
if (fileTransferOpSet != null)
{
fileTransferOpSet.addFileTransferListener(
getContactListPanel());
fileTransferOpSet.addFileTransferListener(getContactListPanel());
}
}

@ -82,18 +82,15 @@ public void addAccount(ProtocolProviderService pps)
}
else
{
OperationSetPresence presence =
(OperationSetPresence) pps
.getOperationSet(OperationSetPresence.class);
OperationSetPresence selectedPresence =
(OperationSetPresence) selectedProvider
.getOperationSet(OperationSetPresence.class);
OperationSetPresence presence
= pps.getOperationSet(OperationSetPresence.class);
OperationSetPresence selectedPresence
= selectedProvider.getOperationSet(OperationSetPresence.class);
if (presence != null
&& selectedPresence != null
&& (selectedPresence.getPresenceStatus().getStatus() < presence
.getPresenceStatus().getStatus()))
&& (selectedPresence.getPresenceStatus().getStatus()
< presence.getPresenceStatus().getStatus()))
{
setSelected(pps);
}

@ -260,7 +260,7 @@ public CreateCallThread(ProtocolProviderService protocolProvider,
public void run()
{
OperationSetBasicTelephony telephonyOpSet
= (OperationSetBasicTelephony) protocolProvider
= protocolProvider
.getOperationSet(OperationSetBasicTelephony.class);
/*
@ -326,8 +326,7 @@ public void run()
{
CallPeer peer = peers.next();
OperationSetBasicTelephony telephony =
(OperationSetBasicTelephony) pps
.getOperationSet(OperationSetBasicTelephony.class);
pps.getOperationSet(OperationSetBasicTelephony.class);
try
{
@ -363,8 +362,7 @@ public CreateConferenceCallThread(
public void run()
{
OperationSetTelephonyConferencing confOpSet
= (OperationSetTelephonyConferencing) protocolProvider
.getOperationSet(OperationSetTelephonyConferencing.class);
= protocolProvider.getOperationSet(OperationSetTelephonyConferencing.class);
/*
* XXX If we are here and we just discover that

@ -419,16 +419,13 @@ private void sendDtmfTone(DTMFTone dtmfTone)
while (callPeers.hasNext())
{
CallPeer peer = callPeers.next();
if (peer.getProtocolProvider()
.getOperationSet(OperationSetDTMF.class) != null)
{
OperationSetDTMF dtmfOpSet
= (OperationSetDTMF) peer.getProtocolProvider()
OperationSetDTMF dtmfOpSet
= peer
.getProtocolProvider()
.getOperationSet(OperationSetDTMF.class);
if (dtmfOpSet != null)
dtmfOpSet.sendDTMF(peer, dtmfTone);
}
}
}
catch (NullPointerException e1)

@ -122,7 +122,7 @@ public void actionPerformed(ActionEvent evt)
if (call != null)
{
OperationSetBasicTelephony telephony =
(OperationSetBasicTelephony) call.getProtocolProvider()
call.getProtocolProvider()
.getOperationSet(OperationSetBasicTelephony.class);
Iterator<? extends CallPeer> peers = call.getCallPeers();

@ -1,117 +1,117 @@
/*
* SIP Communicator, the OpenSource Java VoIP and Instant Messaging client.
*
* Distributable under LGPL license.
* See terms of license at gnu.org.
*/
package net.java.sip.communicator.impl.gui.main.call;
import java.awt.event.*;
import net.java.sip.communicator.impl.gui.*;
import net.java.sip.communicator.impl.gui.utils.*;
import net.java.sip.communicator.service.protocol.*;
import net.java.sip.communicator.util.*;
import net.java.sip.communicator.util.swing.*;
/**
* @author Lubomir Marinov
*/
public class LocalVideoButton
extends SIPCommToggleButton
{
private static final Logger logger
= Logger.getLogger(LocalVideoButton.class);
private static final long serialVersionUID = 0L;
/**
* Creates a <tt>LocalVideoButton</tt> by specifying the corresponding
* <tt>call</tt>.
* @param call the corresponding to this button call
*/
public LocalVideoButton(Call call)
{
setBgImage(ImageLoader.getImage(ImageLoader.CALL_SETTING_BUTTON_BG));
setBgRolloverImage(
ImageLoader.getImage(ImageLoader.CALL_SETTING_BUTTON_BG));
setIconImage(ImageLoader.getImage(ImageLoader.LOCAL_VIDEO_BUTTON));
setPressedImage(
ImageLoader.getImage(ImageLoader.CALL_SETTING_BUTTON_PRESSED_BG));
setModel(new LocalVideoButtonModel(call));
setToolTipText(GuiActivator.getResources().getI18NString(
"service.gui.LOCAL_VIDEO_BUTTON_TOOL_TIP"));
}
private static class LocalVideoButtonModel
extends ToggleButtonModel
implements ActionListener,
Runnable
{
private final Call call;
private Thread runner;
public LocalVideoButtonModel(Call call)
{
this.call = call;
addActionListener(this);
}
public synchronized void actionPerformed(ActionEvent event)
{
if (runner == null)
{
runner = new Thread(this, LocalVideoButton.class.getName());
runner.setDaemon(true);
setEnabled(false);
runner.start();
}
}
public void run()
{
try
{
doRun();
}
finally
{
synchronized (this)
{
if (Thread.currentThread().equals(runner))
{
runner = null;
setEnabled(true);
}
}
}
}
private void doRun()
{
OperationSetVideoTelephony telephony = (OperationSetVideoTelephony)
call.getProtocolProvider()
.getOperationSet(OperationSetVideoTelephony.class);
if (telephony != null)
{
try
{
telephony.setLocalVideoAllowed(
call,
!telephony.isLocalVideoAllowed(call));
}
catch (OperationFailedException ex)
{
logger.error(
"Failed to toggle the streaming of local video.",
ex);
}
}
}
}
}
/*
* SIP Communicator, the OpenSource Java VoIP and Instant Messaging client.
*
* Distributable under LGPL license.
* See terms of license at gnu.org.
*/
package net.java.sip.communicator.impl.gui.main.call;
import java.awt.event.*;
import net.java.sip.communicator.impl.gui.*;
import net.java.sip.communicator.impl.gui.utils.*;
import net.java.sip.communicator.service.protocol.*;
import net.java.sip.communicator.util.*;
import net.java.sip.communicator.util.swing.*;
/**
* @author Lubomir Marinov
*/
public class LocalVideoButton
extends SIPCommToggleButton
{
private static final Logger logger
= Logger.getLogger(LocalVideoButton.class);
private static final long serialVersionUID = 0L;
/**
* Creates a <tt>LocalVideoButton</tt> by specifying the corresponding
* <tt>call</tt>.
* @param call the corresponding to this button call
*/
public LocalVideoButton(Call call)
{
setBgImage(ImageLoader.getImage(ImageLoader.CALL_SETTING_BUTTON_BG));
setBgRolloverImage(
ImageLoader.getImage(ImageLoader.CALL_SETTING_BUTTON_BG));
setIconImage(ImageLoader.getImage(ImageLoader.LOCAL_VIDEO_BUTTON));
setPressedImage(
ImageLoader.getImage(ImageLoader.CALL_SETTING_BUTTON_PRESSED_BG));
setModel(new LocalVideoButtonModel(call));
setToolTipText(GuiActivator.getResources().getI18NString(
"service.gui.LOCAL_VIDEO_BUTTON_TOOL_TIP"));
}
private static class LocalVideoButtonModel
extends ToggleButtonModel
implements ActionListener,
Runnable
{
private final Call call;
private Thread runner;
public LocalVideoButtonModel(Call call)
{
this.call = call;
addActionListener(this);
}
public synchronized void actionPerformed(ActionEvent event)
{
if (runner == null)
{
runner = new Thread(this, LocalVideoButton.class.getName());
runner.setDaemon(true);
setEnabled(false);
runner.start();
}
}
public void run()
{
try
{
doRun();
}
finally
{
synchronized (this)
{
if (Thread.currentThread().equals(runner))
{
runner = null;
setEnabled(true);
}
}
}
}
private void doRun()
{
OperationSetVideoTelephony telephony =
call.getProtocolProvider()
.getOperationSet(OperationSetVideoTelephony.class);
if (telephony != null)
{
try
{
telephony.setLocalVideoAllowed(
call,
!telephony.isLocalVideoAllowed(call));
}
catch (OperationFailedException ex)
{
logger.error(
"Failed to toggle the streaming of local video.",
ex);
}
}
}
}
}

@ -290,7 +290,7 @@ private OperationSetVideoTelephony addVideoListener()
return null;
final OperationSetVideoTelephony telephony =
(OperationSetVideoTelephony) call.getProtocolProvider()
call.getProtocolProvider()
.getOperationSet(OperationSetVideoTelephony.class);
if (telephony == null)
return null;

@ -505,7 +505,7 @@ private void createSecurityPanel(CallPeerSecurityOnEvent event)
if (callPeer != null)
{
OperationSetSecureTelephony secure
= (OperationSetSecureTelephony) callPeer
= callPeer
.getProtocolProvider().getOperationSet(
OperationSetSecureTelephony.class);
@ -548,7 +548,7 @@ protected Component createTransferCallButton()
if (callPeer != null)
{
OperationSetAdvancedTelephony telephony =
(OperationSetAdvancedTelephony) callPeer.getProtocolProvider()
callPeer.getProtocolProvider()
.getOperationSet(OperationSetAdvancedTelephony.class);
if (telephony != null)

@ -53,7 +53,7 @@ public ReceivedCallDialog(Call call)
this.initComponents();
OperationSetBasicTelephony telephonyOpSet
= (OperationSetBasicTelephony) call.getProtocolProvider()
= call.getProtocolProvider()
.getOperationSet(OperationSetBasicTelephony.class);
telephonyOpSet.addCallListener(this);

@ -65,8 +65,9 @@ public void actionPerformed(ActionEvent e)
if (call != null)
{
OperationSetSecureTelephony secure
= (OperationSetSecureTelephony) call
.getProtocolProvider().getOperationSet(
= call
.getProtocolProvider()
.getOperationSet(
OperationSetSecureTelephony.class);
if (secure != null)

@ -89,7 +89,7 @@ private void actionPerformed(ActionListener listener, ActionEvent evt)
if (call != null)
{
OperationSetAdvancedTelephony telephony =
(OperationSetAdvancedTelephony) call.getProtocolProvider()
call.getProtocolProvider()
.getOperationSet(OperationSetAdvancedTelephony.class);
if (telephony != null)
@ -222,7 +222,7 @@ private CallPeer findCallPeer(String address)
{
ProtocolProviderService service = (ProtocolProviderService)
bundleContext.getService(serviceReference);
OperationSetBasicTelephony telephony = (OperationSetBasicTelephony)
OperationSetBasicTelephony telephony =
service.getOperationSet(telephonyClass);
if (telephony != null)

@ -650,8 +650,7 @@ public ChatRoomWrapper createChatRoom(
ChatRoomWrapper chatRoomWrapper = null;
OperationSetMultiUserChat groupChatOpSet
= (OperationSetMultiUserChat) protocolProvider
.getOperationSet(OperationSetMultiUserChat.class);
= protocolProvider.getOperationSet(OperationSetMultiUserChat.class);
// If there's no group chat operation set we have nothing to do here.
if (groupChatOpSet == null)
@ -661,10 +660,9 @@ public ChatRoomWrapper createChatRoom(
try
{
Map<String, Object> members = new Hashtable<String, Object>();
OperationSetPersistentPresence opSet =
(OperationSetPersistentPresence)
protocolProvider.getOperationSet(
OperationSetPersistentPresence.class);
OperationSetPersistentPresence opSet
= protocolProvider
.getOperationSet(OperationSetPersistentPresence.class);
for(String contact : contacts)
{
@ -733,7 +731,7 @@ public AdHocChatRoomWrapper createAdHocChatRoom(
AdHocChatRoomWrapper chatRoomWrapper = null;
OperationSetAdHocMultiUserChat groupChatOpSet
= (OperationSetAdHocMultiUserChat) protocolProvider
= protocolProvider
.getOperationSet(OperationSetAdHocMultiUserChat.class);
// If there's no group chat operation set we have nothing to do here.
@ -746,7 +744,6 @@ public AdHocChatRoomWrapper createAdHocChatRoom(
{
List<Contact> members = new LinkedList<Contact>();
OperationSetPersistentPresence opSet =
(OperationSetPersistentPresence)
protocolProvider.getOperationSet(
OperationSetPersistentPresence.class);
@ -1645,8 +1642,8 @@ private static class FindRoomTask
public ChatRoom doInBackground()
{
OperationSetMultiUserChat groupChatOpSet
= (OperationSetMultiUserChat) chatRoomProvider
.getProtocolProvider().getOperationSet(
= chatRoomProvider
.getProtocolProvider().getOperationSet(
OperationSetMultiUserChat.class);
ChatRoom chatRoom = null;
@ -1687,7 +1684,7 @@ public List<String> doInBackground()
return null;
OperationSetMultiUserChat groupChatOpSet
= (OperationSetMultiUserChat) protocolProvider
= protocolProvider
.getOperationSet(OperationSetMultiUserChat.class);
if (groupChatOpSet == null)

@ -149,11 +149,10 @@ public HistoryWindow(Object historyContact)
Contact protoContact = protoContacts.next();
OperationSetBasicInstantMessaging basicInstantMessaging
= (OperationSetBasicInstantMessaging)
protoContact
.getProtocolProvider()
.getOperationSet(
OperationSetBasicInstantMessaging.class);
= protoContact
.getProtocolProvider()
.getOperationSet(
OperationSetBasicInstantMessaging.class);
if (basicInstantMessaging != null)
{

@ -155,9 +155,8 @@ public void contactClicked(ContactListEvent evt)
= defaultContact.getProtocolProvider();
OperationSetBasicInstantMessaging
defaultIM = (OperationSetBasicInstantMessaging)
defaultProvider.getOperationSet(
OperationSetBasicInstantMessaging.class);
defaultIM = defaultProvider.getOperationSet(
OperationSetBasicInstantMessaging.class);
ProtocolProviderService protoContactProvider;
OperationSetBasicInstantMessaging protoContactIM;
@ -177,9 +176,8 @@ public void contactClicked(ContactListEvent evt)
protoContactProvider = contact.getProtocolProvider();
protoContactIM = (OperationSetBasicInstantMessaging)
protoContactProvider.getOperationSet(
OperationSetBasicInstantMessaging.class);
protoContactIM = protoContactProvider.getOperationSet(
OperationSetBasicInstantMessaging.class);
if(protoContactIM != null
&& protoContactIM.isOfflineMessagingSupported()

@ -46,7 +46,7 @@ public ContactListTransferHandler(DefaultContactList contactList)
* @param t the data to import
* @return <tt>true</tt> if the data was inserted into the component;
* <tt>false</tt>, otherwise
* @see TransferHandler#importData(JComponent. Transferable)
* @see TransferHandler#importData(JComponent, Transferable)
*/
@SuppressWarnings("unchecked") //taken care of
public boolean importData(JComponent comp, Transferable t)

@ -162,10 +162,8 @@ public void registrationStateChanged(RegistrationStateChangeEvent evt)
* to do anything useful can be prevented.
*/
final OperationSetServerStoredAccountInfo accountInfoOpSet
= (OperationSetServerStoredAccountInfo)
protocolProvider
.getOperationSet(
OperationSetServerStoredAccountInfo.class);
= protocolProvider.getOperationSet(
OperationSetServerStoredAccountInfo.class);
if (accountInfoOpSet != null)

@ -68,8 +68,7 @@ public PresenceStatusMenu(ProtocolProviderService protocolProvider)
this.protocolProvider = protocolProvider;
this.presence
= (OperationSetPresence) protocolProvider
.getOperationSet(OperationSetPresence.class);
= protocolProvider.getOperationSet(OperationSetPresence.class);
this.statusIterator = this.presence.getSupportedStatusSet();

@ -1341,8 +1341,7 @@ public static ImageIcon getAccountStatusImage(ProtocolProviderService pps)
ImageIcon statusIcon;
OperationSetPresence presence
= (OperationSetPresence) pps
.getOperationSet(OperationSetPresence.class);
= pps.getOperationSet(OperationSetPresence.class);
Image statusImage;
if (presence != null)

@ -138,7 +138,7 @@ public void mouseClicked(MouseEvent e)
if (e.getClickCount() > 1)
{
Object[] metaContacts
= (Object[]) selectedContactList.getSelectedValues();
= selectedContactList.getSelectedValues();
moveContactsFromRightToLeft(metaContacts);
}
@ -189,8 +189,7 @@ public void mouseClicked(MouseEvent e)
{
public void actionPerformed(ActionEvent e)
{
Object[] metaContacts
= (Object[]) contactList.getSelectedValues();
Object[] metaContacts = contactList.getSelectedValues();
if (metaContacts != null && metaContacts.length > 0)
moveContactsFromLeftToRight(metaContacts);
@ -201,8 +200,7 @@ public void actionPerformed(ActionEvent e)
{
public void actionPerformed(ActionEvent e)
{
Object[] metaContacts
= (Object[]) selectedContactList.getSelectedValues();
Object[] metaContacts = selectedContactList.getSelectedValues();
if (metaContacts != null && metaContacts.length > 0)
moveContactsFromRightToLeft(metaContacts);

@ -484,7 +484,7 @@ public void cleanup()
* The data output stream calls this method to transform outgoing
* packets.
*
* @see PacketTransformer#transform(net.java.sip.communicator.impl.media.transform.RawPacket)
* @see PacketTransformer#transform(RawPacket)
*/
public RawPacket transform(RawPacket pkt)
{
@ -521,7 +521,7 @@ public RawPacket transform(RawPacket pkt)
* The input data stream calls this method to transform
* incoming packets.
*
* @see PacketTransformer#reverseTransform(net.java.sip.communicator.impl.media.transform.RawPacket)
* @see PacketTransformer#reverseTransform(RawPacket)
*/
public RawPacket reverseTransform(RawPacket pkt)
{

@ -1064,8 +1064,7 @@ private void handleProviderAdded(ProtocolProviderService provider)
// check whether the provider has a basic im operation set
OperationSetBasicInstantMessaging opSetIm =
(OperationSetBasicInstantMessaging) provider
.getOperationSet(OperationSetBasicInstantMessaging.class);
provider.getOperationSet(OperationSetBasicInstantMessaging.class);
if (opSetIm != null)
{
@ -1077,8 +1076,7 @@ private void handleProviderAdded(ProtocolProviderService provider)
}
OperationSetMultiUserChat opSetMultiUChat =
(OperationSetMultiUserChat) provider
.getOperationSet(OperationSetMultiUserChat.class);
provider.getOperationSet(OperationSetMultiUserChat.class);
if (opSetMultiUChat != null)
{
@ -1108,8 +1106,7 @@ private void handleProviderAdded(ProtocolProviderService provider)
private void handleProviderRemoved(ProtocolProviderService provider)
{
OperationSetBasicInstantMessaging opSetIm =
(OperationSetBasicInstantMessaging) provider
.getOperationSet(OperationSetBasicInstantMessaging.class);
provider.getOperationSet(OperationSetBasicInstantMessaging.class);
if (opSetIm != null)
{
@ -1117,8 +1114,7 @@ private void handleProviderRemoved(ProtocolProviderService provider)
}
OperationSetMultiUserChat opSetMultiUChat =
(OperationSetMultiUserChat) provider
.getOperationSet(OperationSetMultiUserChat.class);
provider.getOperationSet(OperationSetMultiUserChat.class);
if (opSetMultiUChat != null)
{

@ -93,8 +93,8 @@ public Object getMenu()
private void addAccount(ProtocolProviderService protocolProvider)
{
OperationSetPresence presence
= (OperationSetPresence)
protocolProvider.getOperationSet(OperationSetPresence.class);
= protocolProvider.getOperationSet(OperationSetPresence.class);
boolean swing = (menu instanceof JComponent);
if (presence == null)
@ -157,8 +157,8 @@ private void removeAccount(ProtocolProviderService protocolProvider)
* addAccount(ProtocolProviderService).
*/
OperationSetPresence presence
= (OperationSetPresence)
protocolProvider.getOperationSet(OperationSetPresence.class);
= protocolProvider.getOperationSet(OperationSetPresence.class);
if (presence != null)
presence.removeProviderPresenceStatusListener(this);
else

@ -1,416 +1,416 @@
/*
* SIP Communicator, the OpenSource Java VoIP and Instant Messaging client.
*
* Distributable under LGPL license.
* See terms of license at gnu.org.
*/
package net.java.sip.communicator.impl.protocol;
import java.util.*;
import org.osgi.framework.*;
import net.java.sip.communicator.service.protocol.*;
import net.java.sip.communicator.service.protocol.event.*;
import net.java.sip.communicator.util.*;
/**
* Imposes the policy to have one call in progress i.e. to put existing calls on
* hold when a new call enters in progress.
*
* @author Lubomir Marinov
*/
public class SingleCallInProgressPolicy
{
/**
* The name of the configuration property which specifies whether
* <code>SingleCallInProgressPolicy</code> is enabled i.e. whether it should
* put existing calls on hold when a new call enters in progress.
*/
private static final String PNAME_SINGLE_CALL_IN_PROGRESS_POLICY_ENABLED
= "net.java.sip.communicator.impl.protocol.SingleCallInProgressPolicy.enabled";
/**
* Implements the listeners interfaces used by this policy.
*/
private class SingleCallInProgressPolicyListener
implements CallChangeListener,
CallListener,
ServiceListener
{
/**
* Stops tracking the state of a specific <code>Call</code> and no
* longer tries to put it on hold when it ends.
*
* @see CallListener#callEnded(CallEvent)
*/
public void callEnded(CallEvent callEvent)
{
SingleCallInProgressPolicy.this.handleCallEvent(
CallEvent.CALL_ENDED, callEvent);
}
/**
* Does nothing because adding <code>CallPeer<code>s to
* <code>Call</code>s isn't related to the policy to put existing calls
* on hold when a new call becomes in-progress and just implements
* <code>CallChangeListener</code>.
*
* @see CallChangeListener#callPeerAdded(CallPeerEvent)
*/
public void callPeerAdded( CallPeerEvent callPeerEvent)
{
/*
* Not of interest, just implementing CallChangeListener in which
* only #callStateChanged(CallChangeEvent) is of interest.
*/
}
/**
* Does nothing because removing <code>CallPeer<code>s to
* <code>Call</code>s isn't related to the policy to put existing calls
* on hold when a new call becomes in-progress and just implements
* <code>CallChangeListener</code>.
*
* @see CallChangeListener#callPeerRemoved(CallPeerEvent)
*/
public void callPeerRemoved( CallPeerEvent callPeerEvent)
{
/*
* Not of interest, just implementing CallChangeListener in which
* only #callStateChanged(CallChangeEvent) is of interest.
*/
}
/**
* Upon a <code>Call</code> changing its state to
* <code>CallState.CALL_IN_PROGRESS</code>, puts the other existing
* <code>Call</code>s on hold.
*
* @param callChangeEvent the <tt>CallChangeEvent</tt> that we are to
* deliver.
*
* @see CallChangeListener#callStateChanged(CallChangeEvent)
*/
public void callStateChanged(CallChangeEvent callChangeEvent)
{
SingleCallInProgressPolicy.this.callStateChanged(callChangeEvent);
}
/**
* Remembers an incoming <code>Call</code> so that it can put the other
* existing <code>Call</code>s on hold when it changes its state to
* <code>CallState.CALL_IN_PROGRESS</code>.
*
* @see CallListener#incomingCallReceived(CallEvent)
*/
public void incomingCallReceived(CallEvent callEvent)
{
SingleCallInProgressPolicy.this.handleCallEvent(
CallEvent.CALL_RECEIVED, callEvent);
}
/**
* Remembers an outgoing <code>Call</code> so that it can put the other
* existing <code>Call</code>s on hold when it changes its state to
* <code>CallState.CALL_IN_PROGRESS</code>.
*
* @see CallListener#outgoingCallCreated(CallEvent)
*/
public void outgoingCallCreated(CallEvent callEvent)
{
SingleCallInProgressPolicy.this.handleCallEvent(
CallEvent.CALL_INITIATED, callEvent);
}
/**
* Starts/stops tracking the new <code>Call</code>s originating from a
* specific <code>ProtocolProviderService</code> when it
* registers/unregisters in order to take them into account when putting
* existing calls on hold upon a new call entering its in-progress
* state.
*
* @param serviceEvent
* the <code>ServiceEvent</code> event describing a change in
* the state of a service registration which may be a
* <code>ProtocolProviderService</code> supporting
* <code>OperationSetBasicTelephony</code> and thus being
* able to create new <code>Call</code>s
*/
public void serviceChanged(ServiceEvent serviceEvent)
{
SingleCallInProgressPolicy.this.serviceChanged(serviceEvent);
}
}
/**
* Our class logger
*/
private static final Logger logger =
Logger.getLogger(SingleCallInProgressPolicy.class);
/**
* The <code>BundleContext</code> to the Calls of which this policy applies.
*/
private final BundleContext bundleContext;
/**
* The <code>Call</code>s this policy manages i.e. put on hold when one of
* them enters in progress.
*/
private final List<Call> calls = new ArrayList<Call>();
/**
* The listener utilized by this policy to discover new <code>Call</code>
* and track their in-progress state.
*/
private final SingleCallInProgressPolicyListener listener =
new SingleCallInProgressPolicyListener();
/**
* Initializes a new <code>SingleCallInProgressPolicy</code> instance which
* will apply to the <code>Call</code>s of a specific
* <code>BundleContext</code>.
*
* @param bundleContext
* the <code>BundleContext</code> to the
* <code>Call<code>s of which the new policy should apply
*/
public SingleCallInProgressPolicy(BundleContext bundleContext)
{
this.bundleContext = bundleContext;
this.bundleContext.addServiceListener(listener);
}
/**
* Registers a specific <code>Call</code> with this policy in order to have
* the rules of the latter apply to the former.
*
* @param call
* the <code>Call</code> to register with this policy in order to
* have the rules of the latter apply to the former
*/
private void addCallListener(Call call)
{
synchronized (calls)
{
if (!calls.contains(call))
{
CallState callState = call.getCallState();
if ((callState != null)
&& !callState.equals(CallState.CALL_ENDED))
{
calls.add(call);
}
}
}
call.addCallChangeListener(listener);
}
/**
* Registers a specific <code>OperationSetBasicTelephony</code> with this
* policy in order to have the rules of the latter apply to the
* <code>Call</code>s created by the former.
*
* @param telephony
* the <code>OperationSetBasicTelephony</code> to register with
* this policy in order to have the rules of the latter apply to
* the <code>Call</code>s created by the former
*/
private void addOperationSetBasicTelephonyListener(
OperationSetBasicTelephony telephony)
{
telephony.addCallListener(listener);
}
/**
* Handles changes in the state of a <code>Call</code> this policy applies
* to in order to detect when new calls become in-progress and when the
* other calls should be put on hold.
*
* @param callChangeEvent
* a <code>CallChangeEvent</code> value which describes the
* <code>Call</code> and the change in its state
*/
private void callStateChanged(CallChangeEvent callChangeEvent)
{
Call call = callChangeEvent.getSourceCall();
if (CallState.CALL_INITIALIZATION.equals(callChangeEvent.getOldValue())
&& CallState.CALL_IN_PROGRESS.equals(call.getCallState())
&& ProtocolProviderActivator
.getConfigurationService()
.getBoolean(
PNAME_SINGLE_CALL_IN_PROGRESS_POLICY_ENABLED,
true))
{
synchronized (calls)
{
for (Call otherCall : calls)
if (!call.equals(otherCall)
&& CallState.CALL_IN_PROGRESS
.equals(otherCall.getCallState()))
putOnHold(otherCall);
}
}
}
/**
* Performs end-of-life cleanup associated with this instance e.g. removes
* added listeners.
*/
public void dispose()
{
bundleContext.removeServiceListener(listener);
}
/**
* Handles the start and end of the <code>Call</code>s this policy applies
* to in order to have them or stop having them put the other existing calls
* on hold when the former change their states to
* <code>CallState.CALL_IN_PROGRESS</code>.
*
* @param type
* one of {@link CallEvent#CALL_ENDED},
* {@link CallEvent#CALL_INITIATED} and
* {@link CallEvent#CALL_RECEIVED} which described the type of
* the event to be handled
* @param callEvent
* a <code>CallEvent</code> value which describes the change and
* the <code>Call</code> associated with it
*/
private void handleCallEvent(int type, CallEvent callEvent)
{
Call call = callEvent.getSourceCall();
switch (type)
{
case CallEvent.CALL_ENDED:
removeCallListener(call);
break;
case CallEvent.CALL_INITIATED:
case CallEvent.CALL_RECEIVED:
addCallListener(call);
break;
}
}
/**
* Puts the <code>CallPeer</code>s of a specific <code>Call</code> on
* hold.
*
* @param call
* the <code>Call</code> the <code>CallPeer</code>s of
* which are to be put on hold
*/
private void putOnHold(Call call)
{
OperationSetBasicTelephony telephony =
(OperationSetBasicTelephony) call.getProtocolProvider()
.getOperationSet(OperationSetBasicTelephony.class);
if (telephony != null)
{
for (Iterator<? extends CallPeer> peerIter =
call.getCallPeers(); peerIter.hasNext();)
{
CallPeer peer = peerIter.next();
CallPeerState peerState = peer.getState();
if (!CallPeerState.DISCONNECTED.equals(peerState)
&& !CallPeerState.FAILED.equals(peerState)
&& !CallPeerState.isOnHold(peerState))
{
try
{
telephony.putOnHold(peer);
}
catch (OperationFailedException ex)
{
logger.error("Failed to put " + peer
+ " on hold.", ex);
}
}
}
}
}
/**
* Unregisters a specific <code>Call</code> from this policy in order to
* have the rules of the latter no longer applied to the former.
*
* @param call
* the <code>Call</code> to unregister from this policy in order
* to have the rules of the latter no longer apply to the former
*/
private void removeCallListener(Call call)
{
call.removeCallChangeListener(listener);
synchronized (calls)
{
calls.remove(call);
}
}
/**
* Unregisters a specific <code>OperationSetBasicTelephony</code> from this
* policy in order to have the rules of the latter no longer apply to the
* <code>Call</code>s created by the former.
*
* @param telephony
* the <code>OperationSetBasicTelephony</code> to unregister from
* this policy in order to have the rules of the latter apply to
* the <code>Call</code>s created by the former
*/
private void removeOperationSetBasicTelephonyListener(
OperationSetBasicTelephony telephony)
{
telephony.removeCallListener(listener);
}
/**
* Handles the registering and unregistering of
* <code>OperationSetBasicTelephony</code> instances in order to apply or
* unapply the rules of this policy to the <code>Call</code>s originating
* from them.
*
* @param serviceEvent
* a <code>ServiceEvent</code> value which described a change in
* a OSGi service and which is to be examined for the registering
* or unregistering of a <code>ProtocolProviderService</code> and
* thus a <code>OperationSetBasicTelephony</code>
*/
private void serviceChanged(ServiceEvent serviceEvent)
{
Object service =
bundleContext.getService(serviceEvent.getServiceReference());
if (service instanceof ProtocolProviderService)
{
OperationSetBasicTelephony telephony =
(OperationSetBasicTelephony) ((ProtocolProviderService) service)
.getOperationSet(OperationSetBasicTelephony.class);
if (telephony != null)
{
switch (serviceEvent.getType())
{
case ServiceEvent.REGISTERED:
addOperationSetBasicTelephonyListener(telephony);
break;
case ServiceEvent.UNREGISTERING:
removeOperationSetBasicTelephonyListener(telephony);
break;
}
}
}
}
}
/*
* SIP Communicator, the OpenSource Java VoIP and Instant Messaging client.
*
* Distributable under LGPL license.
* See terms of license at gnu.org.
*/
package net.java.sip.communicator.impl.protocol;
import java.util.*;
import org.osgi.framework.*;
import net.java.sip.communicator.service.protocol.*;
import net.java.sip.communicator.service.protocol.event.*;
import net.java.sip.communicator.util.*;
/**
* Imposes the policy to have one call in progress i.e. to put existing calls on
* hold when a new call enters in progress.
*
* @author Lubomir Marinov
*/
public class SingleCallInProgressPolicy
{
/**
* The name of the configuration property which specifies whether
* <code>SingleCallInProgressPolicy</code> is enabled i.e. whether it should
* put existing calls on hold when a new call enters in progress.
*/
private static final String PNAME_SINGLE_CALL_IN_PROGRESS_POLICY_ENABLED
= "net.java.sip.communicator.impl.protocol.SingleCallInProgressPolicy.enabled";
/**
* Implements the listeners interfaces used by this policy.
*/
private class SingleCallInProgressPolicyListener
implements CallChangeListener,
CallListener,
ServiceListener
{
/**
* Stops tracking the state of a specific <code>Call</code> and no
* longer tries to put it on hold when it ends.
*
* @see CallListener#callEnded(CallEvent)
*/
public void callEnded(CallEvent callEvent)
{
SingleCallInProgressPolicy.this.handleCallEvent(
CallEvent.CALL_ENDED, callEvent);
}
/**
* Does nothing because adding <code>CallPeer<code>s to
* <code>Call</code>s isn't related to the policy to put existing calls
* on hold when a new call becomes in-progress and just implements
* <code>CallChangeListener</code>.
*
* @see CallChangeListener#callPeerAdded(CallPeerEvent)
*/
public void callPeerAdded( CallPeerEvent callPeerEvent)
{
/*
* Not of interest, just implementing CallChangeListener in which
* only #callStateChanged(CallChangeEvent) is of interest.
*/
}
/**
* Does nothing because removing <code>CallPeer<code>s to
* <code>Call</code>s isn't related to the policy to put existing calls
* on hold when a new call becomes in-progress and just implements
* <code>CallChangeListener</code>.
*
* @see CallChangeListener#callPeerRemoved(CallPeerEvent)
*/
public void callPeerRemoved( CallPeerEvent callPeerEvent)
{
/*
* Not of interest, just implementing CallChangeListener in which
* only #callStateChanged(CallChangeEvent) is of interest.
*/
}
/**
* Upon a <code>Call</code> changing its state to
* <code>CallState.CALL_IN_PROGRESS</code>, puts the other existing
* <code>Call</code>s on hold.
*
* @param callChangeEvent the <tt>CallChangeEvent</tt> that we are to
* deliver.
*
* @see CallChangeListener#callStateChanged(CallChangeEvent)
*/
public void callStateChanged(CallChangeEvent callChangeEvent)
{
SingleCallInProgressPolicy.this.callStateChanged(callChangeEvent);
}
/**
* Remembers an incoming <code>Call</code> so that it can put the other
* existing <code>Call</code>s on hold when it changes its state to
* <code>CallState.CALL_IN_PROGRESS</code>.
*
* @see CallListener#incomingCallReceived(CallEvent)
*/
public void incomingCallReceived(CallEvent callEvent)
{
SingleCallInProgressPolicy.this.handleCallEvent(
CallEvent.CALL_RECEIVED, callEvent);
}
/**
* Remembers an outgoing <code>Call</code> so that it can put the other
* existing <code>Call</code>s on hold when it changes its state to
* <code>CallState.CALL_IN_PROGRESS</code>.
*
* @see CallListener#outgoingCallCreated(CallEvent)
*/
public void outgoingCallCreated(CallEvent callEvent)
{
SingleCallInProgressPolicy.this.handleCallEvent(
CallEvent.CALL_INITIATED, callEvent);
}
/**
* Starts/stops tracking the new <code>Call</code>s originating from a
* specific <code>ProtocolProviderService</code> when it
* registers/unregisters in order to take them into account when putting
* existing calls on hold upon a new call entering its in-progress
* state.
*
* @param serviceEvent
* the <code>ServiceEvent</code> event describing a change in
* the state of a service registration which may be a
* <code>ProtocolProviderService</code> supporting
* <code>OperationSetBasicTelephony</code> and thus being
* able to create new <code>Call</code>s
*/
public void serviceChanged(ServiceEvent serviceEvent)
{
SingleCallInProgressPolicy.this.serviceChanged(serviceEvent);
}
}
/**
* Our class logger
*/
private static final Logger logger =
Logger.getLogger(SingleCallInProgressPolicy.class);
/**
* The <code>BundleContext</code> to the Calls of which this policy applies.
*/
private final BundleContext bundleContext;
/**
* The <code>Call</code>s this policy manages i.e. put on hold when one of
* them enters in progress.
*/
private final List<Call> calls = new ArrayList<Call>();
/**
* The listener utilized by this policy to discover new <code>Call</code>
* and track their in-progress state.
*/
private final SingleCallInProgressPolicyListener listener =
new SingleCallInProgressPolicyListener();
/**
* Initializes a new <code>SingleCallInProgressPolicy</code> instance which
* will apply to the <code>Call</code>s of a specific
* <code>BundleContext</code>.
*
* @param bundleContext
* the <code>BundleContext</code> to the
* <code>Call<code>s of which the new policy should apply
*/
public SingleCallInProgressPolicy(BundleContext bundleContext)
{
this.bundleContext = bundleContext;
this.bundleContext.addServiceListener(listener);
}
/**
* Registers a specific <code>Call</code> with this policy in order to have
* the rules of the latter apply to the former.
*
* @param call
* the <code>Call</code> to register with this policy in order to
* have the rules of the latter apply to the former
*/
private void addCallListener(Call call)
{
synchronized (calls)
{
if (!calls.contains(call))
{
CallState callState = call.getCallState();
if ((callState != null)
&& !callState.equals(CallState.CALL_ENDED))
{
calls.add(call);
}
}
}
call.addCallChangeListener(listener);
}
/**
* Registers a specific <code>OperationSetBasicTelephony</code> with this
* policy in order to have the rules of the latter apply to the
* <code>Call</code>s created by the former.
*
* @param telephony
* the <code>OperationSetBasicTelephony</code> to register with
* this policy in order to have the rules of the latter apply to
* the <code>Call</code>s created by the former
*/
private void addOperationSetBasicTelephonyListener(
OperationSetBasicTelephony telephony)
{
telephony.addCallListener(listener);
}
/**
* Handles changes in the state of a <code>Call</code> this policy applies
* to in order to detect when new calls become in-progress and when the
* other calls should be put on hold.
*
* @param callChangeEvent
* a <code>CallChangeEvent</code> value which describes the
* <code>Call</code> and the change in its state
*/
private void callStateChanged(CallChangeEvent callChangeEvent)
{
Call call = callChangeEvent.getSourceCall();
if (CallState.CALL_INITIALIZATION.equals(callChangeEvent.getOldValue())
&& CallState.CALL_IN_PROGRESS.equals(call.getCallState())
&& ProtocolProviderActivator
.getConfigurationService()
.getBoolean(
PNAME_SINGLE_CALL_IN_PROGRESS_POLICY_ENABLED,
true))
{
synchronized (calls)
{
for (Call otherCall : calls)
if (!call.equals(otherCall)
&& CallState.CALL_IN_PROGRESS
.equals(otherCall.getCallState()))
putOnHold(otherCall);
}
}
}
/**
* Performs end-of-life cleanup associated with this instance e.g. removes
* added listeners.
*/
public void dispose()
{
bundleContext.removeServiceListener(listener);
}
/**
* Handles the start and end of the <code>Call</code>s this policy applies
* to in order to have them or stop having them put the other existing calls
* on hold when the former change their states to
* <code>CallState.CALL_IN_PROGRESS</code>.
*
* @param type
* one of {@link CallEvent#CALL_ENDED},
* {@link CallEvent#CALL_INITIATED} and
* {@link CallEvent#CALL_RECEIVED} which described the type of
* the event to be handled
* @param callEvent
* a <code>CallEvent</code> value which describes the change and
* the <code>Call</code> associated with it
*/
private void handleCallEvent(int type, CallEvent callEvent)
{
Call call = callEvent.getSourceCall();
switch (type)
{
case CallEvent.CALL_ENDED:
removeCallListener(call);
break;
case CallEvent.CALL_INITIATED:
case CallEvent.CALL_RECEIVED:
addCallListener(call);
break;
}
}
/**
* Puts the <code>CallPeer</code>s of a specific <code>Call</code> on
* hold.
*
* @param call
* the <code>Call</code> the <code>CallPeer</code>s of
* which are to be put on hold
*/
private void putOnHold(Call call)
{
OperationSetBasicTelephony telephony =
call.getProtocolProvider()
.getOperationSet(OperationSetBasicTelephony.class);
if (telephony != null)
{
for (Iterator<? extends CallPeer> peerIter =
call.getCallPeers(); peerIter.hasNext();)
{
CallPeer peer = peerIter.next();
CallPeerState peerState = peer.getState();
if (!CallPeerState.DISCONNECTED.equals(peerState)
&& !CallPeerState.FAILED.equals(peerState)
&& !CallPeerState.isOnHold(peerState))
{
try
{
telephony.putOnHold(peer);
}
catch (OperationFailedException ex)
{
logger.error("Failed to put " + peer
+ " on hold.", ex);
}
}
}
}
}
/**
* Unregisters a specific <code>Call</code> from this policy in order to
* have the rules of the latter no longer applied to the former.
*
* @param call
* the <code>Call</code> to unregister from this policy in order
* to have the rules of the latter no longer apply to the former
*/
private void removeCallListener(Call call)
{
call.removeCallChangeListener(listener);
synchronized (calls)
{
calls.remove(call);
}
}
/**
* Unregisters a specific <code>OperationSetBasicTelephony</code> from this
* policy in order to have the rules of the latter no longer apply to the
* <code>Call</code>s created by the former.
*
* @param telephony
* the <code>OperationSetBasicTelephony</code> to unregister from
* this policy in order to have the rules of the latter apply to
* the <code>Call</code>s created by the former
*/
private void removeOperationSetBasicTelephonyListener(
OperationSetBasicTelephony telephony)
{
telephony.removeCallListener(listener);
}
/**
* Handles the registering and unregistering of
* <code>OperationSetBasicTelephony</code> instances in order to apply or
* unapply the rules of this policy to the <code>Call</code>s originating
* from them.
*
* @param serviceEvent
* a <code>ServiceEvent</code> value which described a change in
* a OSGi service and which is to be examined for the registering
* or unregistering of a <code>ProtocolProviderService</code> and
* thus a <code>OperationSetBasicTelephony</code>
*/
private void serviceChanged(ServiceEvent serviceEvent)
{
Object service =
bundleContext.getService(serviceEvent.getServiceReference());
if (service instanceof ProtocolProviderService)
{
OperationSetBasicTelephony telephony =
((ProtocolProviderService) service)
.getOperationSet(OperationSetBasicTelephony.class);
if (telephony != null)
{
switch (serviceEvent.getType())
{
case ServiceEvent.REGISTERED:
addOperationSetBasicTelephonyListener(telephony);
break;
case ServiceEvent.UNREGISTERING:
removeOperationSetBasicTelephonyListener(telephony);
break;
}
}
}
}
}

@ -1,396 +1,395 @@
/*
* SIP Communicator, the OpenSource Java VoIP and Instant Messaging client.
*
* Distributable under LGPL license. See terms of license at gnu.org.
*/
package net.java.sip.communicator.impl.protocol.facebook;
import java.io.*;
import java.util.*;
import net.java.sip.communicator.service.protocol.*;
import net.java.sip.communicator.service.protocol.event.*;
import net.java.sip.communicator.util.*;
import org.apache.http.*;
import org.json.*;
/**
* Adapter for the Facebook protocol. This class works as a bridge between the
* Facebook specific classes and the sip communication interfaces. It manages
* the lifecycle of the classes responsible of accessing Facebook servers and
* also manage the necessary {@link Thread threads} used to update the state
* with the latest server changes.
*
* @author Dai Zhiwei
* @author Lubomir Marinov
* @author Edgar Poce
*/
public class FacebookAdapter
implements FacebookSessionListener
{
private static Logger logger = Logger.getLogger(FacebookAdapter.class);
private final OperationSetBasicInstantMessagingFacebookImpl
basicInstantMessaging;
/**
* Parent service provider
*/
private final ProtocolProviderServiceFacebookImpl parentProvider;
private final OperationSetPersistentPresenceFacebookImpl persistentPresence;
/**
* The Facebook session
*/
private FacebookSession session;
private final OperationSetTypingNotificationsFacebookImpl
typingNotifications;
/**
* Cache of typing notifications
*/
private final Map<String, TypingNotificationRecord> typingNotificationRecord
= new HashMap<String, TypingNotificationRecord>();
/**
* Adapter for each Facebook Chat account.
*
* @param parentProvider the parent service provider
* @param persistentPresence
* @param basicInstantMessaging
* @param typingNotifications
*/
public FacebookAdapter(
ProtocolProviderServiceFacebookImpl parentProvider,
OperationSetPersistentPresenceFacebookImpl persistentPresence,
OperationSetBasicInstantMessagingFacebookImpl basicInstantMessaging,
OperationSetTypingNotificationsFacebookImpl typingNotifications)
{
this.parentProvider = parentProvider;
this.persistentPresence = persistentPresence;
this.basicInstantMessaging = basicInstantMessaging;
this.typingNotifications = typingNotifications;
}
/**
* Get the facebook id of this account
*
* @return the facebook id of this account
*/
public String getUID()
{
return this.session.getUid();
}
/**
* Get the parent service provider
*
* @return parent service provider
*/
public ProtocolProviderServiceFacebookImpl getParentProvider()
{
return parentProvider;
}
/**
* Initializes the {@link FacebookSession},<br>
* Initializes the {@link Thread}s to update the buddy list and to poll
* messages
*
* @param email
* @param password
* @return true if the user is logged in
* @throws IOException
* @throws BrokenFacebookProtocolException
*/
public synchronized boolean initialize(
final String email,
final String password)
throws OperationFailedException
{
if (this.session != null && this.session.isLoggedIn())
return true;
logger.info("initializing facebook adapter. account");
try
{
this.session = new FacebookSession();
boolean loggedIn = session.login(email, password);
if (loggedIn)
session.addListener(this);
return loggedIn;
}
catch (Exception e)
{
throw
new OperationFailedException(
"unable to initialize adapter",
FacebookErrorException.kError_Login_GenericError,
e);
}
}
/**
* Post typing notification to the given contact.
*
* @param notifiedContact
* the contact we want to notify
* @param typingState
* our current typing state(SC)
* @throws HttpException
* the http exception
* @throws IOException
* IO exception
* @throws JSONException
* JSON parsing exception
* @throws Exception
* the general exception
*/
public void postTypingNotification(Contact notifiedContact, int typingState)
throws HttpException,
IOException,
JSONException,
Exception
{
TypingNotificationRecord record
= typingNotificationRecord.get(notifiedContact.getAddress());
if (record == null)
{
record = new TypingNotificationRecord(-1l, -1);
synchronized (typingNotificationRecord)
{
typingNotificationRecord
.put(notifiedContact.getAddress(), record);
}
}
if (record.getTime() < System.currentTimeMillis() - 1000)
{
FacebookOutgoingTypingNotification msg
= new FacebookOutgoingTypingNotification(session);
msg.setAddress(notifiedContact.getAddress());
msg.setTypingState(typingState);
msg.send();
record.setTime(System.currentTimeMillis());
record.setType(typingState);
}
}
public void setStatusMessage(String statusMessage)
throws OperationFailedException
{
try
{
this.session.setStatusMessage(statusMessage);
}
catch (IOException e)
{
throw
new OperationFailedException(
"unable to change facebook status message",
-1,
e);
}
}
public synchronized void shutdown()
{
if (session != null)
{
logger.info("shutting down facebook adapter");
session.logout();
}
}
/**
*
* @param message
* @param to
* @return
*/
public synchronized MessageDeliveryFailedEvent postMessage(
Message message,
Contact to)
{
FacebookOutgoingMailboxMessage msg
= new FacebookOutgoingMailboxMessage(session);
msg.setAddress(to.getAddress());
msg.setContent(message.getContent());
msg.setSubject(message.getSubject());
msg.setUid(message.getMessageUID());
try
{
msg.send();
return null;
}
catch (BrokenFacebookProtocolException e)
{
logger.error(e);
return new MessageDeliveryFailedEvent(message, to, -1, System
.currentTimeMillis(), e.getMessage());
}
catch (IOException e)
{
logger.warn(e);
return new MessageDeliveryFailedEvent(message, to, -1, System
.currentTimeMillis(), e.getMessage());
}
catch (FacebookErrorException e)
{
return new MessageDeliveryFailedEvent(message, to, e.getCode());
}
}
public MessageDeliveryFailedEvent postFacebookChatMessage(
Message message,
Contact to)
{
FacebookOutgoingChatMessage msg
= new FacebookOutgoingChatMessage(session);
msg.setAddress(to.getAddress());
msg.setContent(message.getContent());
msg.setMessageUid(message.getMessageUID());
try
{
msg.send();
return null;
}
catch (BrokenFacebookProtocolException e)
{
logger.error(e);
return new MessageDeliveryFailedEvent(message, to, -1, System
.currentTimeMillis(), e.getMessage());
}
catch (IOException e)
{
logger.warn(e);
return new MessageDeliveryFailedEvent(message, to, -1, System
.currentTimeMillis(), e.getMessage());
}
catch (FacebookErrorException e)
{
return new MessageDeliveryFailedEvent(message, to, e.getCode());
}
}
/**
* Promotes the incoming message to the GUI
*
* @see FacebookIncomingMessageListener#onIncomingChatMessage(FacebookMessage)
*/
public void onIncomingChatMessage(FacebookMessage msg)
{
if (!msg.getFrom().equals(this.session.getUid()))
basicInstantMessaging.receivedInstantMessage(msg);
}
/**
* Promotes the incoming notification to the GUI
*
* @see FacebookIncomingMessageListener#onIncomingTypingNotification(String,
* int)
*/
public void onIncomingTypingNotification(String buddyUid, int state)
{
if (!buddyUid.equals(this.session.getUid()))
{
Contact fromContact = persistentPresence.findContactByID(buddyUid);
if (fromContact == null)
fromContact
= persistentPresence.createVolatileContact(buddyUid);
int typingState = OperationSetTypingNotifications.STATE_UNKNOWN;
switch (state)
{
case 1:
typingState = OperationSetTypingNotifications.STATE_TYPING;
break;
case 0:
typingState = OperationSetTypingNotifications.STATE_STOPPED;
break;
default:
typingState = OperationSetTypingNotifications.STATE_UNKNOWN;
}
typingNotifications
.receivedTypingNotification(fromContact, typingState);
}
}
/**
* notifies SC that the connection is lost
*/
public void onFacebookConnectionLost() {
if (parentProvider.isRegistered())
{
try
{
parentProvider.unregister();
}
catch (OperationFailedException e)
{
logger.error("unable to unregister", e);
}
}
// tag all the buddies as offline
persistentPresence
.setPresenceStatusForAllContacts(FacebookStatusEnum.OFFLINE);
}
public void onBuddyListUpdated()
{
for (FacebookUser user : this.session.getBuddyList().getBuddies())
{
PresenceStatus newStatus;
if (user.isOnline && user.isIdle)
newStatus = FacebookStatusEnum.IDLE;
else if (user.isOnline)
newStatus = FacebookStatusEnum.ONLINE;
else
newStatus = FacebookStatusEnum.OFFLINE;
persistentPresence.setPresenceStatusForContact(user.uid, newStatus);
}
}
public FacebookSession getSession()
{
return session;
}
private static class TypingNotificationRecord
{
private long time;
private int type;
public TypingNotificationRecord(long time, int type)
{
this.time = time;
this.type = type;
}
public long getTime()
{
return time;
}
public int getType()
{
return type;
}
public void setTime(long time)
{
this.time = time;
}
public void setType(int type)
{
this.type = type;
}
}
}
/*
* SIP Communicator, the OpenSource Java VoIP and Instant Messaging client.
*
* Distributable under LGPL license. See terms of license at gnu.org.
*/
package net.java.sip.communicator.impl.protocol.facebook;
import java.io.*;
import java.util.*;
import net.java.sip.communicator.service.protocol.*;
import net.java.sip.communicator.service.protocol.event.*;
import net.java.sip.communicator.util.*;
import org.apache.http.*;
import org.json.*;
/**
* Adapter for the Facebook protocol. This class works as a bridge between the
* Facebook specific classes and the sip communication interfaces. It manages
* the lifecycle of the classes responsible of accessing Facebook servers and
* also manage the necessary {@link Thread threads} used to update the state
* with the latest server changes.
*
* @author Dai Zhiwei
* @author Lubomir Marinov
* @author Edgar Poce
*/
public class FacebookAdapter
implements FacebookSessionListener
{
private static Logger logger = Logger.getLogger(FacebookAdapter.class);
private final OperationSetBasicInstantMessagingFacebookImpl
basicInstantMessaging;
/**
* Parent service provider
*/
private final ProtocolProviderServiceFacebookImpl parentProvider;
private final OperationSetPersistentPresenceFacebookImpl persistentPresence;
/**
* The Facebook session
*/
private FacebookSession session;
private final OperationSetTypingNotificationsFacebookImpl
typingNotifications;
/**
* Cache of typing notifications
*/
private final Map<String, TypingNotificationRecord> typingNotificationRecord
= new HashMap<String, TypingNotificationRecord>();
/**
* Adapter for each Facebook Chat account.
*
* @param parentProvider the parent service provider
* @param persistentPresence
* @param basicInstantMessaging
* @param typingNotifications
*/
public FacebookAdapter(
ProtocolProviderServiceFacebookImpl parentProvider,
OperationSetPersistentPresenceFacebookImpl persistentPresence,
OperationSetBasicInstantMessagingFacebookImpl basicInstantMessaging,
OperationSetTypingNotificationsFacebookImpl typingNotifications)
{
this.parentProvider = parentProvider;
this.persistentPresence = persistentPresence;
this.basicInstantMessaging = basicInstantMessaging;
this.typingNotifications = typingNotifications;
}
/**
* Get the facebook id of this account
*
* @return the facebook id of this account
*/
public String getUID()
{
return this.session.getUid();
}
/**
* Get the parent service provider
*
* @return parent service provider
*/
public ProtocolProviderServiceFacebookImpl getParentProvider()
{
return parentProvider;
}
/**
* Initializes the {@link FacebookSession},<br>
* Initializes the {@link Thread}s to update the buddy list and to poll
* messages
*
* @param email
* @param password
* @return true if the user is logged in
* @throws IOException
* @throws BrokenFacebookProtocolException
*/
public synchronized boolean initialize(
final String email,
final String password)
throws OperationFailedException
{
if (this.session != null && this.session.isLoggedIn())
return true;
logger.info("initializing facebook adapter. account");
try
{
this.session = new FacebookSession();
boolean loggedIn = session.login(email, password);
if (loggedIn)
session.addListener(this);
return loggedIn;
}
catch (Exception e)
{
throw
new OperationFailedException(
"unable to initialize adapter",
FacebookErrorException.kError_Login_GenericError,
e);
}
}
/**
* Post typing notification to the given contact.
*
* @param notifiedContact
* the contact we want to notify
* @param typingState
* our current typing state(SC)
* @throws HttpException
* the http exception
* @throws IOException
* IO exception
* @throws JSONException
* JSON parsing exception
* @throws Exception
* the general exception
*/
public void postTypingNotification(Contact notifiedContact, int typingState)
throws HttpException,
IOException,
JSONException,
Exception
{
TypingNotificationRecord record
= typingNotificationRecord.get(notifiedContact.getAddress());
if (record == null)
{
record = new TypingNotificationRecord(-1l, -1);
synchronized (typingNotificationRecord)
{
typingNotificationRecord
.put(notifiedContact.getAddress(), record);
}
}
if (record.getTime() < System.currentTimeMillis() - 1000)
{
FacebookOutgoingTypingNotification msg
= new FacebookOutgoingTypingNotification(session);
msg.setAddress(notifiedContact.getAddress());
msg.setTypingState(typingState);
msg.send();
record.setTime(System.currentTimeMillis());
record.setType(typingState);
}
}
public void setStatusMessage(String statusMessage)
throws OperationFailedException
{
try
{
this.session.setStatusMessage(statusMessage);
}
catch (IOException e)
{
throw
new OperationFailedException(
"unable to change facebook status message",
-1,
e);
}
}
public synchronized void shutdown()
{
if (session != null)
{
logger.info("shutting down facebook adapter");
session.logout();
}
}
/**
*
* @param message
* @param to
* @return
*/
public synchronized MessageDeliveryFailedEvent postMessage(
Message message,
Contact to)
{
FacebookOutgoingMailboxMessage msg
= new FacebookOutgoingMailboxMessage(session);
msg.setAddress(to.getAddress());
msg.setContent(message.getContent());
msg.setSubject(message.getSubject());
msg.setUid(message.getMessageUID());
try
{
msg.send();
return null;
}
catch (BrokenFacebookProtocolException e)
{
logger.error(e);
return new MessageDeliveryFailedEvent(message, to, -1, System
.currentTimeMillis(), e.getMessage());
}
catch (IOException e)
{
logger.warn(e);
return new MessageDeliveryFailedEvent(message, to, -1, System
.currentTimeMillis(), e.getMessage());
}
catch (FacebookErrorException e)
{
return new MessageDeliveryFailedEvent(message, to, e.getCode());
}
}
public MessageDeliveryFailedEvent postFacebookChatMessage(
Message message,
Contact to)
{
FacebookOutgoingChatMessage msg
= new FacebookOutgoingChatMessage(session);
msg.setAddress(to.getAddress());
msg.setContent(message.getContent());
msg.setMessageUid(message.getMessageUID());
try
{
msg.send();
return null;
}
catch (BrokenFacebookProtocolException e)
{
logger.error(e);
return new MessageDeliveryFailedEvent(message, to, -1, System
.currentTimeMillis(), e.getMessage());
}
catch (IOException e)
{
logger.warn(e);
return new MessageDeliveryFailedEvent(message, to, -1, System
.currentTimeMillis(), e.getMessage());
}
catch (FacebookErrorException e)
{
return new MessageDeliveryFailedEvent(message, to, e.getCode());
}
}
/**
* Promotes the incoming message to the GUI
*
* @see FacebookSessionListener#onIncomingChatMessage(FacebookMessage)
*/
public void onIncomingChatMessage(FacebookMessage msg)
{
if (!msg.getFrom().equals(this.session.getUid()))
basicInstantMessaging.receivedInstantMessage(msg);
}
/**
* Promotes the incoming notification to the GUI
*
* @see FacebookSessionListener#onIncomingTypingNotification(String, int)
*/
public void onIncomingTypingNotification(String buddyUid, int state)
{
if (!buddyUid.equals(this.session.getUid()))
{
Contact fromContact = persistentPresence.findContactByID(buddyUid);
if (fromContact == null)
fromContact
= persistentPresence.createVolatileContact(buddyUid);
int typingState = OperationSetTypingNotifications.STATE_UNKNOWN;
switch (state)
{
case 1:
typingState = OperationSetTypingNotifications.STATE_TYPING;
break;
case 0:
typingState = OperationSetTypingNotifications.STATE_STOPPED;
break;
default:
typingState = OperationSetTypingNotifications.STATE_UNKNOWN;
}
typingNotifications
.receivedTypingNotification(fromContact, typingState);
}
}
/**
* notifies SC that the connection is lost
*/
public void onFacebookConnectionLost() {
if (parentProvider.isRegistered())
{
try
{
parentProvider.unregister();
}
catch (OperationFailedException e)
{
logger.error("unable to unregister", e);
}
}
// tag all the buddies as offline
persistentPresence
.setPresenceStatusForAllContacts(FacebookStatusEnum.OFFLINE);
}
public void onBuddyListUpdated()
{
for (FacebookUser user : this.session.getBuddyList().getBuddies())
{
PresenceStatus newStatus;
if (user.isOnline && user.isIdle)
newStatus = FacebookStatusEnum.IDLE;
else if (user.isOnline)
newStatus = FacebookStatusEnum.ONLINE;
else
newStatus = FacebookStatusEnum.OFFLINE;
persistentPresence.setPresenceStatusForContact(user.uid, newStatus);
}
}
public FacebookSession getSession()
{
return session;
}
private static class TypingNotificationRecord
{
private long time;
private int type;
public TypingNotificationRecord(long time, int type)
{
this.time = time;
this.type = type;
}
public long getTime()
{
return time;
}
public int getType()
{
return type;
}
public void setTime(long time)
{
this.time = time;
}
public void setType(int type)
{
this.type = type;
}
}
}

@ -1,288 +1,287 @@
/*
* SIP Communicator, the OpenSource Java VoIP and Instant Messaging client.
*
* Distributable under LGPL license. See terms of license at gnu.org.
*/
package net.java.sip.communicator.impl.protocol.facebook;
import java.io.*;
import java.util.*;
import net.java.sip.communicator.util.*;
import org.apache.http.*;
import org.apache.http.client.entity.*;
import org.apache.http.client.methods.*;
import org.apache.http.message.*;
import org.apache.http.protocol.HTTP;
import org.apache.http.util.*;
import org.json.*;
/**
* Facebook buddy list that store the online buddies information we got from the
* server since we logged in. Some information of ourselves also included. <br>
* This class is responsible of establishing the http connections and updating
* its state when requested.
*
* @author Dai Zhiwei
* @author Edgar Poce
*/
public class FacebookBuddyList
{
private static Logger logger = Logger.getLogger(FacebookBuddyList.class);
/**
* The url of the update
*/
private static final String BUDDYLIST_URL
= "http://www.facebook.com/ajax/chat/buddy_list.php";
/**
* The Facebook Session
*/
private final FacebookSession session;
/**
* Our (online) buddies' information cache
*/
private transient Map<String, FacebookUser> cache
= new LinkedHashMap<String, FacebookUser>();
/**
* Some information of ourselves/myself.
*/
private transient FacebookUser me;
/**
* Listener of this buddy list
*/
private List<FacebookSessionListener> listeners
= new ArrayList<FacebookSessionListener>();
/**
* Init the cache and the parent adapter.
*
* @param adapter
*/
public FacebookBuddyList(FacebookSession session)
{
this.session = session;
}
public void update()
throws BrokenFacebookProtocolException,
IOException,
FacebookErrorException
{
// reconnecting
this.session.reconnect();
logger.info("Updating buddy list...");
// perform POST request
List<NameValuePair> nvps = new ArrayList<NameValuePair>();
nvps.add(new BasicNameValuePair("buddy_list", "1"));
nvps.add(new BasicNameValuePair("notifications", "1"));
nvps.add(new BasicNameValuePair("force_render", "true"));
nvps.add(new BasicNameValuePair("post_form_id", session.getFormId()));
nvps.add(new BasicNameValuePair("user", session.getUid()));
HttpPost post = new HttpPost(BUDDYLIST_URL);
post.setEntity(new UrlEncodedFormEntity(nvps, HTTP.UTF_8));
HttpResponse response = this.session.getHttpClient().execute(post);
String body = EntityUtils.toString(response.getEntity());
if (response.getStatusLine().getStatusCode() != 200)
{
throw new BrokenFacebookProtocolException("Code "
+ response.getStatusLine().getStatusCode()
+ ". Unable to update Facebook buddy list.");
}
this.update(body);
}
/**
* Get meta info of this account
*
* @return meta info of this account
*/
public FacebookUser getMyMetaInfo()
{
return me;
}
/**
* Get our buddy who has the given id from the cache.
*
* @param contactID
* the id we wanna look up
* @return the buddy who has the given id
* @throws FacebookErrorException
* @throws IOException
* @throws BrokenFacebookProtocolException
*/
public FacebookUser getBuddyByUID(String uid)
throws BrokenFacebookProtocolException,
IOException,
FacebookErrorException
{
FacebookUser buddy = this.cache.get(uid);
if (buddy == null && this.me != null && this.me.uid.equals(uid))
{
buddy = me;
}
return buddy;
}
/**
* @return the users in the cache
*/
public Collection<FacebookUser> getBuddies()
{
return Collections.unmodifiableCollection(this.cache.values());
}
/**
* Release the resource
*/
public void clear()
{
for (FacebookUser u : this.cache.values())
{
u.isOnline = false;
}
}
/**
* Updates the buddy list<br>
* If the {@link FacebookSession} is logged out then this method returns
* without modifying the state of the buddy list.
*
* @param body
* @throws BrokenFacebookProtocolException
* @throws FacebookErrorException
*/
@SuppressWarnings("unchecked")
public void update(String body)
throws BrokenFacebookProtocolException,
FacebookErrorException
{
// the session might be getting closed by another thread
// do nothing if it's logged out
synchronized (session)
{
if (!session.isLoggedIn())
{
return;
}
}
JSONObject jsonBuddyList = parseBody(body);
try {
/*
* If listChanged, then we can get the buddies available via looking
* at the nowAvailableList else. we can only get the buddies' info,
* and the nowAvailableList is empty.
*/
JSONObject userInfos = (JSONObject) jsonBuddyList.get("userInfos");
if (userInfos != null)
{
// Then add the new buddies and set them as online(constructor)
Iterator<String> it = userInfos.keys();
while (it.hasNext())
{
String key = it.next();
JSONObject jsonUser = (JSONObject) userInfos.get(key);
if (jsonUser == null)
{
throw new BrokenFacebookProtocolException(
"unable to get user info. " + userInfos);
}
FacebookUser buddy = new FacebookUser(key, jsonUser);
if (buddy.uid.equals(this.session.getUid()))
{
this.me = buddy;
}
else
{
this.cache.put(key, buddy);
}
}
}
JSONObject nowAvailableList = jsonBuddyList
.getJSONObject("nowAvailableList");
if (nowAvailableList == null)
{
throw new BrokenFacebookProtocolException(
"Unable to read Facebook now available list");
}
for (FacebookUser user : this.cache.values())
{
if (nowAvailableList.has(user.uid))
{
user.isOnline = true;
user.lastSeen = Calendar.getInstance().getTimeInMillis();
user.isIdle = nowAvailableList.getJSONObject(user.uid)
.getBoolean("i");
}
else
{
user.isOnline = false;
}
}
// notify listeners
for (FacebookSessionListener l : this.listeners)
l.onBuddyListUpdated();
}
catch (JSONException e)
{
throw new BrokenFacebookProtocolException(e);
}
}
private JSONObject parseBody(String body)
throws BrokenFacebookProtocolException,
FacebookErrorException
{
FacebookJsonResponse jsonResponse = new FacebookJsonResponse(session,
body);
try
{
JSONObject json = jsonResponse.getJson();
JSONObject payload = (JSONObject) json.get("payload");
if (payload == null)
{
throw new BrokenFacebookProtocolException(
"unable to parse buddy list. there's no payload field. "
+ jsonResponse);
}
JSONObject jsonBuddyList = (JSONObject) payload.get("buddy_list");
if (jsonBuddyList == null)
{
throw new BrokenFacebookProtocolException(
"unable to parse buddy list. there's no buddy list field. "
+ jsonResponse);
}
return jsonBuddyList;
}
catch (JSONException e)
{
throw new BrokenFacebookProtocolException(
"unable to parse json response");
}
}
public int getSize()
{
return this.cache.size();
}
/**
* Adds a listener which is notified when the buddy list state changes
*
* @param listener
*/
public void addListener(FacebookSessionListener listener)
{
this.listeners.add(listener);
}
}
/*
* SIP Communicator, the OpenSource Java VoIP and Instant Messaging client.
*
* Distributable under LGPL license. See terms of license at gnu.org.
*/
package net.java.sip.communicator.impl.protocol.facebook;
import java.io.*;
import java.util.*;
import net.java.sip.communicator.util.*;
import org.apache.http.*;
import org.apache.http.client.entity.*;
import org.apache.http.client.methods.*;
import org.apache.http.message.*;
import org.apache.http.protocol.HTTP;
import org.apache.http.util.*;
import org.json.*;
/**
* Facebook buddy list that store the online buddies information we got from the
* server since we logged in. Some information of ourselves also included. <br>
* This class is responsible of establishing the http connections and updating
* its state when requested.
*
* @author Dai Zhiwei
* @author Edgar Poce
*/
public class FacebookBuddyList
{
private static Logger logger = Logger.getLogger(FacebookBuddyList.class);
/**
* The url of the update
*/
private static final String BUDDYLIST_URL
= "http://www.facebook.com/ajax/chat/buddy_list.php";
/**
* The Facebook Session
*/
private final FacebookSession session;
/**
* Our (online) buddies' information cache
*/
private transient Map<String, FacebookUser> cache
= new LinkedHashMap<String, FacebookUser>();
/**
* Some information of ourselves/myself.
*/
private transient FacebookUser me;
/**
* Listener of this buddy list
*/
private List<FacebookSessionListener> listeners
= new ArrayList<FacebookSessionListener>();
/**
* Init the cache and the parent adapter.
*
* @param session the Facebook session
*/
public FacebookBuddyList(FacebookSession session)
{
this.session = session;
}
public void update()
throws BrokenFacebookProtocolException,
IOException,
FacebookErrorException
{
// reconnecting
this.session.reconnect();
logger.info("Updating buddy list...");
// perform POST request
List<NameValuePair> nvps = new ArrayList<NameValuePair>();
nvps.add(new BasicNameValuePair("buddy_list", "1"));
nvps.add(new BasicNameValuePair("notifications", "1"));
nvps.add(new BasicNameValuePair("force_render", "true"));
nvps.add(new BasicNameValuePair("post_form_id", session.getFormId()));
nvps.add(new BasicNameValuePair("user", session.getUid()));
HttpPost post = new HttpPost(BUDDYLIST_URL);
post.setEntity(new UrlEncodedFormEntity(nvps, HTTP.UTF_8));
HttpResponse response = this.session.getHttpClient().execute(post);
String body = EntityUtils.toString(response.getEntity());
if (response.getStatusLine().getStatusCode() != 200)
{
throw new BrokenFacebookProtocolException("Code "
+ response.getStatusLine().getStatusCode()
+ ". Unable to update Facebook buddy list.");
}
this.update(body);
}
/**
* Get meta info of this account
*
* @return meta info of this account
*/
public FacebookUser getMyMetaInfo()
{
return me;
}
/**
* Get our buddy who has the given id from the cache.
*
* @param uid the id we want to look up
* @return the buddy who has the given id
* @throws FacebookErrorException
* @throws IOException
* @throws BrokenFacebookProtocolException
*/
public FacebookUser getBuddyByUID(String uid)
throws BrokenFacebookProtocolException,
IOException,
FacebookErrorException
{
FacebookUser buddy = this.cache.get(uid);
if (buddy == null && this.me != null && this.me.uid.equals(uid))
{
buddy = me;
}
return buddy;
}
/**
* @return the users in the cache
*/
public Collection<FacebookUser> getBuddies()
{
return Collections.unmodifiableCollection(this.cache.values());
}
/**
* Release the resource
*/
public void clear()
{
for (FacebookUser u : this.cache.values())
{
u.isOnline = false;
}
}
/**
* Updates the buddy list<br>
* If the {@link FacebookSession} is logged out then this method returns
* without modifying the state of the buddy list.
*
* @param body
* @throws BrokenFacebookProtocolException
* @throws FacebookErrorException
*/
@SuppressWarnings("unchecked")
public void update(String body)
throws BrokenFacebookProtocolException,
FacebookErrorException
{
// the session might be getting closed by another thread
// do nothing if it's logged out
synchronized (session)
{
if (!session.isLoggedIn())
{
return;
}
}
JSONObject jsonBuddyList = parseBody(body);
try {
/*
* If listChanged, then we can get the buddies available via looking
* at the nowAvailableList else. we can only get the buddies' info,
* and the nowAvailableList is empty.
*/
JSONObject userInfos = (JSONObject) jsonBuddyList.get("userInfos");
if (userInfos != null)
{
// Then add the new buddies and set them as online(constructor)
Iterator<String> it = userInfos.keys();
while (it.hasNext())
{
String key = it.next();
JSONObject jsonUser = (JSONObject) userInfos.get(key);
if (jsonUser == null)
{
throw new BrokenFacebookProtocolException(
"unable to get user info. " + userInfos);
}
FacebookUser buddy = new FacebookUser(key, jsonUser);
if (buddy.uid.equals(this.session.getUid()))
{
this.me = buddy;
}
else
{
this.cache.put(key, buddy);
}
}
}
JSONObject nowAvailableList = jsonBuddyList
.getJSONObject("nowAvailableList");
if (nowAvailableList == null)
{
throw new BrokenFacebookProtocolException(
"Unable to read Facebook now available list");
}
for (FacebookUser user : this.cache.values())
{
if (nowAvailableList.has(user.uid))
{
user.isOnline = true;
user.lastSeen = Calendar.getInstance().getTimeInMillis();
user.isIdle = nowAvailableList.getJSONObject(user.uid)
.getBoolean("i");
}
else
{
user.isOnline = false;
}
}
// notify listeners
for (FacebookSessionListener l : this.listeners)
l.onBuddyListUpdated();
}
catch (JSONException e)
{
throw new BrokenFacebookProtocolException(e);
}
}
private JSONObject parseBody(String body)
throws BrokenFacebookProtocolException,
FacebookErrorException
{
FacebookJsonResponse jsonResponse = new FacebookJsonResponse(session,
body);
try
{
JSONObject json = jsonResponse.getJson();
JSONObject payload = (JSONObject) json.get("payload");
if (payload == null)
{
throw new BrokenFacebookProtocolException(
"unable to parse buddy list. there's no payload field. "
+ jsonResponse);
}
JSONObject jsonBuddyList = (JSONObject) payload.get("buddy_list");
if (jsonBuddyList == null)
{
throw new BrokenFacebookProtocolException(
"unable to parse buddy list. there's no buddy list field. "
+ jsonResponse);
}
return jsonBuddyList;
}
catch (JSONException e)
{
throw new BrokenFacebookProtocolException(
"unable to parse json response");
}
}
public int getSize()
{
return this.cache.size();
}
/**
* Adds a listener which is notified when the buddy list state changes
*
* @param listener
*/
public void addListener(FacebookSessionListener listener)
{
this.listeners.add(listener);
}
}

@ -17,12 +17,12 @@
/**
* This poller checks for new messages in Facebook servers and notifies to the
* registered {@link FacebookIncomingMessageListener listeners} if a new
* registered {@link FacebookSessionListener listeners} if a new
* {@link FacebookMessage} is found.<br>
* Registered {@link FacebookIncomingMessageListener listeners} are notified
* upon arrival of both messages from other buddies and own messages.<br>
* It's responsibility of the {@link FacebookIncomingMessageListener listeners}
* to discard undesired notifications, e.g. own messages.
* Registered {@link FacebookSessionListener listeners} are notified upon
* arrival of both messages from other buddies and own messages.<br>
* It's the responsibility of the {@link FacebookSessionListener listeners} to
* discard undesired notifications, e.g. own messages.
*
* @author Edgar Poce
*/

@ -45,7 +45,6 @@ public FacebookOutgoingChatMessage(FacebookSession session)
* Only one message can be sent at a time for a given
* {@link FacebookSession}
*
* @return true if the message was sent successfully
* @throws BrokenFacebookProtocolException
* @throws IOException
*/

@ -1,266 +1,265 @@
/*
* SIP Communicator, the OpenSource Java VoIP and Instant Messaging client.
*
* Distributable under LGPL license. See terms of license at gnu.org.
*/
package net.java.sip.communicator.impl.protocol.facebook;
import net.java.sip.communicator.service.protocol.*;
import net.java.sip.communicator.service.protocol.event.*;
import net.java.sip.communicator.util.*;
/**
* Instant messaging functionality for the Facebook protocol.
*
* @author Dai Zhiwei
* @author Lubomir Marinov
*/
public class OperationSetBasicInstantMessagingFacebookImpl
extends AbstractOperationSetBasicInstantMessaging
{
private static final Logger logger
= Logger.getLogger(OperationSetBasicInstantMessagingFacebookImpl.class);
/**
* The currently valid persistent presence operation set..
*/
private OperationSetPersistentPresenceFacebookImpl opSetPersPresence = null;
/**
* The protocol provider that created us.
*/
private ProtocolProviderServiceFacebookImpl parentProvider = null;
/**
* Creates an instance of this operation set keeping a reference to the
* parent protocol provider and presence operation set.
*
* @param provider The provider instance that creates us.
* @param opSetPersPresence the currently valid
* <tt>OperationSetPersistentPresenceFacebookImpl</tt>
* instance.
*/
public OperationSetBasicInstantMessagingFacebookImpl(
ProtocolProviderServiceFacebookImpl provider,
OperationSetPersistentPresenceFacebookImpl opSetPersPresence)
{
this.opSetPersPresence = opSetPersPresence;
this.parentProvider = provider;
}
/*
* Implements
* AbstractOperationSetBasicInstantMessaging#createMessage(String, String,
* String, String). Creates a new MessageFacebookImpl instance with the
* specified properties.
*/
public Message createMessage(
String content, String contentType, String encoding, String subject)
{
return
new MessageFacebookImpl(content, contentType, encoding, subject);
}
/**
* Sends the <tt>message</tt> to the destination indicated by the
* <tt>to</tt> contact.
*
* @param to the <tt>Contact</tt> to send <tt>message</tt> to
* @param message the <tt>Message</tt> to send.
* @throws IllegalStateException if the underlying ICQ stack is not
* registered and initialized.
* @throws IllegalArgumentException if <tt>to</tt> is not an instance
* belonging to the underlying implementation.
*/
public void sendInstantMessage(final Contact to, final Message message)
throws IllegalStateException,
IllegalArgumentException
{
if (!(to instanceof ContactFacebookImpl))
throw new IllegalArgumentException(
"The specified contact is not a Facebook contact." + to);
Thread sender = new Thread(new Runnable()
{
public void run()
{
// deliver the facebook chat Message
MessageDeliveryFailedEvent errorEvent = null;
errorEvent =
OperationSetBasicInstantMessagingFacebookImpl.this.parentProvider
.getAdapter().postFacebookChatMessage(message, to);
if (errorEvent == null)
{
fireMessageDelivered(message, to);
return;
}
if(errorEvent.getErrorCode() == FacebookErrorException.kError_Async_NotLoggedIn
|| errorEvent.getErrorCode() == FacebookErrorException.kError_Async_LoginChanged)
{
try
{
parentProvider.unregister(RegistrationStateChangeEvent.REASON_MULTIPLE_LOGINS);
}
catch (OperationFailedException e1)
{
logger.error(
"Unable to unregister the protocol provider: "
+ this
+ " due to the following exception: " + e1);
}
fireMessageDeliveryFailed(
message,
to,
MessageDeliveryFailedEvent.PROVIDER_NOT_REGISTERED);
return;
}
// if the above delivery failed, we try again!
try
{
// wait a moment
Thread.sleep(1000);
errorEvent =
OperationSetBasicInstantMessagingFacebookImpl.this.parentProvider
.getAdapter().postFacebookChatMessage(message, to);
if (errorEvent == null)
{
fireMessageDelivered(message, to);
return;
}
if(errorEvent.getErrorCode() == FacebookErrorException.kError_Async_NotLoggedIn
|| errorEvent.getErrorCode() == FacebookErrorException.kError_Async_LoginChanged)
{
try
{
parentProvider.unregister(RegistrationStateChangeEvent.REASON_MULTIPLE_LOGINS);
}
catch (OperationFailedException e1)
{
logger.error(
"Unable to unregister the protocol provider: "
+ this
+ " due to the following exception: " + e1);
}
}
}
catch (InterruptedException e)
{
logger.warn(e.getMessage());
}
// if we get here, we have failed to deliver this message,
// twice.
fireMessageDeliveryFailed(
message,
to,
MessageDeliveryFailedEvent.UNKNOWN_ERROR);
// now do message delivery.----what's this?
// in case that the "to" we deliver this message to is
// ourselves?
// deliverMessageToMyself(message, (ContactFacebookImpl)to);
}
});
sender.start();
}
/**
* Invoked by the facebook adapter when we got messages from the server.
*
* @param message
* @param from
*/
public void receivedInstantMessage(FacebookMessage fbmsg)
{
Message message = this.createMessage(fbmsg.getText());
String fromID = fbmsg.getFrom();
// TODO handle the msgID.
// it's generated when we createMessage() by now.
// We should set the message id according to the fbmsg.msgID.
// But it's not important.
Contact fromContact = opSetPersPresence.findContactByID(fromID);
if (fromContact == null)
{
// from facebook user who are not on our contact list
// TODO creat volatile contact, fire event.
fromContact = opSetPersPresence.createVolatileContact(fromID);
// opSetPersPresence.subscribe(fromID);
}
fireMessageReceived(message, fromContact);
}
/**
* Notifies all registered message listeners that a message has been
* delivered successfully to its addressee..
*
* @param message
* the <tt>Message</tt> that has been delivered.
* @param to
* the <tt>Contact</tt> that <tt>message</tt> was delivered to.
*/
protected void fireMessageDelivered(Message message, Contact to)
{
// we succeeded in sending a message to contact "to",
// so we know he is online
// but -- if we support the "invisible" status,
// this line could be commented
opSetPersPresence
.setPresenceStatusForContact(
(ContactFacebookImpl) to,
FacebookStatusEnum.ONLINE);
super.fireMessageDelivered(message, to);
}
/**
* Notifies all registered message listeners that a message has been
* received.
*
* @param message the <tt>Message</tt> that has been received.
* @param from the <tt>Contact</tt> that <tt>message</tt> was received
* from.
*/
protected void fireMessageReceived(Message message, Contact from)
{
// we got a message from contact "from", so we know he is online
opSetPersPresence
.setPresenceStatusForContact(
(ContactFacebookImpl) from,
FacebookStatusEnum.ONLINE);
super.fireMessageReceived(message, from);
}
/**
* Determines whether the protocol provider (or the protocol itself) support
* sending and receiving offline messages. Most often this method would
* return true for protocols that support offline messages and false for
* those that don't. It is however possible for a protocol to support these
* messages and yet have a particular account that does not (i.e. feature
* not enabled on the protocol server). In cases like this it is possible
* for this method to return true even when offline messaging is not
* supported, and then have the sendMessage method throw an
* OperationFailedException with code - OFFLINE_MESSAGES_NOT_SUPPORTED.
*
* @return <tt>true</tt> if the protocol supports offline messages and
* <tt>false</tt> otherwise.
*/
public boolean isOfflineMessagingSupported()
{
return false;
}
/**
* Determines wheter the protocol supports the supplied content type
*
* @param contentType the type we want to check
* @return <tt>true</tt> if the protocol supports it and <tt>false</tt>
* otherwise.
*/
public boolean isContentTypeSupported(String contentType)
{
return contentType.equals(DEFAULT_MIME_TYPE);
}
}
/*
* SIP Communicator, the OpenSource Java VoIP and Instant Messaging client.
*
* Distributable under LGPL license. See terms of license at gnu.org.
*/
package net.java.sip.communicator.impl.protocol.facebook;
import net.java.sip.communicator.service.protocol.*;
import net.java.sip.communicator.service.protocol.event.*;
import net.java.sip.communicator.util.*;
/**
* Instant messaging functionality for the Facebook protocol.
*
* @author Dai Zhiwei
* @author Lubomir Marinov
*/
public class OperationSetBasicInstantMessagingFacebookImpl
extends AbstractOperationSetBasicInstantMessaging
{
private static final Logger logger
= Logger.getLogger(OperationSetBasicInstantMessagingFacebookImpl.class);
/**
* The currently valid persistent presence operation set..
*/
private OperationSetPersistentPresenceFacebookImpl opSetPersPresence = null;
/**
* The protocol provider that created us.
*/
private ProtocolProviderServiceFacebookImpl parentProvider = null;
/**
* Creates an instance of this operation set keeping a reference to the
* parent protocol provider and presence operation set.
*
* @param provider The provider instance that creates us.
* @param opSetPersPresence the currently valid
* <tt>OperationSetPersistentPresenceFacebookImpl</tt>
* instance.
*/
public OperationSetBasicInstantMessagingFacebookImpl(
ProtocolProviderServiceFacebookImpl provider,
OperationSetPersistentPresenceFacebookImpl opSetPersPresence)
{
this.opSetPersPresence = opSetPersPresence;
this.parentProvider = provider;
}
/*
* Implements
* AbstractOperationSetBasicInstantMessaging#createMessage(String, String,
* String, String). Creates a new MessageFacebookImpl instance with the
* specified properties.
*/
public Message createMessage(
String content, String contentType, String encoding, String subject)
{
return
new MessageFacebookImpl(content, contentType, encoding, subject);
}
/**
* Sends the <tt>message</tt> to the destination indicated by the
* <tt>to</tt> contact.
*
* @param to the <tt>Contact</tt> to send <tt>message</tt> to
* @param message the <tt>Message</tt> to send.
* @throws IllegalStateException if the underlying ICQ stack is not
* registered and initialized.
* @throws IllegalArgumentException if <tt>to</tt> is not an instance
* belonging to the underlying implementation.
*/
public void sendInstantMessage(final Contact to, final Message message)
throws IllegalStateException,
IllegalArgumentException
{
if (!(to instanceof ContactFacebookImpl))
throw new IllegalArgumentException(
"The specified contact is not a Facebook contact." + to);
Thread sender = new Thread(new Runnable()
{
public void run()
{
// deliver the facebook chat Message
MessageDeliveryFailedEvent errorEvent = null;
errorEvent =
OperationSetBasicInstantMessagingFacebookImpl.this.parentProvider
.getAdapter().postFacebookChatMessage(message, to);
if (errorEvent == null)
{
fireMessageDelivered(message, to);
return;
}
if(errorEvent.getErrorCode() == FacebookErrorException.kError_Async_NotLoggedIn
|| errorEvent.getErrorCode() == FacebookErrorException.kError_Async_LoginChanged)
{
try
{
parentProvider.unregister(RegistrationStateChangeEvent.REASON_MULTIPLE_LOGINS);
}
catch (OperationFailedException e1)
{
logger.error(
"Unable to unregister the protocol provider: "
+ this
+ " due to the following exception: " + e1);
}
fireMessageDeliveryFailed(
message,
to,
MessageDeliveryFailedEvent.PROVIDER_NOT_REGISTERED);
return;
}
// if the above delivery failed, we try again!
try
{
// wait a moment
Thread.sleep(1000);
errorEvent =
OperationSetBasicInstantMessagingFacebookImpl.this.parentProvider
.getAdapter().postFacebookChatMessage(message, to);
if (errorEvent == null)
{
fireMessageDelivered(message, to);
return;
}
if(errorEvent.getErrorCode() == FacebookErrorException.kError_Async_NotLoggedIn
|| errorEvent.getErrorCode() == FacebookErrorException.kError_Async_LoginChanged)
{
try
{
parentProvider.unregister(RegistrationStateChangeEvent.REASON_MULTIPLE_LOGINS);
}
catch (OperationFailedException e1)
{
logger.error(
"Unable to unregister the protocol provider: "
+ this
+ " due to the following exception: " + e1);
}
}
}
catch (InterruptedException e)
{
logger.warn(e.getMessage());
}
// if we get here, we have failed to deliver this message,
// twice.
fireMessageDeliveryFailed(
message,
to,
MessageDeliveryFailedEvent.UNKNOWN_ERROR);
// now do message delivery.----what's this?
// in case that the "to" we deliver this message to is
// ourselves?
// deliverMessageToMyself(message, (ContactFacebookImpl)to);
}
});
sender.start();
}
/**
* Invoked by the facebook adapter when we got messages from the server.
*
* @param fbmsg the received Facebook instant message
*/
public void receivedInstantMessage(FacebookMessage fbmsg)
{
Message message = this.createMessage(fbmsg.getText());
String fromID = fbmsg.getFrom();
// TODO handle the msgID.
// it's generated when we createMessage() by now.
// We should set the message id according to the fbmsg.msgID.
// But it's not important.
Contact fromContact = opSetPersPresence.findContactByID(fromID);
if (fromContact == null)
{
// from facebook user who are not on our contact list
// TODO creat volatile contact, fire event.
fromContact = opSetPersPresence.createVolatileContact(fromID);
// opSetPersPresence.subscribe(fromID);
}
fireMessageReceived(message, fromContact);
}
/**
* Notifies all registered message listeners that a message has been
* delivered successfully to its addressee..
*
* @param message
* the <tt>Message</tt> that has been delivered.
* @param to
* the <tt>Contact</tt> that <tt>message</tt> was delivered to.
*/
protected void fireMessageDelivered(Message message, Contact to)
{
// we succeeded in sending a message to contact "to",
// so we know he is online
// but -- if we support the "invisible" status,
// this line could be commented
opSetPersPresence
.setPresenceStatusForContact(
(ContactFacebookImpl) to,
FacebookStatusEnum.ONLINE);
super.fireMessageDelivered(message, to);
}
/**
* Notifies all registered message listeners that a message has been
* received.
*
* @param message the <tt>Message</tt> that has been received.
* @param from the <tt>Contact</tt> that <tt>message</tt> was received
* from.
*/
protected void fireMessageReceived(Message message, Contact from)
{
// we got a message from contact "from", so we know he is online
opSetPersPresence
.setPresenceStatusForContact(
(ContactFacebookImpl) from,
FacebookStatusEnum.ONLINE);
super.fireMessageReceived(message, from);
}
/**
* Determines whether the protocol provider (or the protocol itself) support
* sending and receiving offline messages. Most often this method would
* return true for protocols that support offline messages and false for
* those that don't. It is however possible for a protocol to support these
* messages and yet have a particular account that does not (i.e. feature
* not enabled on the protocol server). In cases like this it is possible
* for this method to return true even when offline messaging is not
* supported, and then have the sendMessage method throw an
* OperationFailedException with code - OFFLINE_MESSAGES_NOT_SUPPORTED.
*
* @return <tt>true</tt> if the protocol supports offline messages and
* <tt>false</tt> otherwise.
*/
public boolean isOfflineMessagingSupported()
{
return false;
}
/**
* Determines wheter the protocol supports the supplied content type
*
* @param contentType the type we want to check
* @return <tt>true</tt> if the protocol supports it and <tt>false</tt>
* otherwise.
*/
public boolean isContentTypeSupported(String contentType)
{
return contentType.equals(DEFAULT_MIME_TYPE);
}
}

@ -377,7 +377,7 @@ public void leave()
{
Map.Entry<String, Contact> memberEntry = membersSet.next();
Contact participant = (Contact) memberEntry.getValue();
Contact participant = memberEntry.getValue();
fireParticipantPresenceEvent(participant,
AdHocChatRoomParticipantPresenceChangeEvent.CONTACT_LEFT,

@ -107,8 +107,8 @@ public String getDisplayName()
if (call != null)
{
ProtocolProviderService pps = call.getProtocolProvider();
OperationSetPresence opSetPresence = (OperationSetPresence) pps
.getOperationSet(OperationSetPresence.class);
OperationSetPresence opSetPresence
= pps.getOperationSet(OperationSetPresence.class);
Contact cont = opSetPresence.findContactByID(getAddress());
if (cont != null)
@ -243,8 +243,8 @@ public ProtocolProviderService getProtocolProvider()
public Contact getContact()
{
ProtocolProviderService pps = call.getProtocolProvider();
OperationSetPresence opSetPresence = (OperationSetPresence) pps
.getOperationSet(OperationSetPresence.class);
OperationSetPresence opSetPresence
= pps.getOperationSet(OperationSetPresence.class);
return opSetPresence.findContactByID(getAddress());
}

@ -63,8 +63,9 @@ public OperationSetGeolocationJabberImpl(
{
this.jabberProvider = provider;
this.opsetprez = (OperationSetPersistentPresence)
provider.getOperationSet(OperationSetPersistentPresence.class);
this.opsetprez
= provider
.getOperationSet(OperationSetPersistentPresence.class);
this.jabberProvider.addRegistrationStateChangeListener(
new RegistrationStateListener());

@ -63,7 +63,7 @@ public class OperationSetMultiUserChatJabberImpl
jabberProvider.addRegistrationStateChangeListener(providerRegListener);
OperationSetPersistentPresence presenceOpSet
= (OperationSetPersistentPresence) jabberProvider
= jabberProvider
.getOperationSet(OperationSetPersistentPresence.class);
presenceOpSet.addSubscriptionListener(this);

@ -151,8 +151,7 @@ public void handleUri(String uri)
}
OperationSetPresence presenceOpSet
= (OperationSetPresence) provider
.getOperationSet(OperationSetPresence.class);
= provider.getOperationSet(OperationSetPresence.class);
try
{

@ -710,7 +710,8 @@ public boolean equals(Object obj)
public OperationSetPersistentPresence
getParentPresenceOperationSet()
{
return (OperationSetPersistentPresence)parentProvider
return
parentProvider
.getOperationSet(OperationSetPersistentPresence.class);
}
@ -724,7 +725,8 @@ public boolean equals(Object obj)
public OperationSetBasicInstantMessaging
getParentBasicInstantMessagingOperationSet()
{
return (OperationSetBasicInstantMessaging)parentProvider
return
parentProvider
.getOperationSet(OperationSetBasicInstantMessaging.class);
}
@ -738,8 +740,7 @@ public boolean equals(Object obj)
public OperationSetFileTransfer
getFileTransferOperationSet()
{
return (OperationSetFileTransfer)parentProvider
.getOperationSet(OperationSetFileTransfer.class);
return parentProvider.getOperationSet(OperationSetFileTransfer.class);
}

@ -369,7 +369,6 @@ public void rejectInvitation(AdHocChatRoomInvitation invitation,
* @param targetChatRoom the room that invitation refers to
* @param inviter the inviter that sent the invitation
* @param reason the reason why the inviter sent the invitation
* @param password the password to use when joining the room
*/
public void fireInvitationEvent(AdHocChatRoom targetChatRoom,
String inviter, String reason)

@ -1,194 +1,192 @@
/*
* SIP Communicator, the OpenSource Java VoIP and Instant Messaging client.
*
* Distributable under LGPL license.
* See terms of license at gnu.org.
*/
package net.java.sip.communicator.plugin.autoaway;
import java.awt.*;
import java.util.*;
import net.java.sip.communicator.service.configuration.*;
import net.java.sip.communicator.service.protocol.*;
/**
* A Runnable, which permanently looks at the mouse position. If the mouse is
* not moved, all accounts are set to "Away" or similar states.
*
* @author Thomas Hofer
*/
public class StatusUpdateThread
implements Runnable
{
private boolean run = false;
private Point lastPosition = null;
private final Map<ProtocolProviderService, PresenceStatus> lastStates
= new HashMap<ProtocolProviderService, PresenceStatus>();
private static final int IDLE_TIMER = 3000;
private static final int AWAY_DEFAULT_STATUS = 40;
public void run()
{
run = true;
int timer = 0;
do
{
try
{
if (MouseInfo.getPointerInfo() != null)
{
PointerInfo info = MouseInfo.getPointerInfo();
Point currentPosition
= (info != null) ? info.getLocation() : new Point(0, 0);
if (!isNear(lastPosition, currentPosition))
{
// position has changed
// check, if a minor state has been automatically set
// and
// reset this state to the former state.
for (ProtocolProviderService protocolProviderService
: AutoAwayActivator.getProtocolProviders())
{
if (lastStates.get(protocolProviderService) != null)
{
PresenceStatus lastState
= lastStates.get(protocolProviderService);
OperationSetPresence presence
= (OperationSetPresence)
protocolProviderService
.getOperationSet(
OperationSetPresence.class);
try
{
presence
.publishPresenceStatus(lastState, "");
} catch (IllegalArgumentException e)
{
} catch (IllegalStateException e)
{
} catch (OperationFailedException e)
{
}
lastStates.remove(protocolProviderService);
}
}
timer = getTimer() * 1000 * 60;
} else
{
// position has not changed!
// get all protocols and set them to away
for (ProtocolProviderService protocolProviderService
: AutoAwayActivator.getProtocolProviders())
{
OperationSetPresence presence
= (OperationSetPresence)
protocolProviderService
.getOperationSet(
OperationSetPresence.class);
PresenceStatus status = presence
.getPresenceStatus();
if (status.getStatus()
< PresenceStatus.AVAILABLE_THRESHOLD)
{
// already (manually) set to away or lower
continue;
}
lastStates.put(protocolProviderService, status);
PresenceStatus newStatus = findAwayStatus(presence);
try
{
if (newStatus != null)
presence
.publishPresenceStatus(
newStatus,
newStatus.getStatusName());
} catch (IllegalArgumentException e)
{
} catch (IllegalStateException e)
{
} catch (OperationFailedException e)
{
}
}
timer = IDLE_TIMER;
}
lastPosition = currentPosition;
}
Thread.sleep(timer);
} catch (InterruptedException e)
{
}
} while (run && timer > 0);
}
public void stop()
{
run = false;
}
/**
* Finds the Away-Status of the protocols
*
* @param presence
* @return
*/
private PresenceStatus findAwayStatus(OperationSetPresence presence)
{
Iterator<PresenceStatus> statusSet = presence.getSupportedStatusSet();
PresenceStatus status = null;
while (statusSet.hasNext())
{
PresenceStatus possibleState = statusSet.next();
int possibleStatus = possibleState.getStatus();
if ((possibleStatus < PresenceStatus.AVAILABLE_THRESHOLD)
&& (possibleStatus >= PresenceStatus.ONLINE_THRESHOLD))
{
if (status == null
|| (Math.abs(possibleStatus - AWAY_DEFAULT_STATUS)
< Math.abs(
status.getStatus()
- AWAY_DEFAULT_STATUS)))
{
status = possibleState;
}
}
}
return status;
}
private int getTimer()
{
ConfigurationService configService
= AutoAwayActivator.getConfigService();
return
configService.getBoolean(Preferences.ENABLE, false)
? configService.getInt(Preferences.TIMER, 0)
: 0;
}
public boolean isRunning()
{
return run;
}
private boolean isNear(Point p1, Point p2)
{
return
(p1 != null)
&& (p2 != null)
&& (Math.abs(p1.x - p2.x) <= 10)
&& (Math.abs(p1.y - p2.y) <= 10);
}
}
/*
* SIP Communicator, the OpenSource Java VoIP and Instant Messaging client.
*
* Distributable under LGPL license.
* See terms of license at gnu.org.
*/
package net.java.sip.communicator.plugin.autoaway;
import java.awt.*;
import java.util.*;
import net.java.sip.communicator.service.configuration.*;
import net.java.sip.communicator.service.protocol.*;
/**
* A Runnable, which permanently looks at the mouse position. If the mouse is
* not moved, all accounts are set to "Away" or similar states.
*
* @author Thomas Hofer
*/
public class StatusUpdateThread
implements Runnable
{
private boolean run = false;
private Point lastPosition = null;
private final Map<ProtocolProviderService, PresenceStatus> lastStates
= new HashMap<ProtocolProviderService, PresenceStatus>();
private static final int IDLE_TIMER = 3000;
private static final int AWAY_DEFAULT_STATUS = 40;
public void run()
{
run = true;
int timer = 0;
do
{
try
{
if (MouseInfo.getPointerInfo() != null)
{
PointerInfo info = MouseInfo.getPointerInfo();
Point currentPosition
= (info != null) ? info.getLocation() : new Point(0, 0);
if (!isNear(lastPosition, currentPosition))
{
// position has changed
// check, if a minor state has been automatically set
// and
// reset this state to the former state.
for (ProtocolProviderService protocolProviderService
: AutoAwayActivator.getProtocolProviders())
{
if (lastStates.get(protocolProviderService) != null)
{
PresenceStatus lastState
= lastStates.get(protocolProviderService);
OperationSetPresence presence
= protocolProviderService
.getOperationSet(
OperationSetPresence.class);
try
{
presence
.publishPresenceStatus(lastState, "");
} catch (IllegalArgumentException e)
{
} catch (IllegalStateException e)
{
} catch (OperationFailedException e)
{
}
lastStates.remove(protocolProviderService);
}
}
timer = getTimer() * 1000 * 60;
} else
{
// position has not changed!
// get all protocols and set them to away
for (ProtocolProviderService protocolProviderService
: AutoAwayActivator.getProtocolProviders())
{
OperationSetPresence presence
= protocolProviderService
.getOperationSet(
OperationSetPresence.class);
PresenceStatus status = presence
.getPresenceStatus();
if (status.getStatus()
< PresenceStatus.AVAILABLE_THRESHOLD)
{
// already (manually) set to away or lower
continue;
}
lastStates.put(protocolProviderService, status);
PresenceStatus newStatus = findAwayStatus(presence);
try
{
if (newStatus != null)
presence
.publishPresenceStatus(
newStatus,
newStatus.getStatusName());
} catch (IllegalArgumentException e)
{
} catch (IllegalStateException e)
{
} catch (OperationFailedException e)
{
}
}
timer = IDLE_TIMER;
}
lastPosition = currentPosition;
}
Thread.sleep(timer);
} catch (InterruptedException e)
{
}
} while (run && timer > 0);
}
public void stop()
{
run = false;
}
/**
* Finds the Away-Status of the protocols
*
* @param presence
* @return
*/
private PresenceStatus findAwayStatus(OperationSetPresence presence)
{
Iterator<PresenceStatus> statusSet = presence.getSupportedStatusSet();
PresenceStatus status = null;
while (statusSet.hasNext())
{
PresenceStatus possibleState = statusSet.next();
int possibleStatus = possibleState.getStatus();
if ((possibleStatus < PresenceStatus.AVAILABLE_THRESHOLD)
&& (possibleStatus >= PresenceStatus.ONLINE_THRESHOLD))
{
if (status == null
|| (Math.abs(possibleStatus - AWAY_DEFAULT_STATUS)
< Math.abs(
status.getStatus()
- AWAY_DEFAULT_STATUS)))
{
status = possibleState;
}
}
}
return status;
}
private int getTimer()
{
ConfigurationService configService
= AutoAwayActivator.getConfigService();
return
configService.getBoolean(Preferences.ENABLE, false)
? configService.getInt(Preferences.TIMER, 0)
: 0;
}
public boolean isRunning()
{
return run;
}
private boolean isNear(Point p1, Point p2)
{
return
(p1 != null)
&& (p2 != null)
&& (Math.abs(p1.x - p2.x) <= 10)
&& (Math.abs(p1.y - p2.y) <= 10);
}
}

@ -1,344 +1,340 @@
/*
* SIP Communicator, the OpenSource Java VoIP and Instant Messaging client.
*
* Distributable under LGPL license.
* See terms of license at gnu.org.
*/
package net.java.sip.communicator.plugin.chatalerter;
import javax.swing.*;
import net.java.sip.communicator.service.gui.*;
import net.java.sip.communicator.service.protocol.*;
import net.java.sip.communicator.service.protocol.event.*;
import net.java.sip.communicator.util.*;
import org.jdesktop.jdic.misc.*;
import org.osgi.framework.*;
/**
* Chat Alerter plugin.
*
* Sends alerts to the user when new message arrives and the application is not
* in the foreground. On Mac OS X this will bounce the dock icon until the user
* selects the chat windows. On Windows, Gnome and KDE this will flash the
* taskbar button/icon until the user selects the chat window.
*
* @author Damian Minkov
*/
public class ChatAlerterActivator
implements BundleActivator,
ServiceListener,
MessageListener,
ChatRoomMessageListener,
/*
* SIP Communicator, the OpenSource Java VoIP and Instant Messaging client.
*
* Distributable under LGPL license.
* See terms of license at gnu.org.
*/
package net.java.sip.communicator.plugin.chatalerter;
import javax.swing.*;
import net.java.sip.communicator.service.gui.*;
import net.java.sip.communicator.service.protocol.*;
import net.java.sip.communicator.service.protocol.event.*;
import net.java.sip.communicator.util.*;
import org.jdesktop.jdic.misc.*;
import org.osgi.framework.*;
/**
* Chat Alerter plugin.
*
* Sends alerts to the user when new message arrives and the application is not
* in the foreground. On Mac OS X this will bounce the dock icon until the user
* selects the chat windows. On Windows, Gnome and KDE this will flash the
* taskbar button/icon until the user selects the chat window.
*
* @author Damian Minkov
*/
public class ChatAlerterActivator
implements BundleActivator,
ServiceListener,
MessageListener,
ChatRoomMessageListener,
AdHocChatRoomMessageListener,
LocalUserChatRoomPresenceListener,
LocalUserAdHocChatRoomPresenceListener
{
/**
* The logger for this class.
*/
private static Logger logger = Logger.getLogger(ChatAlerterActivator.class);
/**
* The BundleContext that we got from the OSGI bus.
*/
private BundleContext bundleContext = null;
/**
* UIService reference.
*/
private UIService uiService;
/**
* Starts this bundle.
*/
public void start(BundleContext bc) throws Exception
{
try
{
// try to load native libs, if it fails don't do anything
Alerter.newInstance();
}
catch (Exception exception)
{
logger.info("The Alerter not supported or problem loading it!",
exception);
return;
}
ServiceReference uiServiceRef
= bc.getServiceReference(UIService.class.getName());
uiService = (UIService) bc.getService(uiServiceRef);
this.bundleContext = bc;
// start listening for newly register or removed protocol providers
bc.addServiceListener(this);
ServiceReference[] protocolProviderRefs;
try
{
protocolProviderRefs = bc.getServiceReferences(
ProtocolProviderService.class.getName(),
null);
}
catch (InvalidSyntaxException ex)
{
// this shouldn't happen since we're providing no parameter string
// but let's log just in case.
logger.error(
"Error while retrieving service refs", ex);
return;
}
// in case we found any
if (protocolProviderRefs != null)
{
logger.debug("Found "
+ protocolProviderRefs.length
+ " already installed providers.");
for (ServiceReference protocolProviderRef : protocolProviderRefs)
{
ProtocolProviderService provider
= (ProtocolProviderService)
bc.getService(protocolProviderRef);
this.handleProviderAdded(provider);
}
}
{
/**
* The logger for this class.
*/
private static Logger logger = Logger.getLogger(ChatAlerterActivator.class);
/**
* The BundleContext that we got from the OSGI bus.
*/
private BundleContext bundleContext = null;
/**
* UIService reference.
*/
private UIService uiService;
/**
* Starts this bundle.
*/
public void start(BundleContext bc) throws Exception
{
try
{
// try to load native libs, if it fails don't do anything
Alerter.newInstance();
}
catch (Exception exception)
{
logger.info("The Alerter not supported or problem loading it!",
exception);
return;
}
}
public void stop(BundleContext bc) throws Exception
{
// start listening for newly register or removed protocol providers
bc.removeServiceListener(this);
ServiceReference[] protocolProviderRefs;
try
{
protocolProviderRefs = bc.getServiceReferences(
ProtocolProviderService.class.getName(),
null);
}
catch (InvalidSyntaxException ex)
{
// this shouldn't happen since we're providing no parameter string
// but let's log just in case.
logger.error(
"Error while retrieving service refs", ex);
return;
}
// in case we found any
if (protocolProviderRefs != null)
{
for (ServiceReference protocolProviderRef : protocolProviderRefs)
{
ProtocolProviderService provider
= (ProtocolProviderService)
bc.getService(protocolProviderRef);
this.handleProviderRemoved(provider);
}
}
}
/**
* Used to attach the Alerter plugin to existing or
* just registered protocol provider. Checks if the provider has implementation
* of OperationSetBasicInstantMessaging
*
* @param provider ProtocolProviderService
*/
private void handleProviderAdded(ProtocolProviderService provider)
{
logger.debug("Adding protocol provider " + provider.getProtocolName());
// check whether the provider has a basic im operation set
OperationSetBasicInstantMessaging opSetIm =
(OperationSetBasicInstantMessaging) provider
.getOperationSet(OperationSetBasicInstantMessaging.class);
if (opSetIm != null)
{
opSetIm.addMessageListener(this);
}
else
{
logger.trace("Service did not have a im op. set.");
}
// check whether the provider has a sms operation set
OperationSetSmsMessaging opSetSms =
(OperationSetSmsMessaging) provider
.getOperationSet(OperationSetSmsMessaging.class);
if (opSetSms != null)
{
opSetSms.addMessageListener(this);
}
else
{
logger.trace("Service did not have a sms op. set.");
}
OperationSetMultiUserChat opSetMultiUChat =
(OperationSetMultiUserChat) provider
.getOperationSet(OperationSetMultiUserChat.class);
if (opSetMultiUChat != null)
{
for (ChatRoom room : opSetMultiUChat.getCurrentlyJoinedChatRooms())
room.addMessageListener(this);
opSetMultiUChat.addPresenceListener(this);
}
else
{
logger.trace("Service did not have a multi im op. set.");
}
}
/**
* Removes the specified provider from the list of currently known providers
* and ignores all the messages exchanged by it
*
* @param provider the ProtocolProviderService that has been unregistered.
*/
private void handleProviderRemoved(ProtocolProviderService provider)
{
OperationSetBasicInstantMessaging opSetIm =
(OperationSetBasicInstantMessaging) provider
.getOperationSet(OperationSetBasicInstantMessaging.class);
if (opSetIm != null)
{
opSetIm.removeMessageListener(this);
}
OperationSetMultiUserChat opSetMultiUChat =
(OperationSetMultiUserChat) provider
.getOperationSet(OperationSetMultiUserChat.class);
if (opSetMultiUChat != null)
{
for (ChatRoom room : opSetMultiUChat.getCurrentlyJoinedChatRooms())
room.removeMessageListener(this);
}
}
/**
* Called to notify interested parties that a change in our presence in
* a chat room has occurred. Changes may include us being kicked, join,
* left.
* @param evt the <tt>LocalUserChatRoomPresenceChangeEvent</tt> instance
* containing the chat room and the type, and reason of the change
*/
public void localUserPresenceChanged(LocalUserChatRoomPresenceChangeEvent evt)
{
if(evt.getEventType() ==
LocalUserChatRoomPresenceChangeEvent.LOCAL_USER_JOINED)
{
if (!evt.getChatRoom().isSystem())
evt.getChatRoom().addMessageListener(this);
}
else
{
evt.getChatRoom().removeMessageListener(this);
}
}
public void messageReceived(MessageReceivedEvent evt)
{
alertChatWindow();
}
public void messageDelivered(MessageDeliveredEvent evt)
{
// do nothing
}
public void messageDeliveryFailed(MessageDeliveryFailedEvent evt)
{
// do nothing
}
public void messageReceived(ChatRoomMessageReceivedEvent evt)
{
alertChatWindow();
}
public void messageDelivered(ChatRoomMessageDeliveredEvent evt)
{
// do nothing
}
public void messageDeliveryFailed(ChatRoomMessageDeliveryFailedEvent evt)
{
// do nothing
}
/**
* Alerts that a message has been received in
* <code>ExportedWindow.CHAT_WINDOW</code> by using a platform-dependent
* visual clue such as flashing it in the task bar on Windows and Linux.
*/
private void alertChatWindow()
{
try
{
ExportedWindow win
= uiService.getExportedWindow(ExportedWindow.CHAT_WINDOW);
if (win == null)
return;
Object winSource = win.getSource();
if (!(winSource instanceof JFrame))
return;
JFrame fr = (JFrame) winSource;
Alerter.newInstance().alert(fr);
}
catch (Exception ex)
{
logger.error("Cannot alert chat window!");
}
}
/**
* When new protocol provider is registered we check
* does it supports needed Op. Sets and if so add a listener to it
*
* @param serviceEvent ServiceEvent
*/
public void serviceChanged(ServiceEvent serviceEvent)
{
Object sService
= bundleContext.getService(serviceEvent.getServiceReference());
logger.trace("Received a service event for: " +
sService.getClass().getName());
// we don't care if the source service is not a protocol provider
if (!(sService instanceof ProtocolProviderService))
return;
logger.debug("Service is a protocol provider.");
switch (serviceEvent.getType())
{
case ServiceEvent.REGISTERED:
this.handleProviderAdded((ProtocolProviderService)sService);
break;
case ServiceEvent.UNREGISTERING:
this.handleProviderRemoved( (ProtocolProviderService) sService);
break;
}
}
ServiceReference uiServiceRef
= bc.getServiceReference(UIService.class.getName());
uiService = (UIService) bc.getService(uiServiceRef);
this.bundleContext = bc;
// start listening for newly register or removed protocol providers
bc.addServiceListener(this);
ServiceReference[] protocolProviderRefs;
try
{
protocolProviderRefs = bc.getServiceReferences(
ProtocolProviderService.class.getName(),
null);
}
catch (InvalidSyntaxException ex)
{
// this shouldn't happen since we're providing no parameter string
// but let's log just in case.
logger.error(
"Error while retrieving service refs", ex);
return;
}
// in case we found any
if (protocolProviderRefs != null)
{
logger.debug("Found "
+ protocolProviderRefs.length
+ " already installed providers.");
for (ServiceReference protocolProviderRef : protocolProviderRefs)
{
ProtocolProviderService provider
= (ProtocolProviderService)
bc.getService(protocolProviderRef);
this.handleProviderAdded(provider);
}
}
}
public void stop(BundleContext bc) throws Exception
{
// start listening for newly register or removed protocol providers
bc.removeServiceListener(this);
ServiceReference[] protocolProviderRefs;
try
{
protocolProviderRefs = bc.getServiceReferences(
ProtocolProviderService.class.getName(),
null);
}
catch (InvalidSyntaxException ex)
{
// this shouldn't happen since we're providing no parameter string
// but let's log just in case.
logger.error(
"Error while retrieving service refs", ex);
return;
}
// in case we found any
if (protocolProviderRefs != null)
{
for (ServiceReference protocolProviderRef : protocolProviderRefs)
{
ProtocolProviderService provider
= (ProtocolProviderService)
bc.getService(protocolProviderRef);
this.handleProviderRemoved(provider);
}
}
}
/**
* Used to attach the Alerter plugin to existing or
* just registered protocol provider. Checks if the provider has implementation
* of OperationSetBasicInstantMessaging
*
* @param provider ProtocolProviderService
*/
private void handleProviderAdded(ProtocolProviderService provider)
{
logger.debug("Adding protocol provider " + provider.getProtocolName());
// check whether the provider has a basic im operation set
OperationSetBasicInstantMessaging opSetIm
= provider
.getOperationSet(OperationSetBasicInstantMessaging.class);
if (opSetIm != null)
{
opSetIm.addMessageListener(this);
}
else
{
logger.trace("Service did not have a im op. set.");
}
// check whether the provider has a sms operation set
OperationSetSmsMessaging opSetSms
= provider.getOperationSet(OperationSetSmsMessaging.class);
if (opSetSms != null)
{
opSetSms.addMessageListener(this);
}
else
{
logger.trace("Service did not have a sms op. set.");
}
OperationSetMultiUserChat opSetMultiUChat
= provider.getOperationSet(OperationSetMultiUserChat.class);
if (opSetMultiUChat != null)
{
for (ChatRoom room : opSetMultiUChat.getCurrentlyJoinedChatRooms())
room.addMessageListener(this);
opSetMultiUChat.addPresenceListener(this);
}
else
{
logger.trace("Service did not have a multi im op. set.");
}
}
/**
* Removes the specified provider from the list of currently known providers
* and ignores all the messages exchanged by it
*
* @param provider the ProtocolProviderService that has been unregistered.
*/
private void handleProviderRemoved(ProtocolProviderService provider)
{
OperationSetBasicInstantMessaging opSetIm
= provider.getOperationSet(OperationSetBasicInstantMessaging.class);
if (opSetIm != null)
{
opSetIm.removeMessageListener(this);
}
OperationSetMultiUserChat opSetMultiUChat
= provider.getOperationSet(OperationSetMultiUserChat.class);
if (opSetMultiUChat != null)
{
for (ChatRoom room : opSetMultiUChat.getCurrentlyJoinedChatRooms())
room.removeMessageListener(this);
}
}
/**
* Called to notify interested parties that a change in our presence in
* a chat room has occurred. Changes may include us being kicked, join,
* left.
* @param evt the <tt>LocalUserChatRoomPresenceChangeEvent</tt> instance
* containing the chat room and the type, and reason of the change
*/
public void localUserPresenceChanged(LocalUserChatRoomPresenceChangeEvent evt)
{
if(evt.getEventType() ==
LocalUserChatRoomPresenceChangeEvent.LOCAL_USER_JOINED)
{
if (!evt.getChatRoom().isSystem())
evt.getChatRoom().addMessageListener(this);
}
else
{
evt.getChatRoom().removeMessageListener(this);
}
}
public void messageReceived(MessageReceivedEvent evt)
{
alertChatWindow();
}
public void messageDelivered(MessageDeliveredEvent evt)
{
// do nothing
}
public void messageDeliveryFailed(MessageDeliveryFailedEvent evt)
{
// do nothing
}
public void messageReceived(ChatRoomMessageReceivedEvent evt)
{
alertChatWindow();
}
public void messageDelivered(ChatRoomMessageDeliveredEvent evt)
{
// do nothing
}
public void messageDeliveryFailed(ChatRoomMessageDeliveryFailedEvent evt)
{
// do nothing
}
/**
* Alerts that a message has been received in
* <code>ExportedWindow.CHAT_WINDOW</code> by using a platform-dependent
* visual clue such as flashing it in the task bar on Windows and Linux.
*/
private void alertChatWindow()
{
try
{
ExportedWindow win
= uiService.getExportedWindow(ExportedWindow.CHAT_WINDOW);
if (win == null)
return;
Object winSource = win.getSource();
if (!(winSource instanceof JFrame))
return;
JFrame fr = (JFrame) winSource;
Alerter.newInstance().alert(fr);
}
catch (Exception ex)
{
logger.error("Cannot alert chat window!");
}
}
/**
* When new protocol provider is registered we check
* does it supports needed Op. Sets and if so add a listener to it
*
* @param serviceEvent ServiceEvent
*/
public void serviceChanged(ServiceEvent serviceEvent)
{
Object sService
= bundleContext.getService(serviceEvent.getServiceReference());
logger.trace("Received a service event for: " +
sService.getClass().getName());
// we don't care if the source service is not a protocol provider
if (!(sService instanceof ProtocolProviderService))
return;
logger.debug("Service is a protocol provider.");
switch (serviceEvent.getType())
{
case ServiceEvent.REGISTERED:
this.handleProviderAdded((ProtocolProviderService)sService);
break;
case ServiceEvent.UNREGISTERING:
this.handleProviderRemoved( (ProtocolProviderService) sService);
break;
}
}
public void messageDelivered(AdHocChatRoomMessageDeliveredEvent evt)
{
@ -377,4 +373,4 @@ public void localUserAdHocPresenceChanged(
evt.getAdHocChatRoom().removeMessageListener(this);
}
}
}
}

@ -349,8 +349,7 @@ public void handleProviderAdded(ProtocolProviderService provider)
// check whether the provider has a basic telephony operation set
OperationSetBasicTelephony opSetTelephony =
(OperationSetBasicTelephony) provider
.getOperationSet(OperationSetBasicTelephony.class);
provider.getOperationSet(OperationSetBasicTelephony.class);
if (opSetTelephony != null)
{
@ -360,7 +359,6 @@ public void handleProviderAdded(ProtocolProviderService provider)
{
logger.trace("Service did not have a basic telephony op. set.");
}
}
/**
@ -372,8 +370,7 @@ public void handleProviderAdded(ProtocolProviderService provider)
private void handleProviderRemoved(ProtocolProviderService provider)
{
OperationSetBasicTelephony opSetTelephony =
(OperationSetBasicTelephony) provider
.getOperationSet(OperationSetBasicTelephony.class);
provider.getOperationSet(OperationSetBasicTelephony.class);
if (opSetTelephony != null)
{
@ -574,9 +571,9 @@ private void waitForCallEnd(Call call)
private void answerCall(Call call)
{
OperationSetBasicTelephony telephony
= (OperationSetBasicTelephony)call
.getProtocolProvider().getOperationSet(
OperationSetBasicTelephony.class);
= call
.getProtocolProvider()
.getOperationSet(OperationSetBasicTelephony.class);
Iterator peers = call.getCallPeers();
while(peers.hasNext())
@ -607,9 +604,9 @@ private void answerCall(Call call)
private void hangupCall(Call call)
{
OperationSetBasicTelephony telephony
= (OperationSetBasicTelephony)call
.getProtocolProvider().getOperationSet(
OperationSetBasicTelephony.class);
= call
.getProtocolProvider()
.getOperationSet(OperationSetBasicTelephony.class);
logger.info("Max Message Length Reached, Mailbox is"
+" disconnecting the call");
Iterator<? extends CallPeer> callPeers = call.getCallPeers();

@ -176,8 +176,8 @@ public void start(BundleContext bc) throws Exception
private void handleProviderAdded(ProtocolProviderService provider)
{
OperationSetInstantMessageTransform opSetMessageTransform =
(OperationSetInstantMessageTransform) provider
OperationSetInstantMessageTransform opSetMessageTransform
= provider
.getOperationSet(OperationSetInstantMessageTransform.class);
if (opSetMessageTransform != null)
@ -244,8 +244,8 @@ public void stop(BundleContext bc) throws Exception
private void handleProviderRemoved(ProtocolProviderService provider)
{
// check whether the provider has a basic im operation set
OperationSetInstantMessageTransform opSetMessageTransform =
(OperationSetInstantMessageTransform) provider
OperationSetInstantMessageTransform opSetMessageTransform
= provider
.getOperationSet(OperationSetInstantMessageTransform.class);
if (opSetMessageTransform != null)

@ -109,8 +109,7 @@ public static List<OperationSetWhiteboarding> getWhiteboardOperationSets()
= (ProtocolProviderService) bundleContext.getService(serRef);
OperationSetWhiteboarding opSet
= (OperationSetWhiteboarding)
protocolProvider
= protocolProvider
.getOperationSet(OperationSetWhiteboarding.class);
if(opSet != null)

@ -59,9 +59,10 @@ public WhiteboardSessionManager()
*/
public void initWhiteboard (final Contact contact)
{
opSetWb = (OperationSetWhiteboarding)
contact.getProtocolProvider().
getOperationSet(OperationSetWhiteboarding.class);
opSetWb
= contact
.getProtocolProvider()
.getOperationSet(OperationSetWhiteboarding.class);
if (opSetWb == null)
{

@ -46,7 +46,7 @@ protected void setUp() throws Exception
fixture.setUp();
OperationSetPersistentPresence opSetPresence =
(OperationSetPersistentPresence) fixture.mockProvider
fixture.mockProvider
.getOperationSet(OperationSetPersistentPresence.class);
mockGroup = (MockContactGroup)opSetPresence

@ -190,8 +190,8 @@ public void testPartialContactListRestauration()
//verify that contents of the meta contact list matches contents of
//the mock provider we removed.
ContactGroup oldProtoRoot =
((OperationSetPersistentPresence) fixture.mockProvider
.getOperationSet(OperationSetPersistentPresence.class))
fixture.mockProvider
.getOperationSet(OperationSetPersistentPresence.class)
.getServerStoredContactListRoot();
fixture.assertGroupEquals(
@ -203,8 +203,8 @@ public void testPartialContactListRestauration()
//verify that the new mock provider has created unresolved contacts
//for all contacts in the meta cl.
ContactGroup newProtoRoot =
((OperationSetPersistentPresence) fixture.replacementMockPr
.getOperationSet(OperationSetPersistentPresence.class))
fixture.replacementMockPr
.getOperationSet(OperationSetPersistentPresence.class)
.getServerStoredContactListRoot();
assertEquals("Newly loaded provider does not match the old one."
@ -240,21 +240,21 @@ public void testCompleteContactListRestauration()
//Get references to the root groups of the 2 providers we removed
ContactGroup oldProtoMockP1Root =
((OperationSetPersistentPresence) fixture.mockP1
.getOperationSet(OperationSetPersistentPresence.class))
fixture.mockP1
.getOperationSet(OperationSetPersistentPresence.class)
.getServerStoredContactListRoot();
ContactGroup oldProtoMockP2Root =
((OperationSetPersistentPresence) fixture.mockP2
.getOperationSet(OperationSetPersistentPresence.class))
fixture.mockP2
.getOperationSet(OperationSetPersistentPresence.class)
.getServerStoredContactListRoot();
//verify that contacts tnat unresolved contacts that have been created
//inside that the replacement mock providers match those in the
//providers we removed.
ContactGroup newProtoMockP1Root =
((OperationSetPersistentPresence) fixture.replacementMockP1
.getOperationSet(OperationSetPersistentPresence.class))
fixture.replacementMockP1
.getOperationSet(OperationSetPersistentPresence.class)
.getServerStoredContactListRoot();
assertEquals("Newly loaded provider does not match the old one."
@ -262,8 +262,8 @@ public void testCompleteContactListRestauration()
, newProtoMockP1Root);
ContactGroup newProtoMockP2Root =
((OperationSetPersistentPresence) fixture.replacementMockP2
.getOperationSet(OperationSetPersistentPresence.class))
fixture.replacementMockP2
.getOperationSet(OperationSetPersistentPresence.class)
.getServerStoredContactListRoot();
assertEquals("Newly loaded provider does not match the old one."

@ -74,7 +74,7 @@ private Message createMessage(Contact contact, Message message,
String action)
{
OperationSetBasicInstantMessaging imOpSet =
(OperationSetBasicInstantMessaging) contact.getProtocolProvider()
contact.getProtocolProvider()
.getOperationSet(OperationSetBasicInstantMessaging.class);
return imOpSet.createMessage("__" + action + "__"
+ message.getContent());

@ -147,8 +147,7 @@ public void testRegister()
// This message is supposed to be offline message and as one is tested
// in TestOperationSetBasicInstantMessaging.testReceiveOfflineMessages()
OperationSetBasicInstantMessaging opSetBasicIM =
(OperationSetBasicInstantMessaging) fixture.provider
.getOperationSet(OperationSetBasicInstantMessaging.class);
fixture.provider.getOperationSet(OperationSetBasicInstantMessaging.class);
fixture.offlineMsgCollector.register(opSetBasicIM);
//give time for the AIM server to notify everyone of our arrival

@ -70,10 +70,10 @@ public void testCreateCancelCall()
throws ParseException, OperationFailedException
{
OperationSetBasicTelephony basicTelephonyP1
= (OperationSetBasicTelephony)fixture.provider1.getOperationSet(
= fixture.provider1.getOperationSet(
OperationSetBasicTelephony.class);
OperationSetBasicTelephony basicTelephonyP2
= (OperationSetBasicTelephony)fixture.provider2.getOperationSet(
= fixture.provider2.getOperationSet(
OperationSetBasicTelephony.class);
CallEventCollector call1Listener
@ -300,10 +300,10 @@ public void testCreateRejectCall()
throws ParseException, OperationFailedException
{
OperationSetBasicTelephony basicTelephonyP1
= (OperationSetBasicTelephony)fixture.provider1.getOperationSet(
= fixture.provider1.getOperationSet(
OperationSetBasicTelephony.class);
OperationSetBasicTelephony basicTelephonyP2
= (OperationSetBasicTelephony)fixture.provider2.getOperationSet(
= fixture.provider2.getOperationSet(
OperationSetBasicTelephony.class);
CallEventCollector call1Listener
@ -537,10 +537,10 @@ public void aTestCreateAnswerHangupCall()
throws ParseException, OperationFailedException
{
OperationSetBasicTelephony basicTelephonyP1
= (OperationSetBasicTelephony)fixture.provider1.getOperationSet(
= fixture.provider1.getOperationSet(
OperationSetBasicTelephony.class);
OperationSetBasicTelephony basicTelephonyP2
= (OperationSetBasicTelephony)fixture.provider2.getOperationSet(
= fixture.provider2.getOperationSet(
OperationSetBasicTelephony.class);
CallEventCollector call1Listener

Loading…
Cancel
Save