Jitsi: the OpenSource Java VoIP and Instant Messaging client.

net.java.sip.communicator.impl.protocol.mock
Class MockChatRoom

java.lang.Object
  extended by net.java.sip.communicator.impl.protocol.mock.MockChatRoom
All Implemented Interfaces:
ChatRoom

public class MockChatRoom
extends Object
implements ChatRoom

Author:
Damian Minkov

Constructor Summary
MockChatRoom(MockProvider provider, MockMultiUserChat parentOpSet, String roomName)
          Creates an instance of MockChatRoom by specifying the corresponding protocol provider, the multi user chat operation set and the room name.
 
Method Summary
 void addLocalUserRoleListener(ChatRoomLocalUserRoleListener listener)
          Adds a listener that will be notified of changes in our role in the room such as us being granded operator.
 void addMemberPresenceListener(ChatRoomMemberPresenceListener listener)
          Adds a listener that will be notified of changes in our participation in the room such as us being kicked, join, left...
 void addMemberPropertyChangeListener(ChatRoomMemberPropertyChangeListener listener)
          Adds a listener that will be notified of changes in the property of a room member such as the nickname being changed.
 void addMemberRoleListener(ChatRoomMemberRoleListener listener)
          Adds a listener that will be notified of changes of a member role in the room such as being granded operator.
 void addMessageListener(ChatRoomMessageListener listener)
          Registers listener so that it would receive events every time a new message is received on this chat room.
 void addPropertyChangeListener(ChatRoomPropertyChangeListener listener)
          Adds a listener that will be notified of changes in the property of the room such as the subject being change or the room state being changed.
 void banParticipant(ChatRoomMember chatRoomMember, String reason)
          Bans a user from the room.
 Message createMessage(byte[] content, String contentType, String contentEncoding, String subject)
          Create a Message instance for sending arbitrary MIME-encoding content.
 Message createMessage(String messageText)
          Create a Message instance for sending a simple text messages with default (text/plain) content type and encoding.
 void deliverMessage(Message msg, String from)
          Methods for manipulating mock operation set as deliver(receive) messageop
 Iterator<ChatRoomMember> getBanList()
          Returns an Iterator over a set of ban masks for this chat room.
 ChatRoomConfigurationForm getConfigurationForm()
          Returns the ChatRoomConfigurationForm containing all configuration properties for this chat room.
 String getIdentifier()
          Returns the identifier of this ChatRoom.
 List<ChatRoomMember> getMembers()
          Returns a List of ChatRoomMembers corresponding to all members currently participating in this room.
 int getMembersCount()
          Returns the number of participants that are currently in this chat room.
 String getName()
          Returns the name of this ChatRoom.
 ProtocolProviderService getParentProvider()
          Returns a reference to the provider that created this room.
 String getSubject()
          Returns the last known room subject/theme or null if the user hasn't joined the room or the room does not have a subject yet.
 String getUserNickname()
          Returns the local user's nickname in the context of this chat room or null if not currently joined.
 ChatRoomMemberRole getUserRole()
          Returns the local user role.
 void grantAdmin(String address)
          Grants admin role to the participant given by address.
 void grantMembership(String address)
          Grants membership role to the participant given by address.
 void grantModerator(String address)
          Grants moderator role to the participant given by address.
 void grantOwnership(String address)
          Grants ownership role to the participant given by address.
 void grantVoice(String address)
          Grants voice to the participant given by address.
 void invite(String userAddress, String reason)
          Invites another user to this room.
 boolean isJoined()
          Returns true if the local user is currently in the multi user chat (after calling one of the join() methods).
 boolean isPersistent()
          Determines whether this chat room should be stored in the configuration file or not.
 boolean isSystem()
          Returns true if this chat room is a system room and false otherwise.
 void join()
          Joins this chat room with the nickname of the local user so that the user would start receiving events and messages for it.
 void join(byte[] password)
          Joins this chat room so that the user would start receiving events and messages for it.
 void joinAs(String nickname)
          Joins this chat room with the specified nickname so that the user would start receiving events and messages for it.
 void joinAs(String nickname, byte[] password)
          Joins this chat room with the specified nickname and password so that the user would start receiving events and messages for it.
 void kickParticipant(ChatRoomMember chatRoomMember, String reason)
          Kicks a visitor or participant from the room.
 void leave()
          Leave this chat room.
 void removelocalUserRoleListener(ChatRoomLocalUserRoleListener listener)
          Removes a listener that was being notified of changes in our role in this chat room such as us being granded operator.
 void removeMemberPresenceListener(ChatRoomMemberPresenceListener listener)
          Removes a listener that was being notified of changes in the participation of other chat room participants such as users being kicked, join, left.
 void removeMemberPropertyChangeListener(ChatRoomMemberPropertyChangeListener listener)
          Removes a listener that was being notified of changes in the property of a chat room member such as the nickname being changed.
 void removeMemberRoleListener(ChatRoomMemberRoleListener listener)
          Removes a listener that was being notified of changes of a member role in this chat room such as us being granded operator.
 void removeMessageListener(ChatRoomMessageListener listener)
          Removes listener so that it won't receive any further message events from this room.
 void removePropertyChangeListener(ChatRoomPropertyChangeListener listener)
          Removes a listener that was being notified of changes in the property of the chat room such as the subject being change or the room state being changed.
 void revokeAdmin(String address)
          Revokes the admin role for the participant given by address.
 void revokeMembership(String address)
          Revokes the membership role for the participant given by address.
 void revokeModerator(String address)
          Revokes the moderator role for the participant given by address.
 void revokeOwnership(String address)
          Revokes the ownership role for the participant given by address.
 void revokeVoice(String address)
          Revokes the voice for the participant given by address.
 void sendMessage(Message message)
          Sends the message to the destination indicated by the to contact.
 void setLocalUserRole(ChatRoomMemberRole role)
          Sets the local user role.
 void setNickname(String nickname)
          Changes the the local user's nickname in the context of this chatroom.
 void setSubject(String subject)
          Sets the subject of this chat room.
 void setUserNickname(String nickname)
          Changes the the local user's nickname in the context of this chatroom.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MockChatRoom

