message
Class MessageCentreImpl

java.lang.Object
  extended bymessage.MessageCentreImpl
All Implemented Interfaces:
MessageCentre, java.io.Serializable

public class MessageCentreImpl
extends java.lang.Object
implements MessageCentre, java.io.Serializable

Storage and retrieval of portlet message mappings, and the messages. One MessageCentre instance will be created per portlet webapp. The MessageStore used (set in the constructor) will determine the messaging functionality: if it uses a remote store such as a database, the messages will be available to all portlet applications, but if it is a local store, they will only be available to the current portlet application. Direct use of this class is only necessary when you want to modify message mappings in code; to simply load mappings from preferences, or send/receive messages, use MessageHelper.

See Also:
Serialized Form

Field Summary
protected  MessageStore store
           
 
Constructor Summary
MessageCentreImpl()
           
 
Method Summary
 void addInputMapping(MessageBoxKey key, MessageBoxKey source)
           
 void addInputMapping(java.lang.String portletID, java.lang.String name, MessageBoxKey source)
          Set a portlet message key => message box mapping.
 void addOutputMapping(MessageBoxKey key, MessageBoxKey target)
           
 void addOutputMapping(java.lang.String portletID, java.lang.String name, MessageBoxKey target)
          Add a portlet message key => message box mapping.
 void clearAllOutputMappings(MessageBoxKey key)
          Remove any existing output mappings for this key.
 void clearInputMapping(MessageBoxKey key)
          Remove a message key => message box mapping.
 void deleteInput(MessageBoxKey key)
          Remove all trace of the specified input message box.
 void deleteOutput(MessageBoxKey key)
          Remove all trace of the specified output message box.
 MessageBoxKey findInputSource(MessageBoxKey key)
           
 MessageBoxKey findInputSource(java.lang.String portletID, java.lang.String name)
          Get the key of the source message box for this portletID+name combination.
 java.util.Set findOutputTargets(MessageBoxKey key)
           
 java.util.Set findOutputTargets(java.lang.String portletID, java.lang.String name)
          This will always return a Set which contains at least a key for a message box corresponding to the provided portletID+name (it always outputs to itself as well as any other registered mappings)
 java.lang.Object get(MessageBoxKey boxKey)
          Get message from this message box.
 java.lang.Object get(java.lang.String portletID, java.lang.String name)
          Get message for this portletID+name combination.
 java.util.Set getAllInputKeys()
           
 java.util.Set getAllOutputKeys()
           
 java.util.Map getBoxes()
           
 java.util.Set getInputKeys(java.lang.String portletID)
           
 java.util.Set getOutputKeys(java.lang.String portletID)
           
 java.util.Set getPublicBoxKeys()
           
 boolean isValid()
           
protected  MessageBoxKey makeLocalKey(java.lang.String portletID, java.lang.String name)
           
 void send(java.util.Set targetKeys, java.lang.Object message)
          Send message to these message boxes.
 void send(java.lang.String portletID, java.lang.String name, java.lang.Object message)
          Send message to this portletID+name combination.
 void setStore(MessageStore store)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

store

protected MessageStore store
Constructor Detail

MessageCentreImpl

public MessageCentreImpl()
Method Detail

setStore

public void setStore(MessageStore store)
Specified by:
setStore in interface MessageCentre

addInputMapping

public void addInputMapping(java.lang.String portletID,
                            java.lang.String name,
                            MessageBoxKey source)
Set a portlet message key => message box mapping. This will overwrite any existing input mapping.

Specified by:
addInputMapping in interface MessageCentre
Parameters:
portletID - ID of the portlet which is receiving the input
name - (local) name of the portlet input, referred to in the portlet's code
source - the message box from which the portlet's input will read.

addInputMapping

public void addInputMapping(MessageBoxKey key,
                            MessageBoxKey source)
Specified by:
addInputMapping in interface MessageCentre

clearInputMapping

public void clearInputMapping(MessageBoxKey key)
Remove a message key => message box mapping. As there can only be 1 mapping for each input, this will result in the default mapping: looking for a local portlet message of the same name.

Specified by:
clearInputMapping in interface MessageCentre

deleteInput

public void deleteInput(MessageBoxKey key)
Remove all trace of the specified input message box. There will no longer be even a default mapping.

