The Command interface provides a layer of separation between the code specifying some behavior and the code invoking that behavior. This separation aids in creating reusable code. For example, a {@link com.google.gwt.user.client.ui.MenuItem} can have a Command associatedwith it that it executes when the menu item is chosen by the user. Importantly, the code that constructed the Command to be executed when the menu item is invoked knows nothing about the internals of the MenuItem class and vice-versa.
The Command interface is often implemented with an anonymous inner class. For example,
Command sayHello = new Command() { public void execute() { Window.alert("Hello"); } }; sayHello.execute();This type extends ScheduledCommand to help migrate from DeferredCommand API.
Represents a logical "unit of work" that includes a request context, JSP, URLPattern, content template and (optionally) a target and required security permission. Examples of Commands include "view a page," "create a group," and "edit user preferences."
Commands come in two flavors: "static" and "targeted."
final
, threadsafe, and immutable. They have no intrinsic idea of the context they are acting in. For example, the static command {@link PageCommand#VIEW} embodies the idea of viewing a page —but exactly which page is left undefined. Static commands exist so that they can be freely shared and passed around without incurring the penalties of object creation. Static commands are a lot like naked request contexts ("edit", "view", etc.) except that they include additional, essential properites such as the associated URL pattern and content JSP.Concrete implementations of Command include:
For a given targeted Command, its {@link #getTarget()} method will return anon-null
value. In addition, its {@link #requiredPermission()} method will generally also return a non-null
value. It is each implementation's responsibility to construct and store the correct Permission for a given Command and Target. For example, when PageCommand.VIEW is targeted at the WikiPage Main
, the Command's associated permission is PagePermission "theWiki:Main", "view".
Static Commands, and targeted Commands that do not require specific permissions to execute, return a null
result for {@link #requiredPermission()}.
The Command interface provides a layer of separation between the code specifying some behavior and the code invoking that behavior. This separation aids in creating reusable code. For example, a {@link com.google.gwt.user.client.ui.MenuItem} can have a Commandassociated with it that it executes when the menu item is chosen by the user. Importantly, the code that constructed the Command to be executed when the menu item is invoked knows nothing about the internals of the MenuItem class and vice-versa.
The Command interface is often implemented with an anonymous inner class. For example,
Command sayHello = new Command() { public void execute() { Window.alert("Hello"); } }; sayHello.execute();
A command is composed of three elements:
Command
.The basic command syntax is fairly simple:
\
character will escape the following character and be removed from the tokens."
character will escape all characters until the next occurence of "
, except for \
."
characters are not removed from the resulting tokens. It's also possible to include keywords in a command:
$f
is replaced by a file's full path.$n
is replaced by a file's name.$e
is replaced by a file's extension.$N
is replaced by a file's name without its extension.$p
is replaced by a file's parent's path.$j
is replaced by the path of the folder in which the JVM was started. Once a Command
instance has been retrieved, execution tokens can be retrieved through the {@link #getTokens(AbstractFile)} method. This will return a tokenized version of the command and replace anykeyword by the corresponding file value . It's also possible to skip keyword replacement through the {@link #getTokens()} method.
A command's executable tokens are typically meant to be used with {@link com.mucommander.process.ProcessRunner#execute(String[],AbstractFile)}in order to generate instances of {@link com.mucommander.process.AbstractProcess}.
@author Nicolas Rinaudo @see CommandManager @see com.mucommander.process.ProcessRunner @see com.mucommander.process.AbstractProcessThis class represents a Command.
Created March 31, 2011 @author Ken Paulsen kenapaulsen@gmail.comexecute
-method.
@author Michael N. Lipp
Invariant: expects == -1, 0, or 1
Invariant: overall >= -1
Invariant: bitwidth >= -1
Invariant: maxseq >= -1
Invariant: maxstring >= -1
The CommandDispatcher and the HelpCommand operate on this interface. This interface needs to be implemented by your own Commands or Plugins that should be supported by HenPlus. If the documenation given here is not enough (though I hope it is), just read some of the implementations given in henplus.commands.
If you are writing Plugins, consider extending the {@link AbstractCommand} as it provides a default implementation and you areimmune to NoSuchMethodErrors if this interface changes but not yet your plugin...
This interface is defined as an abstract class so we can define static methods.
@version $Revision: 1.11 $ @author Henner ZellerCommand
class is a construct that encapsulates the semantic information of an action. The behavior that the command activates is not encapsulated in this object. This means that command contains only information about "command" not the actual action that happens when command is activated. The action is defined in a {@link CommandListener CommandListener}associated with the Displayable
. Command
objects are presented in the user interface and the way they are presented may depend on the semantic information contained within the command. Commands
may be implemented in any user interface construct that has semantics for activating a single action. This, for example, can be a soft button, item in a menu, or some other direct user interface construct. For example, a speech interface may present these commands as voice tags.
The mapping to concrete user interface constructs may also depend on the total number of the commands. For example, if an application asks for more abstract commands than can be mapped onto the available physical buttons on a device, then the device may use an alternate human interface such as a menu. For example, the abstract commands that cannot be mapped onto physical buttons are placed in a menu and the label "Menu" is mapped onto one of the programmable buttons.
A command contains four pieces of information: a short label, an optional long label, a type, and a priority. One of the labels is used for the visual representation of the command, whereas the type and the priority indicate the semantics of the command.
Each command includes one or two label strings. The label strings are what the application requests to be shown to the user to represent this command. For example, one of these strings may appear next to a soft button on the device or as an element in a menu. For command types other than SCREEN
, the labels provided may be overridden by a system-specific label that is more appropriate for this command on this device. The contents of the label strings are otherwise not interpreted by the implementation.
All commands have a short label. The long label is optional. If the long label is not present on a command, the short label is always used.
The short label string should be as short as possible so that it consumes a minimum of screen real estate. The long label can be longer and more descriptive, but it should be no longer than a few words. For example, a command's short label might be "Play", and its long label might be "Play Sound Clip".
The implementation chooses one of the labels to be presented in the user interface based on the context and the amount of space available. For example, the implementation might use the short label if the command appears on a soft button, and it might use the long label if the command appears on a menu, but only if there is room on the menu for the long label. The implementation may use the short labels of some commands and the long labels of other commands, and it is allowed to switch between using the short and long label at will. The application cannot determine which label is being used at any given time.
The application uses the command type to specify the intent of this command. For example, if the application specifies that the command is of type BACK
, and if the device has a standard of placing the "back" operation on a certain soft-button, the implementation can follow the style of the device by using the semantic information as a guide. The defined types are {@link #BACK BACK}, {@link #CANCEL CANCEL}, {@link #EXIT EXIT}, {@link #HELP HELP}, {@link #ITEM ITEM}, {@link #OK OK}, {@link #SCREEN SCREEN}, and {@link #STOP STOP}.
The application uses the priority value to describe the importance of this command relative to other commands on the same screen. Priority values are integers, where a lower number indicates greater importance. The actual values are chosen by the application. A priority value of one might indicate the most important command, priority values of two, three, four, and so on indicate commands of lesser importance.
Typically, the implementation first chooses the placement of a command based on the type of command and then places similar commands based on a priority order. This could mean that the command with the highest priority is placed so that user can trigger it directly and that commands with lower priority are placed on a menu. It is not an error for there to be commands on the same screen with the same priorities and types. If this occurs, the implementation will choose the order in which they are presented.
For example, if the application has the following set of commands:
|
An implementation with two soft buttons may map the BACK
command to the right soft button and create an "Options" menu on the left soft button to contain the other commands.
When user presses the left soft button, a menu with the two remaining Commands
appears:
If the application had three soft buttons, all commands can be mapped to soft buttons:
The application is always responsible for providing the means for the user to progress through different screens. An application may set up a screen that has no commands. This is allowed by the API but is generally not useful; if this occurs the user would have no means to move to another screen. Such program would simply considered to be in error. A typical device should provide a means for the user to direct the application manager to kill the erroneous application. @since MIDP 1.0
GET
and POST
commands. The commands are for GET
:
POST
: For example updating an enterprise application in an application may be composed of a list of commands to undeploy, update and redeploy the enterprise application. Each of these commands needs to be revertible so that if for example the final redeployment step fails, the prior update and undeployment steps can get reverted in order. If each of the commands in the list has ACID properties, then this results in the composed command to have ACID properties too, and thus work similar to a transaction.
Note that commands are generally not idempotent, that is once they have been successfully executed, you may not be able to successfully execute them again because the preconditions are no longer met. However, commands must be restartable, that is if {@link #perform()} hasthrown an exception and {@link #revert()} has succeeded, then clients canstill successfully execute the command as soon as the preconditions are met again. @see Commands#execute @see CompositeCommand @author Christian Schlichtherle
$Id: Command.java 181 2010-12-12 23:39:00Z georgosn $
@author $LastChangedBy: georgosn $ @version $LastChangedRevision: 181 $An encapsulation for a unit of work that needs to performed to accomplish a task. A Command chooses whether to execute based on the information available to it in the {@link Context}.
A {@link Command} encapsulates a unit of processing work to beperformed, whose purpose is to examine and/or modify the state of a transaction that is represented by a {@link Context}. Individual {@link Command}s can be assembled into a {@link Chain}, which allows them to either complete the required processing or delegate further processing to the next {@link Command} in the {@link Chain}.
{@link Command} implementations should be designed in a thread-safemanner, suitable for inclusion in multiple {@link Chain}s that might be processed by different threads simultaneously. In general, this implies that {@link Command} classes should not maintain state information ininstance variables. Instead, state information should be maintained via suitable modifications to the attributes of the {@link Context} that ispassed to the execute()
command.
{@link Command} implementations typically retrieve and store stateinformation in the {@link Context} instance that is passed as a parameterto the execute()
method, using particular keys into the Map
that can be acquired via Context.getAttributes()
. To improve interoperability of {@link Command} implementations, a useful design pattern is to expose thekey values used as JavaBeans properties of the {@link Command}implementation class itself. For example, a {@link Command} that requiresan input and an output key might implement the following properties:
private String inputKey = "input"; public String getInputKey() { return (this.inputKey); } public void setInputKey(String inputKey) { this.inputKey = inputKey; } private String outputKey = "output"; public String getOutputKey() { return (this.outputKey); } public void setOutputKey(String outputKey) { this.outputKey = outputKey; }
And the operation of accessing the "input" information in the context would be executed by calling:
String input = (String) context.get(getInputKey());
instead of hard coding the attribute name. The use of the "Key" suffix on such property names is a useful convention to identify properties being used in this fashion, as opposed to JavaBeans properties that simply configure the internal operation of this {@link Command}.
@author Craig R. McClanahan @version $Revision: 1.5 $ $Date: 2004/02/25 00:01:07 $Command
is a named {@link org.apache.karaf.shell.api.console.Function}which also provides completion.
Represents a logical "unit of work" that includes a request context, JSP, URLPattern, content template and (optionally) a target and required security permission. Examples of Commands include "view a page," "create a group," and "edit user preferences."
Commands come in two flavors: "static" and "targeted."
final
, threadsafe, and immutable. They have no intrinsic idea of the context they are acting in. For example, the static command {@link PageCommand#VIEW} embodies the idea of viewing a page —but exactly which page is left undefined. Static commands exist so that they can be freely shared and passed around without incurring the penalties of object creation. Static commands are a lot like naked request contexts ("edit", "view", etc.) except that they include additional, essential properites such as the associated URL pattern and content JSP.Concrete implementations of Command include:
For a given targeted Command, its {@link #getTarget()} method will return anon-null
value. In addition, its {@link #requiredPermission()} method will generally also return a non-null
value. It is each implementation's responsibility to construct and store the correct Permission for a given Command and Target. For example, when PageCommand.VIEW is targeted at the WikiPage Main
, the Command's associated permission is PagePermission "theWiki:Main", "view".
Static Commands, and targeted Commands that do not require specific permissions to execute, return a null
result for {@link #requiredPermission()}.
A command is an abstract representation for some semantic behaviour. It is not the actual implementation of this behaviour, nor is it the visual appearance of this behaviour in the user interface. Instead, it is a bridge between the two.
The concept of a command is based on the command design pattern. The notable difference is how the command delegates responsibility for execution. Rather than allowing concrete subclasses, it uses a handler mechanism (see the handlers
extension point). This provides another level of indirection.
A command will exist in two states: defined and undefined. A command is defined if it is declared in the XML of a resolved plug-in. If the plug-in is unloaded or the command is simply not declared, then it is undefined. Trying to reference an undefined command will succeed, but trying to access any of its functionality will fail with a NotDefinedException
. If you need to know when a command changes from defined to undefined (or vice versa), then attach a command listener.
Commands are mutable and will change as their definition changes.
@since 3.1There are important constraints on the valid order in which the various methods may be invoked, e.g., you cannot ask for the result before you've executed the command. These constraints are documented with the various methods.
Purpose: Provide an extendable framework class for a Command object that can be remotely executed.
Description: Is the root command class from which all other remotely executable commands must extend. A Command is invoked by calling propagateCommand() on a local CommandManager, and is executed on each remote service by each remote CommandManager invoking processCommand() on its local @see CommandManager @see CommandProcessor @author Steven Vo @since OracleAS TopLink 10g (9.0.4)
The normal implementation pattern for a JNode native command is to 'extend' the AbstractCommand class. This class provides implementations of the getters defined by this API along with a default implementations of the execute methods, and some special infrastructure to support the 'classic' Java command entry point. @author Martin Husted Hartvig (hagar@jnode.org) @author crawley@jnode.org
A command is encoded by the Transport Protocol Services on the initiator and decoded by the Transport Protocol Services on the target. This class provides enough information to accomplish this.
The Task Router enqueues the command on the proper Logical Unit where it is converted into a Task; some commands are processed directly by the Task Router. A Task uses the Target Transport Port to directly return any data or results.
Commands are single fire objects. They cannot be used more than once. This is to allow undoable commands to be a normal command, not a special case command.
Commands normally have factories associated with them, but they are also prototypes. The copy method returns a new MapCommand without the undo data. The new MapCommand can safely be executed with no negative side-effects.
@see A set of possible command categories are: zoom, pan, cut, paste, addVertex, etc.. Mostcommands are associated with tool whose job is to construct the commands. A MapCommand object describes an concrete change, for example: setBBox(0,0,1,1); setBBox(2,2,3,3) would be a separate object. @author jeicharIf a command accepts any and all parameter types and values, it does not need to define a set of parameter definitions. However, if a command accepts only a certain set of parameters, it must define a set of parameter definitions that determine the validity of a command's parameter values.
Note that command implementors are recommended to provide a set of parameter setter methods should they require parameters in order to be able to execute. This will allow a strongly-typed mechanism to be available in order to set parameters (as opposed to asking the client to add Object values to a weakly-typed map and/or checking the parameter definitions to ensure the parameter values are valid). It is highly recommended that the implementors of this interface define setter methods that take Objects as opposed to primitives (e.g. Integer
vs. int
) to make it easier for cmdline clients to {@link ParameterDefinition#convertObject(Object) convert} fromtext-based input to the Java representations of the actual data types needed.
<specifier> [<modifier>, ... ]
Both the specifier and the optional modifiers are called command elements. For example: load filename - load: is the command specifier - filename: is the command modifier
Both load
and filename
are considered command elements.
Created: 2002.09.08 @author Brad Zdanivsky @author Peter Brandt-Erichsen
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|