org.springframework.richclient.command
Class CommandGroupFactoryBean

Show UML class diagram
java.lang.Object
  extended by org.springframework.richclient.command.CommandGroupFactoryBean
All Implemented Interfaces:
BeanNameAware, FactoryBean, InitializingBean, Authorizable, SecurityControllable

public class CommandGroupFactoryBean
extends Object
implements BeanNameAware, FactoryBean, SecurityControllable, InitializingBean

A FactoryBean that produces a CommandGroup.

Use of this bean simplifies the process of building up complex nested command groups such as the main menu of an application window, a toolbar or popup menus. The main property of interest when creating a bean definition for this class is the members list. This list defines the members of the command group that will be produced by the factory. The objects contained in this list can be instances of the actual command or they can be strings that represent the identifier of the command. Some strings have special meaning:

Author:
Keith Donald

Field Summary
static String COMMAND_MEMBER_PREFIX
          The string prefix that indicates a command group member that is a command.
static String GLUE_MEMBER_CODE
          The string that represents a glue component, to be used between other members of the command group.
static String GROUP_MEMBER_PREFIX
          The string prefix that indicates a command group member that is another command group.
protected  org.apache.commons.logging.Log logger
          Class logger, available to subclasses.
static String SEPARATOR_MEMBER_CODE
          The string that represents a separator between commands in the command group.
 
Fields inherited from interface org.springframework.richclient.core.Authorizable
AUTHORIZED_PROPERTY
 
Constructor Summary
CommandGroupFactoryBean()
          Creates a new uninitialized CommandGroupFactoryBean.
CommandGroupFactoryBean(String groupId, CommandRegistry commandRegistry, CommandConfigurer commandConfigurer, Object[] members)
          Creates a new CommandGroupFactoryBean.
CommandGroupFactoryBean(String groupId, CommandRegistry commandRegistry, Object[] members)
          Creates a new CommandGroupFactoryBean.
CommandGroupFactoryBean(String groupId, Object[] members)
          Creates a new CommandGroupFactoryBean with the given group ID and command group members.
 
Method Summary
 void afterPropertiesSet()
          
protected  void configureIfNecessary(AbstractCommand command)
          Configures the given command if it has not already been configured and this instance has been provided with a CommandConfigurer.
protected  CommandGroup createCommandGroup()
          Creates the command group for this factory and assigns it an identifier equal to the group id of the factory.
protected  String getBeanName()
           
 CommandGroup getCommandGroup()
          Returns the command group that this factory produces.
protected  CommandRegistry getCommandRegistry()
           
protected  Object[] getMembers()
           
 Object getObject()
          Returns the command group that this factory produces.
 Class getObjectType()
          Returns the Class object for CommandGroup.
 String getSecurityControllerId()
          Get the id (bean name) of the security controller that should manage this object.
protected  void initCommandGroupMembers(CommandGroup group)
          Iterates over the collection of encoded members and adds them to the given command group.
protected  boolean isAllowsEmptySelection()
           
 boolean isAuthorized()
          Get the authorized state.
 boolean isExclusive()
          Returns the value of the flag that indicates whether or not this factory produces an exclusive command group.
 boolean isSingleton()
          Always returns true.
 void setAllowsEmptySelection(boolean allowsEmptySelection)
          Sets the flag that indicates whether or not the command group produced by this factory allows no items in the group to be selected, default is false.
 void setAuthorized(boolean authorized)
          Set the authorized state.
 void setBeanName(String beanName)
          Accepts notification from the IoC container of this instance's bean name as declared in the bean definition file.
 void setCommandConfigurer(CommandConfigurer configurer)
          Sets the object that will be used to configure the command objects in the command groups produced by this factory.
 void setCommandRegistry(CommandRegistry commandRegistry)
          Sets the registry that will be used to retrieve the actual instances of the command group members as specified in the encoded members collection.
 void setExclusive(boolean exclusive)
          Sets the flag that indicates whether or not this factory produces an exclusive command group.
 void setMembers(Object[] members)
          Sets the collection of objects that specify the members of the command group produced by this factory.
 void setSecurityControllerId(String controllerId)
          Set the Id of the security controller that should manage this object.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