Specified by:
deleteInput in interface MessageCentre

addOutputMapping

public void addOutputMapping(java.lang.String portletID,
                             java.lang.String name,
                             MessageBoxKey target)
Add a portlet message key => message box mapping. This will be in addition to any existing output mappings; the message will be copied to all mapped output targets.

Specified by:
addOutputMapping in interface MessageCentre
Parameters:
portletID - ID of the portlet which is sending the output
name - (local) name of the portlet output, referred to in the portlet's code
target - the message box to which the portlet's output will copy its message.

addOutputMapping

public void addOutputMapping(MessageBoxKey key,
                             MessageBoxKey target)
Specified by:
addOutputMapping in interface MessageCentre

clearAllOutputMappings

public void clearAllOutputMappings(MessageBoxKey key)
Remove any existing output mappings for this key. The result will be that the output still exists, but does not publish to anywhere.

Specified by:
clearAllOutputMappings in interface MessageCentre

deleteOutput

public void deleteOutput(MessageBoxKey key)
Remove all trace of the specified output message box. There will no longer be even a default mapping, so it will no longer be possible to publish messages to it.

Specified by:
deleteOutput in interface MessageCentre

findOutputTargets

public java.util.Set findOutputTargets(java.lang.String portletID,
                                       java.lang.String name)
This will always return a Set which contains at least a key for a message box corresponding to the provided portletID+name (it always outputs to itself as well as any other registered mappings)

Specified by:
findOutputTargets in interface MessageCentre
Returns:
Set of MessageBoxKey's: the output keys registered for this portletID+name

findOutputTargets

public java.util.Set findOutputTargets(MessageBoxKey key)
Specified by:
findOutputTargets in interface MessageCentre

get

public java.lang.Object get(java.lang.String portletID,
                            java.lang.String name)
Get message for this portletID+name combination. If there is no mapping to a message box defined for the specified portletID+name, it tries to find a local message box of the same name. If there is no message, returns null.

Specified by:
get in interface MessageCentre

send

public void send(java.lang.String portletID,
                 java.lang.String name,
                 java.lang.Object message)
Send message to this portletID+name combination. It will be delivered to a local message box with this name. It will also be delivered to all message boxes for which mappings have been registered for this portletID+name using addMapping. It will replace any message already in the boxes.

Specified by:
send in interface MessageCentre

findInputSource

public MessageBoxKey findInputSource(java.lang.String portletID,
                                     java.lang.String name)
Get the key of the source message box for this portletID+name combination. If no mapping is found, returns a MessageBoxKey for this portletID+name.

Specified by:
findInputSource in interface MessageCentre

findInputSource

public MessageBoxKey findInputSource(MessageBoxKey key)
Specified by:
findInputSource in interface MessageCentre

get

public java.lang.Object get(MessageBoxKey boxKey)
Get message from this message box. If there is no message, returns null.

Specified by:
get in interface MessageCentre

send

public void send(java.util.Set targetKeys,
                 java.lang.Object message)
Send message to these message boxes. It will replace any message already in the boxes, or remove the box if 'message' is null.

Specified by:
send in interface MessageCentre
Parameters:
targetKeys - Set of MessageBoxKeys to which the message should be sent

getInputKeys

public java.util.Set getInputKeys(java.lang.String portletID)
Specified by:
getInputKeys in interface MessageCentre

getOutputKeys

public java.util.Set getOutputKeys(java.lang.String portletID)
Specified by:
getOutputKeys in interface MessageCentre

getPublicBoxKeys

public java.util.Set getPublicBoxKeys()
Specified by:
getPublicBoxKeys in interface MessageCentre

getBoxes

public java.util.Map getBoxes()
Specified by:
getBoxes in interface MessageCentre

getAllInputKeys

public java.util.Set getAllInputKeys()
Specified by:
getAllInputKeys in interface MessageCentre

getAllOutputKeys

public java.util.Set getAllOutputKeys()
Specified by:
getAllOutputKeys in interface MessageCentre

isValid

public boolean isValid()
Specified by:
isValid in interface MessageCentre

makeLocalKey

protected MessageBoxKey makeLocalKey(java.lang.String portletID,
                                     java.lang.String name)