org.sakaiproject.component.legacy.message
Class BaseMessageService.BaseMessageChannelEdit

java.lang.Object
  extended byjava.util.Observable
      extended byorg.sakaiproject.component.legacy.message.BaseMessageService.BaseMessageChannelEdit
All Implemented Interfaces:
Edit, Entity, EventListener, MessageChannel, MessageChannelEdit, SessionBindingListener
Direct Known Subclasses:
BaseAnnouncementService.BaseAnnouncementChannelEdit, BaseChatService.BaseChatChannelEdit, BaseDiscussionService.BaseDiscussionChannelEdit, BaseMailArchiveService.BaseMailArchiveChannelEdit
Enclosing class:
BaseMessageService

public class BaseMessageService.BaseMessageChannelEdit
extends Observable
implements MessageChannelEdit, SessionBindingListener

MessageChannel implementation


Field Summary
protected  boolean m_active
          Active flag.
protected  String m_context
          The context in which this channel exists.
protected  String m_event
          The event code for this edit.
protected  String m_id
          The channel id, unique within the context.
protected  boolean m_isRemoved
          When true, the channel has been removed.
protected  ResourcePropertiesEdit m_properties
          The properties.
 
Fields inherited from interface org.sakaiproject.service.legacy.entity.Entity
SEPARATOR
 
Constructor Summary
BaseMessageService.BaseMessageChannelEdit(Element el)
          Construct from a channel (and possibly messages) already defined in XML in a DOM tree.
BaseMessageService.BaseMessageChannelEdit(MessageChannel other)
          Construct as a copy of another.
BaseMessageService.BaseMessageChannelEdit(String ref)
          Construct with a reference.
 
Method Summary
 void activate()
          Enable editing.
 MessageEdit addMessage()
          Add a new message to this channel.
 boolean allowAddChannelMessage()
          Check if the user has permission to add a channel-wide (not grouped) message.
 boolean allowAddMessage()
          check permissions for addMessage().
protected  boolean allowEditMessage(Message m, String fOwn, String fAny)
          check permissions for the message, to be able to edit or save it.
 boolean allowEditMessage(String messageId)
          check permissions for editMessage()
 boolean allowGetMessages()
          check permissions for getMessages() or getMessage().
 boolean allowRemoveMessage(Message m)
          check permissions for removeMessage().
 void cancelMessage(MessageEdit edit)
          Cancel the changes made to a MessageEdit object, and release the lock.
protected  void closeEdit()
          Close the edit object - it cannot be used after this.
 void commitMessage(MessageEdit edit)
          Commit the changes made to a MessageEdit object, and release the lock.
 void commitMessage(MessageEdit edit, int priority)
          Commit the changes made to a MessageEdit object, and release the lock.
 MessageEdit editMessage(String messageId)
          Return a specific channel message, as specified by message name, locked for update.
protected  void finalize()
          Clean up.
 List findFilterMessages(Filter filter, boolean ascending)
          Find messages, sort, and filter.
protected  Message findMessage(String messageId)
          Find the message, in cache or info store - cache it if newly found.
protected  List findMessages()
          Find all messages.
 String getContext()
          Access the context of the resource.
protected  String getEvent()
          Access the event code for this edit.
 Collection getGroupsAllowAddMessage()
          Get the collection of Groups defined for the context of this channel that the end user has add message permissions in.
protected  Collection getGroupsAllowFunction(String function)
          Get the groups of this channel's contex-site that the end user has permission to "function" in.
 Collection getGroupsAllowGetMessage()
          Get the collection of Group defined for the context of this channel that the end user has get message permissions in.
 String getId()
          Access the id of the resource.
 Message getMessage(String messageId)
          Return a specific channel message, as specified by message name.
 List getMessages(Filter filter, boolean ascending)
          Return a list of all or filtered messages in the channel.
 ResourceProperties getProperties()
          Access the channel's properties.
 ResourcePropertiesEdit getPropertiesEdit()
          Access the resource's properties for modification
 String getReference()
          Access the internal reference which can be used to access the resource from within the system.
 String getReference(String rootProperty)
          Access the alternate internal reference which can be used to access the entity from within the system.
 String getUrl()
          Access the URL which can be used to access the resource.
 String getUrl(String rootProperty)
          Access the alternate URL which can be used to access the entity.
 boolean isActiveEdit()
          Check to see if the edit is still active, or has already been closed.
