org.sakaiproject.component.legacy.notification
Class BaseNotificationService

java.lang.Object
  extended byorg.sakaiproject.component.legacy.notification.BaseNotificationService
All Implemented Interfaces:
CacheRefresher, NotificationService, Observer, StorageUser
Direct Known Subclasses:
DbNotificationService

public abstract class BaseNotificationService
extends Object
implements NotificationService, Observer, StorageUser, CacheRefresher

%%%

Version:
$Revision: 6016 $
Author:
University of Michigan, Sakai Software Development Team

Nested Class Summary
 class BaseNotificationService.BaseNotification
          Notification implementation
 class BaseNotificationService.BaseNotificationEdit
          NotificationEdit implementation
protected static interface BaseNotificationService.Storage
          Storage
 
Field Summary
protected  NotificationCache m_cache
          A Cache for this service - Notification objects stored by notification reference.
protected  EventTrackingService m_eventTrackingService
          Dependency: event tracking service
protected  Logger m_logger
          Dependency: logging service
protected  String m_relativeAccessPoint
          The initial portion of a relative access point URL.
protected  BaseNotificationService.Storage m_storage
          Storage manager for this service.
protected  List m_transients
          Transient notifications (NotificationEdit).
 
Fields inherited from interface org.sakaiproject.service.legacy.notification.NotificationService
NOTI_NONE, NOTI_OPTIONAL, NOTI_REQUIRED, PREF_DIGEST, PREF_IGNORE, PREF_IMMEDIATE, PREF_NONE, PREFS_DEFAULT, PREFS_NOTI, PREFS_SITE, PREFS_TYPE, REFERENCE_ROOT, SECURE_ADD_NOTIFICATION, SECURE_REMOVE_NOTIFICATION, SECURE_UPDATE_NOTIFICATION, SERVICE_NAME
 
Constructor Summary
BaseNotificationService()
           
 
Method Summary
 NotificationEdit addNotification()
          Establish a new notification, locked for edit.
 NotificationEdit addTransientNotification()
          Establish a new transient notification.
 void cancelEdit(NotificationEdit notification)
          Cancel the changes made to a NotificationEdit object, and release the lock.
 void commitEdit(NotificationEdit notification)
          Commit the changes made to a NotificationEdit object, and release the lock.
 void destroy()
          Returns to uninitialized state.
 NotificationEdit editNotification(String id)
          Get a locked notification object for editing.
 Notification findNotification(String function, String filter)
          Find a notification object.
protected  String getAccessPoint(boolean relative)
          Access the partial URL that forms the root of resource URLs.
 Time getDate(Entity r)
          Access the resource date.
 Notification getNotification(String id)
          Access a notification object.
 List getNotifications(String function)
          Access all notification objects that are watching this event function.
 String getOwnerId(Entity r)
          Access the resource owner user id.
 void init()
          Final initialization, once all dependencies are set.
 boolean isDraft(Entity r)
          Check if this resource is in draft mode.
protected  boolean match(String filter, String ref)
          Does the resource reference match the filter?
 Entity newContainer(Element element)
          Construct a new container resource, from an XML element.
 Entity newContainer(Entity other)
          Construct a new container resource, as a copy of another
 Entity newContainer(String ref)
          Construct a new continer given just an id.
 Edit newContainerEdit(Element element)
          Construct a new container resource, from an XML element.
 Edit newContainerEdit(Entity other)
          Construct a new container resource, as a copy of another
 Edit newContainerEdit(String ref)
          Construct a new continer given just an id.
 Entity newResource(Entity container, Element element)
          Construct a new resource, from an XML element.
 Entity newResource(Entity container, Entity other)
          Construct a new resource from another resource of the same type.
 Entity newResource(Entity container, String id, Object[] others)
          Construct a new rsource given just an id.
 Edit newResourceEdit(Entity container, Element element)
          Construct a new resource, from an XML element.
 Edit newResourceEdit(Entity container, Entity other)
          Construct a new resource from another resource of the same type.
 Edit newResourceEdit(Entity container, String id, Object[] others)
          Construct a new rsource given just an id.
protected abstract  BaseNotificationService.Storage newStorage()
          Construct storage for this service.
protected  String notificationId(String ref)
          Access the notification id extracted from a notification reference.
 String notificationReference(String id)
          Access the internal reference which can be used to access the resource from within the system.
protected  String notificationUrl(String id)
          Access the external URL which can be used to access the resource from outside the system.
 Object refresh(Object key, Object oldValue, Event event)
          Get a new value for this key whose value has already expired in the cache.
 void removeNotification(NotificationEdit notification)
          Remove this notification - it must be a notification with a lock from editNotification().
 void setEventTrackingService(EventTrackingService service)
          Dependency: event tracking service.
 void setLogger(Logger service)
          Dependency: logging service.
 Object[] storageFields(Entity r)
          Collect the fields that need to be stored outside the XML (for the resource).
 void update(Observable o, Object arg)
          This method is called whenever the observed object is changed.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

