com.sas.commands
Class CompositeDynamicAttributeCommand

com.sas.commands.CompositeDynamicAttributeCommand
All Implemented Interfaces:
CompositeDynamicAttributeCommandInterface, DynamicAttributeCommandInterface, BaseEntityInterface, BaseEntityValueInterface, EntityKeyInterface, com.sas.lang.StringDataInterface, com.sas.PublicClonable, com.sas.util.ApplyInterface, com.sas.util.Command, com.sas.util.SimpleCommand, java.lang.Cloneable, java.rmi.Remote

public class CompositeDynamicAttributeCommand
implements DynamicAttributeCommandInterface, com.sas.util.ApplyInterface, CompositeDynamicAttributeCommandInterface

A command which manages the order of execution and rollback for a group of sub-commands.

This command also allows for the application of dynamic attributes to each of the sub-commands when the sub-commands have unique names.

Since:
3.0

Field Summary
 
Fields inherited from interface com.sas.commands.DynamicAttributeCommandInterface
COMMAND_NAME_PREFIX
 
Fields inherited from interface com.sas.util.ApplyInterface
ABORT, CONTINUE
 
Constructor Summary
CompositeDynamicAttributeCommand()
          Default constructor
CompositeDynamicAttributeCommand(java.lang.String name)
          Name Constructor.
 
Method Summary
 void add(DynamicAttributeCommandInterface command, java.util.Map dynamicAttributeNames)
          Add a command to be executed during this Composite command's execute().
 int apply(java.lang.Object obj)
          Executes all executable sub-commands.
protected  void applyCommandAttributes(DynamicAttributeCommandInterface command)
           
 java.lang.Object clone()
          Clones this command.
 void execute(java.lang.Object obj)
          Executes all the executable sub-commands in the order that they were added.
 java.util.Collection getCommandAttributeNames()
          Returns a collection containing the names of all the composite command's dynamic attributes.
 java.util.List getCommands()
           
 java.util.Locale getLocale()
          Returns the command's locale
 java.lang.String getName()
          Returns the name of the command.
static java.lang.String getNextCommandName()
          Returns a unique command name.
 java.lang.String getText()
          Placeholder to satisy interface requirements.
 boolean isExecutable()
          Returns true if any sub-command is executable.
 boolean isUndoable()
          Returns the boolean indicating whether the last operation this command executed can be undone ( rolled back ).
 void remove(DynamicAttributeCommandInterface command)
          Removes a command from the list of commands to be executed during this Composite command's execute().
static void setCommonAttribute(java.util.Collection commands, java.lang.String attributeName, java.lang.Object attributeValue)
          Sets the specified attribute on all sub-commands of type DynamicAttributeCommandInterface.
 void setCommonAttribute(java.lang.String attributeName, java.lang.Object attributeValue)
          Sets the specified attribute on all sub-commands.
 void setLocale(java.util.Locale loc)
          Sets the command's locale
 void setName(java.lang.String name)
          Sets the name of the command.
 void setText(java.lang.String text)
          Placeholder to satisy interface requirements.
 void undo()
          Undo all the sub-commands in reverse order of their execution().
 
Methods inherited from class com.sas.entities.BaseEntity
containsAttributeNamed, equals, equals, getAttribute, getAttribute, getAttributeCount, getAttributes, getEntityKey, getPropertyDescriptors, getStringAttribute, listAttributeNames, removeAllAttributes, removeAttribute, reset, sameEntity, setAttribute, setAttributes, setEntityKey, toString
 
Methods inherited from interface com.sas.entities.BaseEntityValueInterface
getAttribute, setAttribute
 

Constructor Detail

CompositeDynamicAttributeCommand

public CompositeDynamicAttributeCommand()
Default constructor


CompositeDynamicAttributeCommand

public CompositeDynamicAttributeCommand(java.lang.String name)
Name Constructor.

Parameters:
name - The name of this command.
See Also:
execute(java.lang.Object), add(com.sas.commands.DynamicAttributeCommandInterface, java.util.Map)
Method Detail

getName

public java.lang.String getName()
Returns the name of the command.

Specified by:
getName in interface DynamicAttributeCommandInterface
Returns:
name of the command
See Also:
setName(java.lang.String)

setName

public void setName(java.lang.String name)
Sets the name of the command.

To ensure unique command names use the getNextCommandName() method.

Specified by:
setName in interface DynamicAttributeCommandInterface
Parameters:
name - unique name of the command.
See Also:
getName()

setLocale

public void setLocale(java.util.Locale loc)
Sets the command's locale

Parameters:
loc - the locale
See Also:
getLocale()

getLocale

public java.util.Locale getLocale()
Returns the command's locale

Returns:
locale
See Also:
setLocale(java.util.Locale)

getNextCommandName

public static java.lang.String getNextCommandName()
Returns a unique command name.

Convenience method for ensuring commands are given unique names.

Returns:
a unique name for a command.
See Also:
setName(java.lang.String)