GLUE_MEMBER_CODE

public static final String GLUE_MEMBER_CODE
The string that represents a glue component, to be used between other members of the command group.

See Also:
Constant Field Values

SEPARATOR_MEMBER_CODE

public static final String SEPARATOR_MEMBER_CODE
The string that represents a separator between commands in the command group.

See Also:
Constant Field Values

COMMAND_MEMBER_PREFIX

public static final String COMMAND_MEMBER_PREFIX
The string prefix that indicates a command group member that is a command.

See Also:
Constant Field Values

GROUP_MEMBER_PREFIX

public static final String GROUP_MEMBER_PREFIX
The string prefix that indicates a command group member that is another command group.

See Also:
Constant Field Values

logger

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

Constructor Detail

CommandGroupFactoryBean

public CommandGroupFactoryBean()
Creates a new uninitialized CommandGroupFactoryBean. If created by the Spring IoC container, the groupId assigned to this instance will be the bean name of the bean as declared in the bean definition file. If using this constructor, a non-null list of command group members must be provided by calling the setMembers(Object[]) method before this instance is used.


CommandGroupFactoryBean

public CommandGroupFactoryBean(String groupId,
                               Object[] members)
Creates a new CommandGroupFactoryBean with the given group ID and command group members.

Parameters:
groupId - The identifier that will be assigned to the command group produced by this factory. Note that if this instance is created by a Spring IoC container, the group ID provided here will be overwritten by the bean name of this instance's bean definition.
members - The collection of objects that specify the members of the command group. These objects are expected to be either instances of AbstractCommand or strings. See the class documentation for details on how these strings will be interpreted. Must not be null.
Throws:
IllegalArgumentException - if members is null.

CommandGroupFactoryBean

public CommandGroupFactoryBean(String groupId,
                               CommandRegistry commandRegistry,
                               Object[] members)
Creates a new CommandGroupFactoryBean.

Parameters:
groupId - The value to be used as the command identifier of the command group produced by this factory.
commandRegistry - The registry that will be used to retrieve the actual instances of the command group members as specified in members.
members - The collection of objects that specify the members of the command group. These objects are expected to be either instances of AbstractCommand or strings. See the class documentation for details on how these strings will be interpreted. Must not be null.
Throws:
IllegalArgumentException - if members is null.

CommandGroupFactoryBean

public CommandGroupFactoryBean(String groupId,
                               CommandRegistry commandRegistry,
                               CommandConfigurer commandConfigurer,
                               Object[] members)
Creates a new CommandGroupFactoryBean.

Parameters:
groupId - The value to be used as the command identifier of the command group produced by this factory.
commandRegistry - The registry that will be used to retrieve the actual instances of the command group members as specified in members.
members - The collection of objects that specify the members of the command group. These objects are expected to be either instances of AbstractCommand or strings. See the class documentation for details on how these strings will be interpreted. Must not be null.
commandConfigurer - The object that will be used to configure the command objects contained in this factory's command group.
Throws:
IllegalArgumentException - if members is null.
Method Detail

afterPropertiesSet

public void afterPropertiesSet()

Specified by:
afterPropertiesSet in interface InitializingBean

setCommandRegistry

public void setCommandRegistry(CommandRegistry commandRegistry)
Sets the registry that will be used to retrieve the actual instances of the command group members as specified in the encoded members collection.

Parameters:
commandRegistry - The registry containing commands for the command group produced by this factory. May be null.

getCommandRegistry

protected CommandRegistry getCommandRegistry()
Returns:
commandRegistry containing commands for this command group.

setCommandConfigurer

public void setCommandConfigurer(CommandConfigurer configurer)
Sets the object that will be used to configure the command objects in the command groups produced by this factory.

Parameters:
configurer - The command configurer, may be null.

setMembers