public MockChatRoom(MockProvider provider,
                    MockMultiUserChat parentOpSet,
                    String roomName)
Creates an instance of MockChatRoom by specifying the corresponding protocol provider, the multi user chat operation set and the room name.

Parameters:
provider - the corresponding ProtocolProviderService
parentOpSet - the corresponding OperationSetMultiUserChat
roomName - the name of the room
Method Detail

getName

public String getName()
Returns the name of this ChatRoom.

Specified by:
getName in interface ChatRoom
Returns:
a String containing the name of this ChatRoom.

join

public void join()
          throws OperationFailedException
Joins this chat room with the nickname of the local user so that the user would start receiving events and messages for it.

Specified by:
join in interface ChatRoom
Throws:
OperationFailedException - with the corresponding code if an error occurs while joining the room.

join

public void join(byte[] password)
          throws OperationFailedException
Joins this chat room so that the user would start receiving events and messages for it. The method uses the nickname of the local user and the specified password in order to enter the chatroom.

Specified by:
join in interface ChatRoom
Parameters:
password - the password to use when authenticating on the chatroom.
Throws:
OperationFailedException - with the corresponding code if an error occurs while joining the room.

joinAs

public void joinAs(String nickname)
            throws OperationFailedException
Joins this chat room with the specified nickname so that the user would start receiving events and messages for it. If the chatroom already contains a user with this nickname, the method would throw an OperationFailedException with code IDENTIFICATION_CONFLICT.

Specified by:
joinAs in interface ChatRoom
Parameters:
nickname - the nickname to use.
Throws:
OperationFailedException - with the corresponding code if an error occurs while joining the room.

joinAs

public void joinAs(String nickname,
                   byte[] password)
            throws OperationFailedException
Joins this chat room with the specified nickname and password so that the user would start receiving events and messages for it. If the chatroom already contains a user with this nickname, the method would throw an OperationFailedException with code IDENTIFICATION_CONFLICT.

Specified by:
joinAs in interface ChatRoom
Parameters:
nickname - the nickname to use.
password - a password necessary to authenticate when joining the room.
Throws:
OperationFailedException - with the corresponding code if an error occurs while joining the room.

isJoined

public boolean isJoined()
Returns true if the local user is currently in the multi user chat (after calling one of the join() methods).

Specified by:
isJoined in interface ChatRoom
Returns:
true if currently we're currently in this chat room and false otherwise.

leave