protected  boolean isIntersectionGroupRefsToGroups(Collection groupRefs, Collection groups)
          See if the collection of group reference strings has at least one group that is in the collection of Group objects.
 MessageEdit mergeMessage(Element el)
          Merge in a new message as defined in the xml.
 void notify(Event event)
          Notify the channel that it has changed (i.e. when a message has changed)
 void removeMessage(MessageEdit message)
          Remove a message from the channel - it must be locked from editMessage().
 void removeMessage(String messageId)
          Remove a message from the channel based on message id
protected  void setEvent(String event)
          Set the event code for this edit.
 void setRemoved(Event event)
          Set the channel as removed.
 Element toXml(Document doc, Stack stack)
          Serialize the resource into XML, adding an element to the doc under the top of the stack element.
 void valueBound(SessionBindingEvent event)
          SessionBindingListener implementation
 void valueUnbound(SessionBindingEvent event)
          Notifies the object that it is being unbound from a session.
 
Methods inherited from class java.util.Observable
addObserver, clearChanged, countObservers, deleteObserver, deleteObservers, hasChanged, notifyObservers, notifyObservers, setChanged
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

m_context

protected String m_context
The context in which this channel exists.


m_id

protected String m_id
The channel id, unique within the context.


m_properties

protected ResourcePropertiesEdit m_properties
The properties.


m_isRemoved

protected boolean m_isRemoved
When true, the channel has been removed.


m_event

protected String m_event
The event code for this edit.


m_active

protected boolean m_active
Active flag.

Constructor Detail

BaseMessageService.BaseMessageChannelEdit

public BaseMessageService.BaseMessageChannelEdit(String ref)
Construct with a reference.

Parameters:
ref - The channel reference.

BaseMessageService.BaseMessageChannelEdit

public BaseMessageService.BaseMessageChannelEdit(MessageChannel other)
Construct as a copy of another.


BaseMessageService.BaseMessageChannelEdit

public BaseMessageService.BaseMessageChannelEdit(Element el)
Construct from a channel (and possibly messages) already defined in XML in a DOM tree. The Channel is added to storage.

Parameters:
el - The XML DOM element defining the channel.
Method Detail

finalize

protected void finalize()
Clean up.


setRemoved

public void setRemoved(Event event)
Set the channel as removed.

Parameters:
event - The tracking event associated with this action.

getContext

public String getContext()
Access the context of the resource.

Specified by:
getContext in interface MessageChannel
Returns:
The context.

getId

public String getId()
Access the id of the resource.

Specified by:
getId in interface Entity
Returns:
The id.

getUrl

public String getUrl()
Access the URL which can be used to access the resource.

Specified by:
getUrl in interface Entity
Returns:
The URL which can be used to access the resource.

getReference

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

Specified by:
getReference in interface Entity
Returns:
The the internal reference which can be used to access the resource from within the system.

getReference

public String getReference(String rootProperty)
Description copied from interface: Entity
Access the alternate internal reference which can be used to access the entity from within the system.

Specified by:
getReference in interface Entity
Parameters:
rootProperty - The name of the entity property whose value controls which alternate reference is requested. If null, the native 'raw' reference is requested.
Returns:
The the alternate internal reference which can be used to access the entity from within the system.

getUrl

public String getUrl(String rootProperty)
Description copied from interface: Entity
Access the alternate URL which can be used to access the entity.

Specified by:
getUrl in interface Entity
Parameters:
rootProperty - The name of the entity property whose value controls which alternate reference URL is requested. If null, the native 'raw' URL is requested.
Returns:
The alternate URL which can be used to access the entity.

getProperties

public ResourceProperties getProperties()
Access the channel's properties.

Specified by:
getProperties in interface Entity
Returns:
The channel's properties.

allowGetMessages

public boolean allowGetMessages()
check permissions for getMessages() or getMessage().

Specified by:
allowGetMessages in interface MessageChannel
Returns:
true if the user is allowed to get messages from this channel, false if not.

getGroupsAllowGetMessage

public Collection getGroupsAllowGetMessage()
Description copied from interface: MessageChannel
Get the collection of Group defined for the context of this channel that the end user has get message permissions in.

