Jitsi: the OpenSource Java VoIP and Instant Messaging client.

net.java.sip.communicator.service.notification
Class NotificationServiceImpl

java.lang.Object
  extended by net.java.sip.communicator.service.notification.NotificationServiceImpl
All Implemented Interfaces:
NotificationService

 class NotificationServiceImpl
extends Object
implements NotificationService

The implementation of the NotificationService.

Author:
Yana Stamcheva, Ingo Bauersachs

Constructor Summary
NotificationServiceImpl()
          Creates an instance of NotificationServiceImpl by loading all previously saved notifications.
 
Method Summary
 void addActionHandler(NotificationHandler handler)
          Adds an object that executes the actual action of a notification action.
 void addNotificationChangeListener(NotificationChangeListener listener)
          Adds the given listener to the list of change listeners.
 NotificationData fireNotification(String eventType)
          If there is a registered event notification of the given eventType and the event notification is currently activated, we go through the list of registered actions and execute them.
 NotificationData fireNotification(String eventType, String title, String message, byte[] icon, Object tag)
          If there is a registered event notification of the given eventType and the event notification is currently activated, the list of registered actions is executed.
 NotificationData fireNotification(String eventType, String title, String message, Map<String,String> extra, byte[] icon, Object tag)
          If there is a registered event notification of the given eventType and the event notification is currently activated, the list of registered actions is executed.
 Iterable<NotificationHandler> getActionHandlers(String actionType)
          Gets a list of handler for the specified action type.
 NotificationAction getEventNotificationAction(String eventType, String actionType)
          Returns the notification action corresponding to the given eventType and actionType.
 Iterable<String> getRegisteredEvents()
          Returns an iterator over a list of all events registered in this notification service.
 boolean isActive(String eventType)
          Finds the EventNotification corresponding to the given eventType and returns its isActive status.
 void registerDefaultNotificationForEvent(String eventType, NotificationAction action)
          Creates a new default EventNotification or obtains the corresponding existing one and registers a new action in it.
 void registerDefaultNotificationForEvent(String eventType, String actionType, String actionDescriptor, String defaultMessage)
          Creates a new default EventNotification or obtains the corresponding existing one and registers a new action in it.
 void registerNotificationForEvent(String eventType, NotificationAction action)
          Creates a new EventNotification or obtains the corresponding existing one and registers a new action in it.
 void registerNotificationForEvent(String eventType, String actionType, String actionDescriptor, String defaultMessage)
          Creates a new EventNotification or obtains the corresponding existing one and registers a new action in it.
 void removeActionHandler(String actionType)
          Removes an object that executes the actual action of notification action.
 void removeEventNotification(String eventType)
          Removes the EventNotification corresponding to the given eventType from the table of registered event notifications.
 void removeEventNotificationAction(String eventType, String actionType)
          Removes the given actionType from the list of actions registered for the given eventType.
 void removeNotificationChangeListener(NotificationChangeListener listener)
          Removes the given listener from the list of change listeners.
 void restoreDefaults()
          Deletes all registered events and actions and registers and saves the default events as current.
 void setActive(String eventType, boolean isActive)
          Finds the EventNotification corresponding to the given eventType and marks it as activated/deactivated.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

NotificationServiceImpl

NotificationServiceImpl()
Creates an instance of NotificationServiceImpl by loading all previously saved notifications.

Method Detail

registerNotificationForEvent

public void registerNotificationForEvent(String eventType,
                                         NotificationAction action)
Creates a new EventNotification or obtains the corresponding existing one and registers a new action in it.