public void leave()
Leave this chat room. Once this method is called, the user won't be listed as a member of the chat room any more and no further chat events will be delivered. Depending on the underlying protocol and implementation leave() might cause the room to be destroyed if it has been created by the local user.

Specified by:
leave in interface ChatRoom

getSubject

public String getSubject()
Returns the last known room subject/theme or null if the user hasn't joined the room or the room does not have a subject yet.

To be notified every time the room's subject change you should add a ChatRoomChangelistener to this room. addPropertyChangeListener(ChatRoomPropertyChangeListener)

To change the room's subject use setSubject(String).

Specified by:
getSubject in interface ChatRoom
Returns:
the room subject or null if the user hasn't joined the room or the room does not have a subject yet.

setSubject

public void setSubject(String subject)
                throws OperationFailedException
Sets the subject of this chat room. If the user does not have the right to change the room subject, or the protocol does not support this, or the operation fails for some other reason, the method throws an OperationFailedException with the corresponding code.

Specified by:
setSubject in interface ChatRoom
Parameters:
subject - the new subject that we'd like this room to have
Throws:
OperationFailedException

getUserNickname

public String getUserNickname()
Returns the local user's nickname in the context of this chat room or null if not currently joined.

Specified by:
getUserNickname in interface ChatRoom
Returns:
the nickname currently being used by the local user in the context of the local chat room.

setNickname

public void setNickname(String nickname)
                 throws OperationFailedException
Changes the the local user's nickname in the context of this chatroom. If the operation is not supported by the underlying implementation, the method throws an OperationFailedException with the corresponding code.

Parameters:
nickname - the new nickname within the room.
Throws:
OperationFailedException - if the setting the new nickname changes for some reason.

addMemberPresenceListener

public void addMemberPresenceListener(ChatRoomMemberPresenceListener listener)
Adds a listener that will be notified of changes in our participation in the room such as us being kicked, join, left...

Specified by:
addMemberPresenceListener in interface ChatRoom
Parameters:
listener - a member participation listener.

removeMemberPresenceListener

public void removeMemberPresenceListener(ChatRoomMemberPresenceListener listener)
Removes a listener that was being notified of changes in the participation of other chat room participants such as users being kicked, join, left.

Specified by:
removeMemberPresenceListener in interface ChatRoom
Parameters:
listener - a member participation listener.

addLocalUserRoleListener

public void addLocalUserRoleListener(ChatRoomLocalUserRoleListener listener)
Adds a listener that will be notified of changes in our role in the room such as us being granded operator.

Specified by:
addLocalUserRoleListener in interface ChatRoom
Parameters:
listener - a local user role listener.

removelocalUserRoleListener

public void removelocalUserRoleListener(ChatRoomLocalUserRoleListener listener)
Removes a listener that was being notified of changes in our role in this chat room such as us being granded operator.

Specified by:
removelocalUserRoleListener in interface ChatRoom
Parameters:
listener - a local user role listener.

addMemberRoleListener

public void addMemberRoleListener(ChatRoomMemberRoleListener listener)
Adds a listener that will be notified of changes of a member role in the room such as being granded operator.

Specified by:
addMemberRoleListener in interface ChatRoom
Parameters:
listener - a member role listener.

removeMemberRoleListener

public void removeMemberRoleListener(ChatRoomMemberRoleListener listener)
Removes a listener that was being notified of changes of a member role in this chat room such as us being granded operator.

Specified by:
removeMemberRoleListener in interface ChatRoom
Parameters:
listener - a member role listener.

addPropertyChangeListener

public void addPropertyChangeListener(ChatRoomPropertyChangeListener listener)
Adds a listener that will be notified of changes in the property of the room such as the subject being change or the room state being changed.

Specified by:
addPropertyChangeListener in interface ChatRoom
Parameters:
listener - a property change listener.

removePropertyChangeListener

public void removePropertyChangeListener(ChatRoomPropertyChangeListener listener)
Removes a listener that was being notified of changes in the property of the chat room such as the subject being change or the room state being changed.

Specified by:
removePropertyChangeListener in interface ChatRoom
Parameters:
listener - a property change listener.

invite

public void invite(String userAddress,
                   String reason)
Invites another user to this room.

If the room is password-protected, the invitee will receive a password to use to join the room. If the room is members-only, the the invitee may be added to the member list.

Specified by:
invite in interface ChatRoom
Parameters:
userAddress - the address of the user to invite to the room.(one may also invite users not on their contact list).
reason - a reason, subject, or welcome message that would tell the the user why they are being invited.