Specified by:
getGroupsAllowGetMessage in interface MessageChannel
Returns:
The Collection (Group) of groups defined for the context of this channel that the end user has get message permissions in, empty if none.

getMessages

public List getMessages(Filter filter,
                        boolean ascending)
                 throws PermissionException
Return a list of all or filtered messages in the channel. The order in which the messages will be found in the iteration is by date, oldest first if ascending is true, newest first if ascending is false.

Specified by:
getMessages in interface MessageChannel
Parameters:
filter - A filtering object to accept messages, or null if no filtering is desired.
ascending - Order of messages, ascending if true, descending if false
Returns:
a list on channel Message objects or specializations of Message objects (may be empty).
Throws:
PermissionException - if the user does not have read permission to the channel.

getMessage

public Message getMessage(String messageId)
                   throws IdUnusedException,
                          PermissionException
Return a specific channel message, as specified by message name.

Specified by:
getMessage in interface MessageChannel
Parameters:
messageId - The id of the message to get.
Returns:
the Message that has the specified id.
Throws:
IdUnusedException - If this name is not a defined message in this channel.
PermissionException - If the user does not have any permissions to read the message.

allowEditMessage

public boolean allowEditMessage(String messageId)
check permissions for editMessage()

Specified by:
allowEditMessage in interface MessageChannel
Returns:
true if the user is allowed to update the message, false if not.

allowEditMessage

protected boolean allowEditMessage(Message m,
                                   String fOwn,
                                   String fAny)
check permissions for the message, to be able to edit or save it.

Parameters:
m - The message.
Returns:
true if the user is allowed to update the message, false if not.

editMessage

public MessageEdit editMessage(String messageId)
                        throws IdUnusedException,
                               PermissionException,
                               InUseException
Return a specific channel message, as specified by message name, locked for update. Must commitEdit() to make official, or cancelEdit() when done!

Specified by:
editMessage in interface MessageChannel
Parameters:
messageId - The id of the message to get.
Returns:
the Message that has the specified id.
Throws:
IdUnusedException - If this name is not a defined message in this channel.
PermissionException - If the user does not have any permissions to read the message.
InUseException - if the current user does not have permission to mess with this user.

commitMessage

public void commitMessage(MessageEdit edit)
                   throws PermissionException
Commit the changes made to a MessageEdit object, and release the lock. The MessageEdit is disabled, and not to be used after this call.

Specified by:
commitMessage in interface MessageChannel
Throws:
PermissionException - If the user does not have permission to store this message.

commitMessage

public void commitMessage(MessageEdit edit,
                          int priority)
                   throws PermissionException
Commit the changes made to a MessageEdit object, and release the lock. The MessageEdit is disabled, and not to be used after this call.

Specified by:
commitMessage in interface MessageChannel
Parameters:
priority - The notification priority for this commit.
Throws:
PermissionException - If the user does not have permission to store this message.

cancelMessage

public void cancelMessage(MessageEdit edit)
Cancel the changes made to a MessageEdit object, and release the lock. The MessageEdit is disabled, and not to be used after this call.

Specified by:
cancelMessage in interface MessageChannel

allowAddMessage

public boolean allowAddMessage()
check permissions for addMessage().

Specified by:
allowAddMessage in interface MessageChannel
Returns:
true if the user is allowed to addMessage(...), false if not.

allowAddChannelMessage

public boolean allowAddChannelMessage()
Description copied from interface: MessageChannel
Check if the user has permission to add a channel-wide (not grouped) message.

Specified by:
allowAddChannelMessage in interface MessageChannel
Returns:
true if the user has permission to add a channel-wide (not grouped) message.

getGroupsAllowAddMessage

public Collection getGroupsAllowAddMessage()
Description copied from interface: MessageChannel
Get the collection of Groups defined for the context of this channel that the end user has add message permissions in.

Specified by:
getGroupsAllowAddMessage in interface MessageChannel
Returns:
The Collection (Group) of groups defined for the context of this channel that the end user has add message permissions in, empty if none.

addMessage

public MessageEdit addMessage()
                       throws PermissionException
Add a new message to this channel. Must commitEdit() to make official, or cancelEdit() when done!

Specified by:
addMessage in interface MessageChannel
Returns:
The newly added message.
Throws:
PermissionException - If the user does not have write permission to the channel.