add

public void add(DynamicAttributeCommandInterface command,
                java.util.Map dynamicAttributeNames)
Add a command to be executed during this Composite command's execute().

Parameters:
command - The command to be added.
dynamicAttributeNames - Mappings from the composite's attribute name to the command's corresponding attribute name.
Throws:
java.lang.IllegalArgumentException - if command is null.
java.lang.IllegalStateException - if a composite attribute name is already registered.
See Also:
execute(java.lang.Object)

remove

public void remove(DynamicAttributeCommandInterface command)
Removes a command from the list of commands to be executed during this Composite command's execute().

Parameters:
command - The command to be remove.
Throws:
java.lang.IllegalArgumentException - if command is null.
See Also:
execute(java.lang.Object)

clone

public java.lang.Object clone()
                       throws java.lang.CloneNotSupportedException
Clones this command.

Specified by:
clone in interface com.sas.PublicClonable
Specified by:
clone in interface com.sas.util.Command
Overrides:
clone in class BaseEntity
Returns:
a new command equivalent to this one
Throws:
java.lang.CloneNotSupportedException - this class supports cloning, but a subclass may not

isExecutable

public boolean isExecutable()
Returns true if any sub-command is executable.

If present, dynamic attributes are applied to each sub-command before each command is asked isExecutable().

Note that it should do no harm to call execute(object) even if isExecutable() returns false.

Specified by:
isExecutable in interface com.sas.util.Command
Returns:
true if any of the sub-commands are executable. false otherwise
See Also:
execute(java.lang.Object)

execute

public void execute(java.lang.Object obj)
Executes all the executable sub-commands in the order that they were added.

This method does no error checking on the success of each command execution. It will execute all executable commands unless an exception is thrown.

Specified by:
execute in interface com.sas.util.SimpleCommand
Parameters:
obj - passed to the execute(Object) method of all sub-commands
See Also:
undo()

apply

public int apply(java.lang.Object obj)
Executes all executable sub-commands.

If any executable command implements ApplyInterface, then its apply method is called, otherwise its execute() method is called.

If the apply method does not return ApplyInterface.CONTINUE, then the next command will not be executed and the value will be returned.

Specified by:
apply in interface com.sas.util.ApplyInterface
Parameters:
obj - passed to the apply(Object) or execute(Object) methods of both commands
Returns:
ApplyInterface.CONTINUE or ApplyInterface.ABORT
See Also:
execute(java.lang.Object), ApplyInterface.CONTINUE

isUndoable

public boolean isUndoable()
Returns the boolean indicating whether the last operation this command executed can be undone ( rolled back ).

Returns true if all the executed sub-commands are undoable.

Specified by:
isUndoable in interface com.sas.util.Command
Returns:
the boolean indicating whether the last operation this command executed can be undone ( rolled back ).
See Also:
undo()

undo

public void undo()
Undo all the sub-commands in reverse order of their execution().

Specified by:
undo in interface com.sas.util.Command
See Also:
execute(java.lang.Object)

getText

public java.lang.String getText()
Placeholder to satisy interface requirements.

Specified by:
getText in interface com.sas.lang.StringDataInterface
Returns:
the empty string ("")
See Also:
setText(java.lang.String)

setText

public void setText(java.lang.String text)
Placeholder to satisy interface requirements.

Does nothing

Specified by:
setText in interface com.sas.lang.StringDataInterface
Parameters:
text - the command's text
See Also:
getText()

setCommonAttribute

public void setCommonAttribute(java.lang.String attributeName,
                               java.lang.Object attributeValue)
Sets the specified attribute on all sub-commands.

For use when all sub-commands need the same attribute set with the same value.

Internally it calls setCommonAttribute(List commands, String attributeName, Object attributeValue )

Specified by:
setCommonAttribute in interface CompositeDynamicAttributeCommandInterface
Parameters:
attributeName - The name of the attribute to set on all sub-commands.
attributeValue - The value of the attribute.

setCommonAttribute

public static void setCommonAttribute(java.util.Collection commands,
                                      java.lang.String attributeName,
                                      java.lang.Object attributeValue)
Sets the specified attribute on all sub-commands of type DynamicAttributeCommandInterface.

For use when all sub-commands need the same attribute set with the same value.

Parameters:
commands - The collection of DynamicAttributeCommandInterface sub-commands.
attributeName - The name of the attribute to set on all sub-commands.
attributeValue - The value of the attribute.

applyCommandAttributes

protected void applyCommandAttributes(DynamicAttributeCommandInterface command)

getCommandAttributeNames

public java.util.Collection getCommandAttributeNames()
Returns a collection containing the names of all the composite command's dynamic attributes.

Specified by:
getCommandAttributeNames in interface CompositeDynamicAttributeCommandInterface
Returns:
a collection of command attribute names.

getCommands

public java.util.List getCommands()



Copyright © 2009 SAS Institute Inc. All Rights Reserved.