Specified by:
registerNotificationForEvent in interface NotificationService
Parameters:
eventType - the name of the event (as defined by the plugin that's registering it) that we are setting an action for.
action - the NotificationAction responsible for handling the given actionType

registerNotificationForEvent

public void registerNotificationForEvent(String eventType,
                                         String actionType,
                                         String actionDescriptor,
                                         String defaultMessage)
Creates a new EventNotification or obtains the corresponding existing one and registers a new action in it.

Specified by:
registerNotificationForEvent in interface NotificationService
Parameters:
eventType - the name of the event (as defined by the plugin that's registering it) that we are setting an action for.
actionType - the type of the action that is to be executed when the specified event occurs (could be one of the ACTION_XXX fields).
actionDescriptor - a String containing a description of the action (a URI to the sound file for audio notifications or a command line for exec action types) that should be executed when the action occurs.
defaultMessage - the default message to use if no specific message has been provided when firing the notification.

removeEventNotification

public void removeEventNotification(String eventType)
Removes the EventNotification corresponding to the given eventType from the table of registered event notifications.

Specified by:
removeEventNotification in interface NotificationService
Parameters:
eventType - the name of the event (as defined by the plugin that's registering it) to be removed.

removeEventNotificationAction

public void removeEventNotificationAction(String eventType,
                                          String actionType)
Removes the given actionType from the list of actions registered for the given eventType.

Specified by:
removeEventNotificationAction in interface NotificationService
Parameters:
eventType - the name of the event (as defined by the plugin that's registering it) for which we'll remove the notification.
actionType - the type of the action that is to be executed when the specified event occurs (could be one of the ACTION_XXX fields).

getRegisteredEvents

public Iterable<String> getRegisteredEvents()
Returns an iterator over a list of all events registered in this notification service. Each line in the returned list consists of a String, representing the name of the event (as defined by the plugin that registered it).

Specified by:
getRegisteredEvents in interface NotificationService
Returns:
an iterator over a list of all events registered in this notifications service

getEventNotificationAction

public NotificationAction getEventNotificationAction(String eventType,
                                                     String actionType)
Returns the notification action corresponding to the given eventType and actionType.

Specified by:
getEventNotificationAction in interface NotificationService
Parameters:
eventType - the type of the event that we'd like to retrieve.
actionType - the type of the action that we'd like to retrieve a descriptor for.
Returns:
the notification action of the action to be executed when an event of the specified type has occurred.

addNotificationChangeListener

public void addNotificationChangeListener(NotificationChangeListener listener)
Adds the given listener to the list of change listeners.

Specified by:
addNotificationChangeListener in interface NotificationService
Parameters:
listener - the listener that we'd like to register to listen for changes in the event notifications stored by this service.

removeNotificationChangeListener

public void removeNotificationChangeListener(NotificationChangeListener listener)
Removes the given listener from the list of change listeners.

Specified by:
removeNotificationChangeListener in interface NotificationService
Parameters:
listener - the listener that we'd like to remove

addActionHandler

public void addActionHandler(NotificationHandler handler)
Adds an object that executes the actual action of a notification action. If the same action type is added twice, the last added wins.

Specified by:
addActionHandler in interface NotificationService
Parameters:
handler - The handler that executes the action.

removeActionHandler

public void removeActionHandler(String actionType)
Removes an object that executes the actual action of notification action.

Specified by:
removeActionHandler in interface NotificationService
Parameters:
actionType - The handler type to remove.

getActionHandlers

public Iterable<NotificationHandler> getActionHandlers(String actionType)
Gets a list of handler for the specified action type.

Specified by:
getActionHandlers in interface NotificationService
Parameters:
actionType - the type for which the list of handlers should be retrieved or null if all handlers shall be returned.
Returns:
Iterable of NotificationHandler objects

fireNotification

public NotificationData fireNotification(String eventType,
                                         String title,
                                         String message,
                                         byte[] icon,
                                         Object tag)
If there is a registered event notification of the given eventType and the event notification is currently activated, the list of registered actions is executed.

Specified by:
fireNotification in interface NotificationService
Parameters:
eventType - the type of the event that we'd like to fire a notification for.
title - the title of the given message
message - the message to use if and where appropriate (e.g. with systray or log notification.)
icon - the icon to show in the notification if and where appropriate
tag - additional info to be used by the notification handler
Returns:
An object referencing the notification. It may be used to stop a still running notification. Can be null if the eventType is unknown or the notification is not active.

fireNotification

public NotificationData fireNotification(String eventType,
                                         String title,
                                         String message,
                                         Map<String,String> extra,
                                         byte[] icon,
                                         Object tag)
If there is a registered event notification of the given eventType and the event notification is currently activated, the list of registered actions is executed.

Specified by:
fireNotification in interface NotificationService
Parameters:
eventType - the type of the event that we'd like to fire a notification for.
title - the title of the given message
message - the message to use if and where appropriate (e.g. with systray or log notification.)
extra - the extra data to pass (especially for Command execution)
icon - the icon to show in the notification if and where appropriate
tag - additional info to be used by the notification handler
Returns:
An object referencing the notification. It may be used to stop a still running notification. Can be null if the eventType is unknown or the notification is not active.

fireNotification

public NotificationData fireNotification(String eventType)
If there is a registered event notification of the given eventType and the event notification is currently activated, we go through the list of registered actions and execute them.

Specified by:
fireNotification in interface NotificationService
Parameters:
eventType - the type of the event that we'd like to fire a notification for.
Returns:
An object referencing the notification. It may be used to stop a still running notification. Can be null if the eventType is unknown or the notification is not active.

setActive

public void setActive(String eventType,
                      boolean isActive)
Finds the EventNotification corresponding to the given eventType and marks it as activated/deactivated.

Specified by:
setActive in interface NotificationService
Parameters:
eventType - the name of the event, which actions should be activated /deactivated.
isActive - indicates whether to activate or deactivate the actions related to the specified eventType.

isActive

public boolean isActive(String eventType)
Finds the EventNotification corresponding to the given eventType and returns its isActive status.

Specified by:
isActive in interface NotificationService
Parameters:
eventType - the name of the event (as defined by the plugin that's registered it) that we are checking.
Returns:
true if actions for the specified eventType are activated, false - otherwise. If the given eventType is not contained in the list of registered event types - returns false.

registerDefaultNotificationForEvent

public void registerDefaultNotificationForEvent(String eventType,
                                                NotificationAction action)
Creates a new default EventNotification or obtains the corresponding existing one and registers a new action in it.

Specified by:
registerDefaultNotificationForEvent in interface NotificationService
Parameters:
eventType - the name of the event (as defined by the plugin that's registering it) that we are setting an action for.
action - the NotificationAction to register

registerDefaultNotificationForEvent

public void registerDefaultNotificationForEvent(String eventType,
                                                String actionType,
                                                String actionDescriptor,
                                                String defaultMessage)
Creates a new default EventNotification or obtains the corresponding existing one and registers a new action in it.

Specified by:
registerDefaultNotificationForEvent in interface NotificationService
Parameters:
eventType - the name of the event (as defined by the plugin that's registering it) that we are setting an action for.
actionType - the type of the action that is to be executed when the specified event occurs (could be one of the ACTION_XXX fields).
actionDescriptor - a String containing a description of the action (a URI to the sound file for audio notifications or a command line for exec action types) that should be executed when the action occurs.
defaultMessage - the default message to use if no specific message has been provided when firing the notification.

restoreDefaults

public void restoreDefaults()
Deletes all registered events and actions and registers and saves the default events as current.

Specified by:
restoreDefaults in interface NotificationService

Jitsi: the OpenSource Java VoIP and Instant Messaging client.

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