getMembers

public List<ChatRoomMember> getMembers()
Returns a List of ChatRoomMembers corresponding to all members currently participating in this room.

Specified by:
getMembers in interface ChatRoom
Returns:
a List of ChatRoomMember instances corresponding to all room members.

getMembersCount

public int getMembersCount()
Returns the number of participants that are currently in this chat room.

Specified by:
getMembersCount in interface ChatRoom
Returns:
int the number of Contacts, currently participating in this room.

addMessageListener

public void addMessageListener(ChatRoomMessageListener listener)
Registers listener so that it would receive events every time a new message is received on this chat room.

Specified by:
addMessageListener in interface ChatRoom
Parameters:
listener - a MessageListener that would be notified every time a new message is received on this chat room.

removeMessageListener

public void removeMessageListener(ChatRoomMessageListener listener)
Removes listener so that it won't receive any further message events from this room.

Specified by:
removeMessageListener in interface ChatRoom
Parameters:
listener - the MessageListener to remove from this room

createMessage

public Message createMessage(byte[] content,
                             String contentType,
                             String contentEncoding,
                             String subject)
Create a Message instance for sending arbitrary MIME-encoding content.

Specified by:
createMessage in interface ChatRoom
Parameters:
content - content value
contentType - the MIME-type for content
contentEncoding - encoding used for content
subject - a String subject or null for now subject.
Returns:
the newly created message.

createMessage

public Message createMessage(String messageText)
Create a Message instance for sending a simple text messages with default (text/plain) content type and encoding.

Specified by:
createMessage in interface ChatRoom
Parameters:
messageText - the string content of the message.
Returns:
Message the newly created message

sendMessage

public void sendMessage(Message message)
                 throws OperationFailedException
Sends the message to the destination indicated by the to contact.

Specified by:
sendMessage in interface ChatRoom
Parameters:
message - the Message to send.
Throws:
OperationFailedException - if sending the message fails for some reason.

getParentProvider

public ProtocolProviderService getParentProvider()
Returns a reference to the provider that created this room.

Specified by:
getParentProvider in interface ChatRoom
Returns:
a reference to the ProtocolProviderService instance that created this room.

getBanList

public Iterator<ChatRoomMember> getBanList()
Returns an Iterator over a set of ban masks for this chat room. The ban mask defines a group of users that will be banned. The ban list is a list of all such ban masks defined for this chat room.

Specified by:
getBanList in interface ChatRoom
Returns:
an Iterator over a set of ban masks for this chat room

deliverMessage

public void deliverMessage(Message msg,
                           String from)
Methods for manipulating mock operation set as deliver(receive) messageop

Parameters:
msg - the message that we are to deliver.
from - delivered from

setUserNickname

public void setUserNickname(String nickname)
                     throws OperationFailedException
Changes the the local user's nickname in the context of this chatroom. If the operation is not supported by the underlying implementation, the method throws an OperationFailedException with the corresponding code.

Specified by:
setUserNickname in interface ChatRoom
Parameters:
nickname - the new nickname within the room.
Throws:
OperationFailedException - if the setting the new nickname changes for some reason.

getIdentifier

public String getIdentifier()
Returns the identifier of this ChatRoom. The identifier of the chat room would have the following syntax: [chatRoomName]@[chatRoomServer]@[accountID]

Specified by:
getIdentifier in interface ChatRoom
Returns:
a String containing the identifier of this ChatRoom.

banParticipant

public void banParticipant(ChatRoomMember chatRoomMember,
                           String reason)
                    throws OperationFailedException
Bans a user from the room. Not implemented for mock chat rooms.

Specified by:
banParticipant in interface ChatRoom
Parameters:
chatRoomMember - the ChatRoomMember to be banned
reason - the reason why the user was banned
Throws:
OperationFailedException - if an error occurs while banning a user

kickParticipant

public void kickParticipant(ChatRoomMember chatRoomMember,
                            String reason)
                     throws OperationFailedException
Kicks a visitor or participant from the room. Not implemented for mock chat rooms.

Specified by:
kickParticipant in interface ChatRoom
Parameters:
chatRoomMember - the ChatRoomMember to kick from the room
reason - the reason why the participant is being kicked from the room
Throws:
OperationFailedException - if an error occurs while kicking the participant

