org.springframework.richclient.command.support
Class DefaultCommandRegistry

java.lang.Object
  extended by org.springframework.richclient.command.support.DefaultCommandRegistry
All Implemented Interfaces:
EventListener, CommandRegistry, CommandRegistryListener

public class DefaultCommandRegistry
extends Object
implements CommandRegistry, CommandRegistryListener

The default implementation of the CommandRegistry interface. This implementation may act as the child of another registry, allowing for a hierarchy of registries to be created. If a command is requested from this registry but cannot be found, the request will be delegated to the parent registry.

Author:
Keith Donald, Kevin Stembridge

Field Summary
protected  org.apache.commons.logging.Log logger
          Class logger, available to subclasses.
 
Constructor Summary
DefaultCommandRegistry()
          Creates a new uninitialized DefaultCommandRegistry.
DefaultCommandRegistry(CommandRegistry parent)
          Creates a new DefaultCommandRegistry as a child of the given registry.
 
Method Summary
 void addCommandRegistryListener(CommandRegistryListener listener)
          Adds the given listener to the colleciton of listeners that will be notified of registry events.
 void commandRegistered(CommandRegistryEvent event)
          
 boolean containsActionCommand(String commandId)
          Deprecated.  
 boolean containsCommand(String commandId)
          Returns true if the registry contains a command with the given identifier.
 boolean containsCommandGroup(String groupId)
          Deprecated.  
protected  void fireCommandRegistered(AbstractCommand command)
          Fires a 'commandRegistered' CommandRegistryEvent for the given command to all registered listeners.
 ActionCommand getActionCommand(String commandId)
          Deprecated.  
 Object getCommand(String commandId)
          Retrieves from the registry the command with the given identifier.
 Object getCommand(String commandId, Class requiredType)
          Retrieves from the registry the command with the given identifier.
 CommandGroup getCommandGroup(String groupId)
          Deprecated.  
 CommandRegistry getParent()
          Returns the parent registry of this instance.
 Class getType(String commandId)
          Returns the type of the command with the given identifier, if it is contained in the registry.
 boolean isTypeMatch(String commandId, Class targetType)
          Returns true if the command with the given identifier is assignable to the given type.
 void registerCommand(AbstractCommand command)
          Registers the given command with the registry.
 void removeCommandRegistryListener(CommandRegistryListener listener)
          Remove the given listener from the collection of listeners that will be notified of registry events.
 void setParent(CommandRegistry parent)
          Sets the given registry to be the parent of this instance.
 void setTargetableActionCommandExecutor(String commandId, ActionCommandExecutor executor)
          Sets a command executor for the command with the given id.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

logger

protected final org.apache.commons.logging.Log logger
Class logger, available to subclasses.

Constructor Detail

DefaultCommandRegistry

public DefaultCommandRegistry()
Creates a new uninitialized DefaultCommandRegistry.


DefaultCommandRegistry

public DefaultCommandRegistry(CommandRegistry parent)
Creates a new DefaultCommandRegistry as a child of the given registry. The newly created instance will be added as a listener on the parent registry.

Parameters:
parent - The parent registry. May be null.
Method Detail

setParent

public void setParent(CommandRegistry parent)
Sets the given registry to be the parent of this instance. If the new parent is not null, this instance will act as a registry listener on it.

Parameters:
parent - The parent registry. May be null.

commandRegistered

public void commandRegistered(CommandRegistryEvent event)

Specified by:
commandRegistered in interface CommandRegistryListener

getActionCommand

public ActionCommand getActionCommand(String commandId)
Deprecated. 

Returns the ActionCommand that has the given id.

Specified by:
getActionCommand in interface CommandRegistry
Parameters:
commandId - The id of the action command to be returned.
Returns:
The action command with the given id, or null if no such command exists in the registry.

getCommandGroup

public CommandGroup getCommandGroup(String groupId)
Deprecated. 

Returns the CommandGroup that has the given id.

Specified by:
getCommandGroup in interface CommandRegistry
Parameters:
groupId - The id of the command group to be returned.
Returns:
The command group with the given id, or null if no such command group exists in the registry.

containsActionCommand

public boolean containsActionCommand(String commandId)
Deprecated. 

Returns true if the registry contains a command of type ActionCommand with the given id.

