Command Framework API

You can use the Command Framework API in the net.rim.device.api.command package to define functionality that you can use in different locations in your application or in other applications on the BlackBerry® device.

The Command Framework API contains command handlers, command metadata, and commands.

Component

Description

Command handler

You use the CommandHandler class to define functionality that you want to make available in your application or in other applications on the device. You create a class that extends the abstract CommandHandler class and define the functionality in the class's execute() method. That functionality is called a command.

Command metadata

You use the CommandMetadata class to define metadata that describes a command. Each command's metadata is encapsulated in a CommandMetadata object. The only required piece of metadata for a command is the command's ID, which is provided when the CommandMetadata object is constructed and is stored in the object's COMMAND_ID field.

CommandMetadata provides other fields for you to use to describe the command, such as RESOURCE_BUNDLE_NAME, to which you can assign the name of the resource bundle that is used by the command. You can also define metadata items that are specific to a particular command.

Command

You use the Command class to execute a command. You can think of a Command instance as a proxy to an instance of a class that extends CommandHandler. When Command.execute() is invoked, the call is delegated to the associated CommandHandler instance, passing the current context and transparently passing a read-only version of the associated command metadata for execution.

The Command Framework API provides two registries that you can use to store your commands:

  • You can use the local registry to store commands for use in your application by using the LocalCommandRegistrarConnection class.
  • You can use the global registry to store commands for use in other applications on the device by using the RemoteCommandRegistrarConnection class.

The Command Framework Demo and Command Framework Demo Remote App sample applications are included in the BlackBerry® Java® SDK. These sample applications demonstrate how to define and use commands in a single application and how to define commands in one application and use them in other applications.


Was this information helpful? Send us your comments.