getConfigurationForm

public ChatRoomConfigurationForm getConfigurationForm()
                                               throws OperationFailedException
Returns the ChatRoomConfigurationForm containing all configuration properties for this chat room. Not implemented for mock chat rooms.

Specified by:
getConfigurationForm in interface ChatRoom
Returns:
the ChatRoomConfigurationForm containing all configuration properties for this chat room
Throws:
OperationFailedException - if the user doesn't have permissions to see and change chat room configuration

addMemberPropertyChangeListener

public void addMemberPropertyChangeListener(ChatRoomMemberPropertyChangeListener listener)
Adds a listener that will be notified of changes in the property of a room member such as the nickname being changed.

Specified by:
addMemberPropertyChangeListener in interface ChatRoom
Parameters:
listener - a room member property change listener.

removeMemberPropertyChangeListener

public void removeMemberPropertyChangeListener(ChatRoomMemberPropertyChangeListener listener)
Removes a listener that was being notified of changes in the property of a chat room member such as the nickname being changed.

Specified by:
removeMemberPropertyChangeListener in interface ChatRoom
Parameters:
listener - a room member property change listener.

isSystem

public boolean isSystem()
Returns true if this chat room is a system room and false otherwise.

Specified by:
isSystem in interface ChatRoom
Returns:
true if this chat room is a system room and false otherwise.

isPersistent

public boolean isPersistent()
Determines whether this chat room should be stored in the configuration file or not. If the chat room is persistent it still will be shown after a restart in the chat room list. A non-persistent chat room will be only in the chat room list until the the program is running.

Specified by:
isPersistent in interface ChatRoom
Returns:
true if this chat room is persistent, false otherwise

grantAdmin

public void grantAdmin(String address)
Grants admin role to the participant given by address.

Specified by:
grantAdmin in interface ChatRoom
Parameters:
address - the address of the participant to grant admin role to

grantMembership

public void grantMembership(String address)
Grants membership role to the participant given by address.

Specified by:
grantMembership in interface ChatRoom
Parameters:
address - the address of the participant to grant membership role to

grantModerator

public void grantModerator(String address)
Grants moderator role to the participant given by address.

Specified by:
grantModerator in interface ChatRoom
Parameters:
address - the address of the participant to grant moderator role to

grantOwnership

public void grantOwnership(String address)
Grants ownership role to the participant given by address.

Specified by:
grantOwnership in interface ChatRoom
Parameters:
address - the address of the participant to grant ownership role to

grantVoice

public void grantVoice(String address)
Grants voice to the participant given by address.

Specified by:
grantVoice in interface ChatRoom
Parameters:
address - the address of the participant to grant voice to

revokeAdmin

public void revokeAdmin(String address)
Revokes the admin role for the participant given by address.

Specified by:
revokeAdmin in interface ChatRoom
Parameters:
address - the address of the participant to revoke admin role for

revokeMembership

public void revokeMembership(String address)
Revokes the membership role for the participant given by address.

Specified by:
revokeMembership in interface ChatRoom
Parameters:
address - the address of the participant to revoke membership role for

revokeModerator

public void revokeModerator(String address)
Revokes the moderator role for the participant given by address.

Specified by:
revokeModerator in interface ChatRoom
Parameters:
address - the address of the participant to revoke moderator role for

revokeOwnership

public void revokeOwnership(String address)
Revokes the ownership role for the participant given by address.

Specified by:
revokeOwnership in interface ChatRoom
Parameters:
address - the address of the participant to revoke ownership role for

revokeVoice

public void revokeVoice(String address)
Revokes the voice for the participant given by address.

Specified by:
revokeVoice in interface ChatRoom
Parameters:
address - the address of the participant to revoke voice for

getUserRole

public ChatRoomMemberRole getUserRole()
Returns the local user role.

Specified by:
getUserRole in interface ChatRoom
Returns:
the local user role

setLocalUserRole

public void setLocalUserRole(ChatRoomMemberRole role)
                      throws OperationFailedException
Sets the local user role.

Specified by:
setLocalUserRole in interface ChatRoom
Parameters:
role - the role to set
Throws:
OperationFailedException - if the operation don't succeed

Jitsi: the OpenSource Java VoIP and Instant Messaging client.

Jitsi, the OpenSource Java VoIP and Instant Messaging client.
Distributable under LGPL license.