mergeMessage

public MessageEdit mergeMessage(Element el)
                         throws PermissionException,
                                IdUsedException
Merge in a new message as defined in the xml. Must commitEdit() to make official, or cancelEdit() when done!

Specified by:
mergeMessage in interface MessageChannel
Parameters:
el - The message information in XML in a DOM element.
Returns:
The newly added message, locked for update.
Throws:
PermissionException - If the user does not have write permission to the channel.
IdUsedException - if the user id is already used.

allowRemoveMessage

public boolean allowRemoveMessage(Message m)
check permissions for removeMessage().

Specified by:
allowRemoveMessage in interface MessageChannel
Parameters:
m - The message from this channel to remove.
Returns:
true if the user is allowed to removeMessage(...), false if not.

removeMessage

public void removeMessage(String messageId)
                   throws PermissionException
Description copied from interface: MessageChannel
Remove a message from the channel based on message id

Specified by:
removeMessage in interface MessageChannel
Parameters:
messageId - The messageId for the message of the channel to remove.
Throws:
PermissionException - if the user does not have permission to remove the message.

removeMessage

public void removeMessage(MessageEdit message)
                   throws PermissionException
Remove a message from the channel - it must be locked from editMessage().

Specified by:
removeMessage in interface MessageChannel
Parameters:
message - The message from this channel to remove.
Throws:
PermissionException - if the user does not have permission to remove the message.

toXml

public Element toXml(Document doc,
                     Stack stack)
Serialize the resource into XML, adding an element to the doc under the top of the stack element.

Specified by:
toXml in interface Entity
Parameters:
doc - The DOM doc to contain the XML (or null for a string return).
stack - The DOM elements, the top of which is the containing element of the new "resource" element.
Returns:
The newly added element.

notify

public void notify(Event event)
Notify the channel that it has changed (i.e. when a message has changed)

Parameters:
event - The event that caused the update.

findMessage

protected Message findMessage(String messageId)
Find the message, in cache or info store - cache it if newly found.

Parameters:
messageId - The id of the message.
Returns:
The message, if found.

findMessages

protected List findMessages()
Find all messages.

Returns:
a List of all messages in the channel.

findFilterMessages

public List findFilterMessages(Filter filter,
                               boolean ascending)
Find messages, sort, and filter.

Parameters:
filter - A filtering object to accept messages, or null if no filtering is desired.
ascending - Order of messages, ascending if true, descending if false
Returns:
All messages, sorted and filtered.

isIntersectionGroupRefsToGroups

protected boolean isIntersectionGroupRefsToGroups(Collection groupRefs,
                                                  Collection groups)
See if the collection of group reference strings has at least one group that is in the collection of Group objects.

Parameters:
groupRefs - The collection (String) of group references.
groups - The collection (Group) of group objects.
Returns:
true if there is interesection, false if not.

getEvent

protected String getEvent()
Access the event code for this edit.

Returns:
The event code for this edit.

setEvent

protected void setEvent(String event)
Set the event code for this edit.

Parameters:
event - The event code for this edit.

getPropertiesEdit

public ResourcePropertiesEdit getPropertiesEdit()
Access the resource's properties for modification

Specified by:
getPropertiesEdit in interface Edit
Returns:
The resource's properties.

activate

public void activate()
Enable editing.


isActiveEdit

public boolean isActiveEdit()
Check to see if the edit is still active, or has already been closed.

Specified by:
isActiveEdit in interface Edit
Returns:
true if the edit is active, false if it's been closed.

closeEdit

protected void closeEdit()
Close the edit object - it cannot be used after this.


getGroupsAllowFunction

protected Collection getGroupsAllowFunction(String function)
Get the groups of this channel's contex-site that the end user has permission to "function" in.

Parameters:
function - The function to check

valueBound

public void valueBound(SessionBindingEvent event)
SessionBindingListener implementation

Specified by:
valueBound in interface SessionBindingListener
Parameters:
event - the event that identifies the session

valueUnbound

public void valueUnbound(SessionBindingEvent event)
Description copied from interface: SessionBindingListener
Notifies the object that it is being unbound from a session.

Specified by:
valueUnbound in interface SessionBindingListener
Parameters:
event - the event that identifies the session