public final void setMembers(Object[] members)
Sets the collection of objects that specify the members of the command group produced by this factory. The objects in members are expected to be either instances of AbstractCommand or strings. See the class documentation for details on how these strings will be interpreted.

Parameters:
members - The (possibly) encoded representation of the command group members. Must not be null.
Throws:
IllegalArgumentException - if members is null.

getMembers

protected Object[] getMembers()
Returns:
the possibly encoded representation of the command group members.

setBeanName

public void setBeanName(String beanName)
Accepts notification from the IoC container of this instance's bean name as declared in the bean definition file. This value is used as the id of the command group produced by this factory.

Specified by:
setBeanName in interface BeanNameAware

getBeanName

protected String getBeanName()
Returns:
beanName.

isExclusive

public boolean isExclusive()
Returns the value of the flag that indicates whether or not this factory produces an exclusive command group.

Returns:
The exclusive flag.
See Also:
ExclusiveCommandGroup

setExclusive

public void setExclusive(boolean exclusive)
Sets the flag that indicates whether or not this factory produces an exclusive command group.

Parameters:
exclusive - true to produce an exclusive command group, false otherwise.
See Also:
ExclusiveCommandGroup

setAllowsEmptySelection

public void setAllowsEmptySelection(boolean allowsEmptySelection)
Sets the flag that indicates whether or not the command group produced by this factory allows no items in the group to be selected, default is false. This is only relevant for exclusive command groups.

Parameters:
allowsEmptySelection - Set true for the command group to allow none of its members to be selected.

isAllowsEmptySelection

protected boolean isAllowsEmptySelection()
Returns:
true if the exclusive commandGroup can have no item selected.

getObject

public Object getObject()
                 throws Exception
Returns the command group that this factory produces.

Specified by:
getObject in interface FactoryBean
Returns:
The factory's command group, never null.
Throws:
Exception

getCommandGroup

public CommandGroup getCommandGroup()
Returns the command group that this factory produces.

Returns:
The factory's command group, never null.

createCommandGroup

protected CommandGroup createCommandGroup()
Creates the command group for this factory and assigns it an identifier equal to the group id of the factory. The command group will also be assigned the security controller id, if any, that was provided via the setSecurityControllerId(String) method and the values from the encoded members list will be used to retrieve the corresponding command objects from the command registry.

Returns:
The command group, never null.

initCommandGroupMembers

protected void initCommandGroupMembers(CommandGroup group)
Iterates over the collection of encoded members and adds them to the given command group.

Parameters:
group - The group that is to contain the commands from the encoded members list. Must not be null.
Throws:
InvalidGroupMemberEncodingException - if a member prefix is provided without a command id.

configureIfNecessary

protected void configureIfNecessary(AbstractCommand command)
Configures the given command if it has not already been configured and this instance has been provided with a CommandConfigurer.

Parameters:
command - The command to be configured.
Throws:
IllegalArgumentException - if command is null.

getObjectType

public Class getObjectType()
Returns the Class object for CommandGroup.

Specified by:
getObjectType in interface FactoryBean
Returns:
CommandGroup.class

isSingleton

public boolean isSingleton()
Always returns true. The command groups produced by this factory are always singletons.

Specified by:
isSingleton in interface FactoryBean
Returns:
true always.

setSecurityControllerId

public void setSecurityControllerId(String controllerId)
Set the Id of the security controller that should manage this object.

Specified by:
setSecurityControllerId in interface SecurityControllable
Parameters:
controllerId - Id (bean name) of the security controller

getSecurityControllerId

public String getSecurityControllerId()
Get the id (bean name) of the security controller that should manage this object.

Specified by:
getSecurityControllerId in interface SecurityControllable
Returns:
controller id

setAuthorized

public void setAuthorized(boolean authorized)
Set the authorized state.

Specified by:
setAuthorized in interface Authorizable
Parameters:
authorized - Pass true if the object is to be authorized

isAuthorized

public boolean isAuthorized()
Get the authorized state.

Specified by:
isAuthorized in interface Authorizable
Returns:
authorized


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