net.rim.device.api.command
Class Command

java.lang.Object
  extended by net.rim.device.api.command.Command

public final class Command
extends Object

Executes a command. You can think of a Command instance as a proxy to an instance of CommandHandler. It binds an instance of CommandHandler with an associated CommandMetadata instance.

For more information about using this class, see the package overview.

Since:
BlackBerry API 6.0.0

Constructor Summary
Command(CommandHandler commandHandler)
          Creates a Command instance using a passed-in CommandHandler.
Command(CommandHandler commandHandler, CommandMetadata metadata)
          Creates a Command instance using a passed-in CommandHandler and CommandMetadata.
Command(CommandHandler commandHandler, ReadOnlyCommandMetadata metadata)
          Creates a Command instance using a passed-in CommandHandler and ReadOnlyCommandMetadata.
Command(CommandMetadata metadata)
          Creates a Command instance using a passed-in CommandMetadata.
 
Method Summary
 boolean canExecute(Object context)
          Determines whether a call to execute() is valid using a passed-in context object.
 void execute(Object context)
          Executes the command using a passed-in context object.
 String getId()
          Returns the command's identifier.
 ReadOnlyCommandMetadata getMetadata()
          Returns the command's metadata.
 StringProvider getStringResource(int resourceId)
          Returns the localized string resource associated with a specified resource identifier.
 StringProvider getStringResource(String metadataId)
          Returns the localized string resource associated with a specified metadata identifier.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 



Constructor Detail

Command

public Command(CommandHandler commandHandler)
Creates a Command instance using a passed-in CommandHandler.

Parameters:
commandHandler - The CommandHandler to delegate to for the execute() and canExecute() methods.
Since:
BlackBerry API 6.0.0

Command

public Command(CommandHandler commandHandler,
               CommandMetadata metadata)
Creates a Command instance using a passed-in CommandHandler and CommandMetadata.

Parameters:
commandHandler - The CommandHandler to delegate to for the execute() and canExecute() methods.
metadata - The command's metadata instance.
Since:
BlackBerry API 6.0.0

Command

public Command(CommandHandler commandHandler,
               ReadOnlyCommandMetadata metadata)
Creates a Command instance using a passed-in CommandHandler and ReadOnlyCommandMetadata.

Parameters:
commandHandler - The CommandHandler to delegate to for the execute() and canExecute() methods.
metadata - The command's metadata instance.
Since:
BlackBerry API 7.0.0

Command

public Command(CommandMetadata metadata)
Creates a Command instance using a passed-in CommandMetadata.

Parameters:
metadata - The command's metadata instance.
Since:
BlackBerry API 6.0.0


Method Detail

canExecute

public boolean canExecute(Object context)
Determines whether a call to execute() is valid using a passed-in context object. Implementations of this method can ignore the passed-in context object.

Parameters:
context - External state information.
Returns:
true if the execute() method can be called, false otherwise.
Since:
BlackBerry API 6.0.0

execute

public void execute(Object context)
Executes the command using a passed-in context object. Implementations of this method can ignore the passed-in context object.

Parameters:
context - External state information.
Since:
BlackBerry API 6.0.0

getMetadata

public ReadOnlyCommandMetadata getMetadata()
Returns the command's metadata.

Returns:
The metadata. Never returns null.
Since:
BlackBerry API 6.0.0

getId

public String getId()
Returns the command's identifier.

Returns:
The command's identifier. Never returns null.
Since:
BlackBerry API 6.0.0

getStringResource

public StringProvider getStringResource(String metadataId)
Returns the localized string resource associated with a specified metadata identifier. This method expects the associated metadata to contain a resource bundle name attribute whose value is the name of the resource bundle to use.

If the method call is invalid for any reason, a non-null StringProvider will be returned whose toString() method returns null.

StringProvider instances created as a result of calling this method will be cached by this instance.

Parameters:
metadataId - The metadata identifier. Should be contained in the associated metadata instance's resource bundle.
Returns:
The localized string resource. Never returns null.
See Also:
CommandMetadata.RESOURCE_BUNDLE_NAME
Since:
BlackBerry API 6.0.0

getStringResource

public StringProvider getStringResource(int resourceId)
Returns the localized string resource associated with a specified resource identifier. This method expects the associated metadata to contain a resource bundle name attribute whose value is the name of the resource bundle to use.

If the method call is invalid for any reason, a non-null StringProvider will be returned whose toString() method returns null.

StringProvider instances created as a result of calling this method will be cached by this instance.

Parameters:
resourceId - The resource identifier.
Returns:
The localized string resource. Never returns null.
See Also:
CommandMetadata.RESOURCE_BUNDLE_NAME
Since:
BlackBerry API 6.0.0





Copyright 1999-2011 Research In Motion Limited. 295 Phillip Street, Waterloo, Ontario, Canada, N2L 3W8. All Rights Reserved.
Java is a trademark of Oracle America Inc. in the US and other countries.
Legal