public abstract class AdHocCommand extends Object
getForm
method retrieves a form with all the users.
Each command has a node that should be unique within a given JID.
Commands may have zero or more stages. Each stage is usually used for gathering information required for the command execution. Users are able to move forward or backward across the different stages. Commands may not be cancelled while they are being executed. However, users may request the "cancel" action when submitting a stage response indicating that the command execution should be aborted. Thus, releasing any collected information. Commands that require user interaction (i.e. have more than one stage) will have to provide the data forms the user must complete in each stage and the allowed actions the user might perform during each stage (e.g. go to the previous stage or go to the next stage).
All the actions may throw an XMPPException if there is a problem executing them. TheXMPPError
of that exception may have some specific
information about the problem. The possible extensions are:
See the SpecificErrorCondition
class for detailed description
of each one.
getSpecificErrorConditionFrom
to obtain the specific
information from an XMPPError
.Modifier and Type | Class and Description |
---|---|
static class |
AdHocCommand.Action |
static class |
AdHocCommand.SpecificErrorCondition |
static class |
AdHocCommand.Status
The status of the stage in the adhoc command.
|
Constructor and Description |
---|
AdHocCommand() |
Modifier and Type | Method and Description |
---|---|
protected void |
addActionAvailable(AdHocCommand.Action action)
Add an action to the current stage available actions.
|
protected void |
addNote(AdHocCommandNote note)
Adds a note to the current stage.
|
abstract void |
cancel()
Cancels the execution of the command.
|
abstract void |
complete(Form response)
Completes the command execution with the information provided in the
response . |
abstract void |
execute()
Executes the command.
|
protected List<AdHocCommand.Action> |
getActions()
Returns a collection with the allowed actions based on the current stage.
|
protected AdHocCommand.Action |
getExecuteAction()
Returns the action available for the current stage which is
considered the equivalent to "execute".
|
Form |
getForm()
Returns the form of the current stage.
|
String |
getName()
Returns the human readable name of the command.
|
String |
getNode()
Returns the unique identifier of the command.
|
List<AdHocCommandNote> |
getNotes()
Returns the notes that the command has at the current stage.
|
abstract Jid |
getOwnerJID()
Returns the full JID of the owner of this command.
|
String |
getRaw() |
static AdHocCommand.SpecificErrorCondition |
getSpecificErrorCondition(StanzaError error)
Returns the specific condition of the
error or null if the
error doesn't have any. |
AdHocCommand.Status |
getStatus()
Returns the status of the current stage.
|
boolean |
isCompleted()
Check if this command has been completed successfully.
|
protected boolean |
isValidAction(AdHocCommand.Action action)
Returns true if the
action is available in the current stage. |
abstract void |
next(Form response)
Executes the next action of the command with the information provided in
the
response . |
abstract void |
prev()
Goes to the previous stage.
|
protected void |
setExecuteAction(AdHocCommand.Action action)
Sets which of the actions available for the current stage is
considered the equivalent to "execute".
|
protected void |
setForm(Form form)
Sets the form of the current stage.
|
void |
setName(String name)
Set the the human readable name of the command, usually used for
displaying in a UI.
|
void |
setNode(String node)
Sets the unique identifier of the command.
|
public AdHocCommand()
public static AdHocCommand.SpecificErrorCondition getSpecificErrorCondition(StanzaError error)
error
or null if the
error doesn't have any.error
- the error the get the specific condition from.public void setName(String name)
name
- the name.public String getName()
public void setNode(String node)
OwnerJID
.node
- the unique identifier of the command.public String getNode()
OwnerJID
.public abstract Jid getOwnerJID()
public List<AdHocCommandNote> getNotes()
protected void addNote(AdHocCommandNote note)
getNotes()
method during the current stage.
Once the stage changes all the notes are discarded.note
- the note.public Form getForm()
protected void setForm(Form form)
form
- the form of the current stage to fill out or the result of the
execution.public abstract void execute() throws SmackException.NoResponseException, XMPPException.XMPPErrorException, SmackException.NotConnectedException, InterruptedException
SmackException.NoResponseException
XMPPException.XMPPErrorException
- if there is an error executing the command.SmackException.NotConnectedException
InterruptedException
public abstract void next(Form response) throws SmackException.NoResponseException, XMPPException.XMPPErrorException, SmackException.NotConnectedException, InterruptedException
response
. This form must be the answer form of the
previous stage. This method will be only invoked for commands that have one
or more stages. If there is a problem executing the command it throws an
XMPPException.response
- the form answer of the previous stage.SmackException.NoResponseException
XMPPException.XMPPErrorException
- if there is a problem executing the command.SmackException.NotConnectedException
InterruptedException
public abstract void complete(Form response) throws SmackException.NoResponseException, XMPPException.XMPPErrorException, SmackException.NotConnectedException, InterruptedException
response
. This form must be the answer form of the
previous stage. This method will be only invoked for commands that have one
or more stages. If there is a problem executing the command it throws an
XMPPException.response
- the form answer of the previous stage.SmackException.NoResponseException
XMPPException.XMPPErrorException
- if there is a problem executing the command.SmackException.NotConnectedException
InterruptedException
public abstract void prev() throws SmackException.NoResponseException, XMPPException.XMPPErrorException, SmackException.NotConnectedException, InterruptedException
SmackException.NoResponseException
XMPPException.XMPPErrorException
- if there is a problem executing the command.SmackException.NotConnectedException
InterruptedException
public abstract void cancel() throws SmackException.NoResponseException, XMPPException.XMPPErrorException, SmackException.NotConnectedException, InterruptedException
SmackException.NoResponseException
XMPPException.XMPPErrorException
- if there is a problem executing the command.SmackException.NotConnectedException
InterruptedException
protected List<AdHocCommand.Action> getActions()
prev
, next
and
complete
. This method will be only invoked for commands that
have one or more stages.protected void addActionAvailable(AdHocCommand.Action action)
action
- the action.protected AdHocCommand.Action getExecuteAction()
protected void setExecuteAction(AdHocCommand.Action action)
action
- the action.public AdHocCommand.Status getStatus()
public boolean isCompleted()
true
if this command is completed.protected boolean isValidAction(AdHocCommand.Action action)
action
is available in the current stage.
The cancel
action is always allowed. To define the
available actions use the addActionAvailable
method.action
- The action to check if it is available.