Specified by:
containsActionCommand in interface CommandRegistry
Parameters:
commandId - The id of the command to be searched for.
Returns:
true if the registry contains the command and it is assignable to ActionCommand.

containsCommandGroup

public boolean containsCommandGroup(String groupId)
Deprecated. 

Returns true if the registry contains a command of type CommandGroup with the given id.

Specified by:
containsCommandGroup in interface CommandRegistry
Parameters:
groupId - The id of the command group to be searched for.
Returns:
true if the registry contains the command and it is assignable to CommandGroup.

registerCommand

public void registerCommand(AbstractCommand command)
Registers the given command with the registry. Neither the command nor its id can be null. All registered listeners will be notified of the newly registered command via their CommandRegistryListener.commandRegistered(CommandRegistryEvent) method. If the given command is an instance of CommandGroup, its CommandGroup.setCommandRegistry(CommandRegistry) method must be called to set this instance as the registry for the command group.

Specified by:
registerCommand in interface CommandRegistry
Parameters:
command - The command to be registered. Must not be null.

fireCommandRegistered

protected void fireCommandRegistered(AbstractCommand command)
Fires a 'commandRegistered' CommandRegistryEvent for the given command to all registered listeners.

Parameters:
command - The command that has been registered. Must not be null.
Throws:
IllegalArgumentException - if command is null.

setTargetableActionCommandExecutor

public void setTargetableActionCommandExecutor(String commandId,
                                               ActionCommandExecutor executor)
Sets a command executor for the command with the given id. The actual type of the command must be assignable to TargetableActionCommand.

Specified by:
setTargetableActionCommandExecutor in interface CommandRegistry
Parameters:
commandId - The id of the targetable command that will have its executor set. Must not be null.
executor - The command executor. May be null.

addCommandRegistryListener

public void addCommandRegistryListener(CommandRegistryListener listener)
Adds the given listener to the colleciton of listeners that will be notified of registry events.

Specified by:
addCommandRegistryListener in interface CommandRegistry
Parameters:
listener - The listener to be added. Must not be null.

removeCommandRegistryListener

public void removeCommandRegistryListener(CommandRegistryListener listener)
Remove the given listener from the collection of listeners that will be notified of registry events.

Specified by:
removeCommandRegistryListener in interface CommandRegistry
Parameters:
listener - The listener to be removed.

getParent

public CommandRegistry getParent()
Returns the parent registry of this instance.

Returns:
The parent registry, or null.

containsCommand

public boolean containsCommand(String commandId)
Returns true if the registry contains a command with the given identifier.

Specified by:
containsCommand in interface CommandRegistry
Parameters:
commandId - The ID of the command to search for.
Returns:
true if the registry contains the command, false otherwise.

getCommand

public Object getCommand(String commandId)
Retrieves from the registry the command with the given identifier.

Specified by:
getCommand in interface CommandRegistry
Parameters:
commandId - The ID of the command to be retrieved.
Returns:
The command with the given ID, or null if no such command could be found.

getCommand

public Object getCommand(String commandId,
                         Class requiredType)
                  throws CommandNotOfRequiredTypeException
Retrieves from the registry the command with the given identifier. An exception is thrown if the retrieved command is not assignable to the required type.

Specified by:
getCommand in interface CommandRegistry
Parameters:
commandId - The identifier of the command to be retrieved. Must not be null.
requiredType - The required type of the command with the given id.
Returns:
The command with the given id if it exists in the registry and is of the required type.
Throws:
CommandNotOfRequiredTypeException - if the retrieved command is not assignable to the required type.

getType

public Class getType(String commandId)
Returns the type of the command with the given identifier, if it is contained in the registry.

Specified by:
getType in interface CommandRegistry
Parameters:
commandId - The ID of the command whose type is to be returned. Must not be null.
Returns:
The type of the command with the given ID, or null if no such command exists in the registry.

isTypeMatch

public boolean isTypeMatch(String commandId,
                           Class targetType)
Returns true if the command with the given identifier is assignable to the given type.

Specified by:
isTypeMatch in interface CommandRegistry
Parameters:
commandId - The ID of the command whose type will be checked. Must not be null.
targetType - The type to be checked against the type of the command. Must not be null.
Returns:
true if a command with the given ID exists in the registry and it is assignable to the given target type, false otherwise.


Copyright © 2004-2008 The Spring Framework. All Rights Reserved.