m_storage

protected BaseNotificationService.Storage m_storage
Storage manager for this service.


m_cache

protected NotificationCache m_cache
A Cache for this service - Notification objects stored by notification reference.


m_relativeAccessPoint

protected String m_relativeAccessPoint
The initial portion of a relative access point URL.


m_transients

protected List m_transients
Transient notifications (NotificationEdit).


m_logger

protected Logger m_logger
Dependency: logging service


m_eventTrackingService

protected EventTrackingService m_eventTrackingService
Dependency: event tracking service

Constructor Detail

BaseNotificationService

public BaseNotificationService()
Method Detail

newStorage

protected abstract BaseNotificationService.Storage newStorage()
Construct storage for this service.


match

protected boolean match(String filter,
                        String ref)
Does the resource reference match the filter?

Parameters:
filter - The resource reference filter.
ref - The resource reference string.
Returns:
true if the filter matches the ref, false if not.

getAccessPoint

protected String getAccessPoint(boolean relative)
Access the partial URL that forms the root of resource URLs.

Parameters:
relative - if true, form within the access path only (i.e. starting with /content)
Returns:
the partial URL that forms the root of resource URLs.

notificationId

protected String notificationId(String ref)
Access the notification id extracted from a notification reference.

Parameters:
ref - The notification reference string.
Returns:
The the notification id extracted from a notification reference.

notificationUrl

protected String notificationUrl(String id)
Access the external URL which can be used to access the resource from outside the system.

Parameters:
id - The notification id.
Returns:
The the external URL which can be used to access the resource from outside the system.

setLogger

public void setLogger(Logger service)
Dependency: logging service.

Parameters:
service - The logging service.

setEventTrackingService

public void setEventTrackingService(EventTrackingService service)
Dependency: event tracking service.

Parameters:
service - The event tracking service.

init

public void init()
Final initialization, once all dependencies are set.


destroy

public void destroy()
Returns to uninitialized state.


addNotification

public NotificationEdit addNotification()
Establish a new notification, locked for edit. Must commitEdit() to make official, or cancelEdit() when done!

Specified by:
addNotification in interface NotificationService
Returns:
a new Notification, locked for edit.

addTransientNotification

public NotificationEdit addTransientNotification()
Establish a new transient notification. Transient notifications are processed by the service but not stored in storage. Modification to the notification can be done at any time, do not use edit(), commit() or remove() on it.

Specified by:
addTransientNotification in interface NotificationService
Returns:
a new transient Notification.

getNotification

public Notification getNotification(String id)
                             throws IdUnusedException
Access a notification object.

Specified by:
getNotification in interface NotificationService
Parameters:
id - The notification id string.
Returns:
A notification object containing the notification information.
Throws:
IdUnusedException - if not found.

notificationReference

public String notificationReference(String id)
Access the internal reference which can be used to access the resource from within the system.

Specified by:
notificationReference in interface NotificationService
Parameters:
id - The notification id.
Returns:
The the internal reference which can be used to access the resource from within the system.

editNotification

public NotificationEdit editNotification(String id)
                                  throws IdUnusedException,
                                         InUseException
Get a locked notification object for editing. Must commitEdit() to make official, or cancelEdit() when done!

Specified by:
editNotification in interface NotificationService
Parameters:
id - The notification id string.
Returns:
A NotificationEdit object for editing.
Throws:
IdUnusedException - if not found.
PermissionException - if the current user does not have permission to mess with this notification.
InUseException - if the notification is being edited by another user.

commitEdit

public void commitEdit(NotificationEdit notification)
Commit the changes made to a NotificationEdit object, and release the lock.

Specified by:
commitEdit in interface NotificationService
Parameters:
notification - The NotificationEdit object to commit.

cancelEdit

public void cancelEdit(NotificationEdit notification)
Cancel the changes made to a NotificationEdit object, and release the lock.

Specified by:
cancelEdit in interface NotificationService
Parameters:
notification - The NotificationEdit object to commit.

removeNotification

public void removeNotification(NotificationEdit notification)
Remove this notification - it must be a notification with a lock from editNotification(). The NotificationEdit is disabled, and not to be used after this call.

Specified by:
removeNotification in interface NotificationService
Throws:
PermissionException - if the current notification does not have permission to remove this notification.

getNotifications

public List getNotifications(String function)
Access all notification objects that are watching this event function.

Parameters:
function - The event function.
Returns:
A Set of notification objects that are watching this event function.

findNotification

public Notification findNotification(String function,
                                     String filter)
Find a notification object.

Specified by:
findNotification in interface NotificationService
Parameters:
function - The function setting of the notification object.
filter - The resourceFilter setting of the notification object.
Returns:
A notification object matching the criteria, or null if none found.

