org.springframework.richclient.command
Interface CommandRegistry

All Known Subinterfaces:
CommandManager
All Known Implementing Classes:
ApplicationWindowCommandManager, DefaultCommandManager, DefaultCommandRegistry

public interface CommandRegistry

A registry for command objects.

The commands to be placed in the registry must have non-null identifiers available via their AbstractCommand.getId() method, and this id is expected to be unique amongst all the commands in the application. Generally speaking, this uniqueness will not be enforced by the framework but will instead allow commands to be overwritten by others with the same id.

Implementations may allow for the creation of hierarchical registries whereby a registry may have a parent registry. In this case, if a registry does not contain a requested command it will delegate to its parent to find the command. Commands in a child registry will override commands with the same ID in any ancestor registries.

Author:
Keith Donald, Kevin Stembridge

Method Summary
 void addCommandRegistryListener(CommandRegistryListener listener)
          Adds the given listener to the colleciton of listeners that will be notified of registry events.
 boolean containsActionCommand(String commandId)
          Deprecated. Replaced by isTypeMatch(String, Class)
 boolean containsCommand(String commandId)
          Returns true if the registry contains a command with the given identifier.
 boolean containsCommandGroup(String groupId)
          Deprecated. Replaced by isTypeMatch(String, Class)
 ActionCommand getActionCommand(String commandId)
          Deprecated. use getCommand(String, Class) instead. You may choose to either catch the CommandNotOfRequiredTypeException or call isTypeMatch(String, Class) first.
 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. use getCommand(String, Class) instead. You may choose to either catch the CommandNotOfRequiredTypeException or call isTypeMatch(String, Class) first.
 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 setTargetableActionCommandExecutor(String targetableCommandId, ActionCommandExecutor commandExecutor)
          Sets a command executor for the command with the given id.
 

Method Detail

containsCommand

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

Parameters:
commandId - The ID of the command to search for.
Returns:
true if the registry contains the command, false otherwise.
Throws:
IllegalArgumentException - if commandId is null.

getCommand

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

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.
Throws:
IllegalArgumentException - if commandId is null.

getCommand

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.

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

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

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.
Throws:
IllegalArgumentException - if commandId is null.

isTypeMatch

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

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.
Throws:
IllegalArgumentException - if either argument is null.

getActionCommand

ActionCommand getActionCommand(String commandId)
Deprecated. use getCommand(String, Class) instead. You may choose to either catch the CommandNotOfRequiredTypeException or call isTypeMatch(String, Class) first.

Returns the ActionCommand that has the given id.

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.
Throws:
IllegalArgumentException - if commandId is null.
CommandNotOfRequiredTypeException - if there is a command with the given id in the registry but it is not of type ActionCommand.

getCommandGroup

CommandGroup getCommandGroup(String groupId)
Deprecated. use getCommand(String, Class) instead. You may choose to either catch the CommandNotOfRequiredTypeException or call isTypeMatch(String, Class) first.

Returns the CommandGroup that has the given id.

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.
Throws:
IllegalArgumentException - if commandId is null.
CommandNotOfRequiredTypeException - if there is a command with the given id in the registry but it is not of type CommandGroup.

containsActionCommand

boolean containsActionCommand(String commandId)
Deprecated. Replaced by isTypeMatch(String, Class)

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

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

boolean containsCommandGroup(String groupId)
Deprecated. Replaced by isTypeMatch(String, Class)

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

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

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.

Parameters:
command - The command to be registered. Must not be null.
Throws:
IllegalArgumentException - if command is null or if its id is null.

setTargetableActionCommandExecutor

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

Parameters:
targetableCommandId - The id of the targetable command that will have its executor set. Must not be null.
commandExecutor - The command executor. May be null.
Throws:
IllegalArgumentException - if targetableCommandId is null.
CommandNotOfRequiredTypeException - if the command with the given id is not a TargetableActionCommand.

addCommandRegistryListener

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

Parameters:
listener - The listener to be added. Must not be null.

removeCommandRegistryListener

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

Parameters:
listener - The listener to be removed.


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