update

public void update(Observable o,
                   Object arg)
This method is called whenever the observed object is changed. An application calls an Observable object's notifyObservers method to have all the object's observers notified of the change. default implementation is to cause the courier service to deliver to the interface controlled by my controller. Extensions can override.

Specified by:
update in interface Observer
Parameters:
o - the observable object.
arg - an argument passed to the notifyObservers method.

newContainer

public Entity newContainer(String ref)
Construct a new continer given just an id.

Specified by:
newContainer in interface StorageUser
Parameters:
ref - The container reference.
Returns:
The new containe Resource.

newContainer

public Entity newContainer(Element element)
Construct a new container resource, from an XML element.

Specified by:
newContainer in interface StorageUser
Parameters:
element - The XML.
Returns:
The new container resource.

newContainer

public Entity newContainer(Entity other)
Construct a new container resource, as a copy of another

Specified by:
newContainer in interface StorageUser
Parameters:
other - The other contianer to copy.
Returns:
The new container resource.

newResource

public Entity newResource(Entity container,
                          String id,
                          Object[] others)
Construct a new rsource given just an id.

Specified by:
newResource in interface StorageUser
Parameters:
container - The Resource that is the container for the new resource (may be null).
id - The id for the new object.
others - (options) array of objects to load into the Resource's fields.
Returns:
The new resource.

newResource

public Entity newResource(Entity container,
                          Element element)
Construct a new resource, from an XML element.

Specified by:
newResource in interface StorageUser
Parameters:
container - The Resource that is the container for the new resource (may be null).
element - The XML.
Returns:
The new resource from the XML.

newResource

public Entity newResource(Entity container,
                          Entity other)
Construct a new resource from another resource of the same type.

Specified by:
newResource in interface StorageUser
Parameters:
container - The Resource that is the container for the new resource (may be null).
other - The other resource.
Returns:
The new resource as a copy of the other.

newContainerEdit

public Edit newContainerEdit(String ref)
Construct a new continer given just an id.

Specified by:
newContainerEdit in interface StorageUser
Parameters:
ref - The container reference.
Returns:
The new containe Resource.

newContainerEdit

public Edit newContainerEdit(Element element)
Construct a new container resource, from an XML element.

Specified by:
newContainerEdit in interface StorageUser
Parameters:
element - The XML.
Returns:
The new container resource.

newContainerEdit

public Edit newContainerEdit(Entity other)
Construct a new container resource, as a copy of another

Specified by:
newContainerEdit in interface StorageUser
Parameters:
other - The other contianer to copy.
Returns:
The new container resource.

newResourceEdit

public Edit newResourceEdit(Entity container,
                            String id,
                            Object[] others)
Construct a new rsource given just an id.

Specified by:
newResourceEdit in interface StorageUser
Parameters:
container - The Resource that is the container for the new resource (may be null).
id - The id for the new object.
others - (options) array of objects to load into the Resource's fields.
Returns:
The new resource.

newResourceEdit

public Edit newResourceEdit(Entity container,
                            Element element)
Construct a new resource, from an XML element.

Specified by:
newResourceEdit in interface StorageUser
Parameters:
container - The Resource that is the container for the new resource (may be null).
element - The XML.
Returns:
The new resource from the XML.

newResourceEdit

public Edit newResourceEdit(Entity container,
                            Entity other)
Construct a new resource from another resource of the same type.

Specified by:
newResourceEdit in interface StorageUser
Parameters:
container - The Resource that is the container for the new resource (may be null).
other - The other resource.
Returns:
The new resource as a copy of the other.

storageFields

public Object[] storageFields(Entity r)
Collect the fields that need to be stored outside the XML (for the resource).

Specified by:
storageFields in interface StorageUser
Returns:
An array of field values to store in the record outside the XML (for the resource).

isDraft

public boolean isDraft(Entity r)
Check if this resource is in draft mode.

Specified by:
isDraft in interface StorageUser
Parameters:
r - The resource.
Returns:
true if the resource is in draft mode, false if not.

getOwnerId

public String getOwnerId(Entity r)
Access the resource owner user id.

Specified by:
getOwnerId in interface StorageUser
Parameters:
r - The resource.
Returns:
The resource owner user id.

getDate

public Time getDate(Entity r)
Access the resource date.

Specified by:
getDate in interface StorageUser
Parameters:
r - The resource.
Returns:
The resource date.

refresh

public Object refresh(Object key,
                      Object oldValue,
                      Event event)
Get a new value for this key whose value has already expired in the cache.

Specified by:
refresh in interface CacheRefresher
Parameters:
key - The key whose value has expired and needs to be refreshed.
oldValue - The old exipred value of the key.
event - The event which triggered this refresh.
Returns:
a new value for use in the cache for this key; if null, the entry will be removed.