Overview | Package | Class | Tree | Deprecated | Index | Help
| Openfire 3.8.2 Javadoc
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## org.jivesoftware.openfire.commands
Class AdHocCommand

    java.lang.Object
      org.jivesoftware.openfire.commands.AdHocCommand

Direct Known Subclasses:
  AddGroup, AddGroupUsers, AddUser, AuthenticateUser, ChangeSharedSecret, ChangeUserPassword, CreateMUCRoom, DeleteGroup, DeleteGroupUsers, GenerateNonce, GetAdminConsoleInfo, GetListActiveUsers, GetListGroups, GetListGroupUsers, GetNumberActiveUsers, GetNumberOnlineUsers, GetNumberUserSessions, GetServerStats, GetUsersPresence, GroupAdminAdded, GroupAdminRemoved, GroupCreated, GroupDeleting, GroupMemberAdded, GroupMemberRemoved, GroupModified, HttpBindStatus, PacketsNotification, PendingSubscriptionsCommand, SystemAdminAdded, SystemAdminRemoved, UpdateGroup, UserCreated, UserDeleting, UserModified, UserProperties, VCardCreated, VCardDeleting, VCardModified

    public abstract class AdHocCommand

extends Object

An ad-hoc command is a stateless object responsbile for executing the provided service. Each subclass will only have one instance that will be shared across all users sessions. Therefore, it is important to not keep any information related to executions as permanent data (i.e. as instance or static variables). Each command has a `code` 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 beig executed. However, users may request the "cancel" action when submiting 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).

Author:
  Gaston Dombiak

Nested Class Summary
`static class` | `AdHocCommand.Action`
`static class` | `AdHocCommand.Status`

Constructor Summary
`AdHocCommand()`

Method Summary
`void` | `addNextStageInformation(SessionData data, org.dom4j.Element command)` Increments the stage number by one and adds to the command element the new data form and new allowed actions that the user might perform.
`void` | `addPreviousStageInformation(SessionData data, org.dom4j.Element command)` Decrements the stage number by one and adds to the command the data form and allowed actions that the user might perform of the previous stage.
`protected void` | `addStageActions(SessionData data, org.dom4j.Element command)` Adds the allowed actions to follow from the current stage.
`protected abstract void` | `addStageInformation(SessionData data, org.dom4j.Element command)` Adds to the command element the data form or notes required by the current stage.
`abstract void` | `execute(SessionData data, org.dom4j.Element command)` Executes the command with the specified session data.
`protected String` | `get(Map<String,List<String>> data, String key, int value)`
`protected abstract List<AdHocCommand.Action>` | `getActions(SessionData data)` Returns a collection with the allowed actions based on the current stage as defined in the SessionData.
`abstract String` | `getCode()` Returns the unique identifier for this command for the containing JID.
`abstract String` | `getDefaultLabel()` Returns the default label used for describing this commmand.
`protected abstract AdHocCommand.Action` | `getExecuteAction(SessionData data)` Returns which of the actions available for the current stage is considered the equivalent to "execute".
`String` | `getLabel()`
`abstract int` | `getMaxStages(SessionData data)` Returns the max number of stages for this command.
`boolean` | `hasPermission(org.xmpp.packet.JID requester)` Returns true if the requester is allowed to execute this command.
`void` | `setLabel(String label)`

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Constructor Detail

### AdHocCommand

    public AdHocCommand()

Method Detail

### getLabel

    public String getLabel()

### setLabel

    public void setLabel(String label)

### hasPermission

    public boolean hasPermission(org.xmpp.packet.JID requester)

  Returns true if the requester is allowed to execute this command. By default only admins are allowed to execute commands. Subclasses may redefine this method with any specific logic.

  Note: The bare JID of the requester will be compared with the bare JID of the admins.

  Parameters:
    `requester` - the JID of the user requesting to execute this command.
  Returns:
    true if the requester is allowed to execute this command.

### getCode

    public abstract String getCode()

  Returns the unique identifier for this command for the containing JID. The code will be used as the node in the disco#items or the node when executing the command.

  Returns:
    the unique identifier for this command for the containing JID.

### getDefaultLabel

    public abstract String getDefaultLabel()

  Returns the default label used for describing this commmand. This information is usually used when returning commands as disco#items. Admins can later use `setLabel(String)` to set a new label and reset to the default value at any time.

  Returns:
    the default label used for describing this commmand.

### getMaxStages

    public abstract int getMaxStages(SessionData data)

  Returns the max number of stages for this command. The number of stages may vary according to the collected data in previous stages. Therefore, a SessionData object is passed as a parameter. When the max number of stages has been reached then the command is ready to be executed.

  Parameters:
    `data` - the gathered data through the command stages or `null` if the command does not have stages or the requester is requesting the execution for the first time.
  Returns:
    the max number of stages for this command.

### execute

    public abstract void execute(SessionData data,
                                 org.dom4j.Element command)

  Executes the command with the specified session data.

  Parameters:
    `data` - the gathered data through the command stages or `null` if the command does not have stages.
    `command` - the command element to be sent to the command requester with a reported data result or note element with the answer of the execution.

### addStageInformation

    protected abstract void addStageInformation(SessionData data,
                                                org.dom4j.Element command)

  Adds to the command element the data form or notes required by the current stage. The current stage is specified in the SessionData. This method will never be invoked for commands that have no stages.

  Parameters:
    `data` - the gathered data through the command stages or `null` if the command does not have stages or the requester is requesting the execution for the first time.
    `command` - the command element to be sent to the command requester.

### getActions

    protected abstract List<AdHocCommand.Action> getActions(SessionData data)

  Returns a collection with the allowed actions based on the current stage as defined in the SessionData. Possible actions are: `prev`, `next` and `complete`. This method will never be invoked for commands that have no stages.

  Parameters:
    `data` - the gathered data through the command stages or `null` if the command does not have stages or the requester is requesting the execution for the first time.
  Returns:
    a collection with the allowed actions based on the current stage as defined in the SessionData.

### getExecuteAction

    protected abstract AdHocCommand.Action getExecuteAction(SessionData data)

  Returns which of the actions available for the current stage is considered the equivalent to "execute". When the requester sends his reply, if no action was defined in the command then the action will be assumed "execute" thus assuming the action returned by this method. This method will never be invoked for commands that have no stages.

  Parameters:
    `data` - the gathered data through the command stages or `null` if the command does not have stages or the requester is requesting the execution for the first time.
  Returns:
    which of the actions available for the current stage is considered the equivalent to "execute".

### addNextStageInformation

    public void addNextStageInformation(SessionData data,
                                        org.dom4j.Element command)

  Increments the stage number by one and adds to the command element the new data form and new allowed actions that the user might perform.

  Parameters:
    `data` - the gathered data through the command stages.
    `command` - the command element to be sent to the command requester.

### addPreviousStageInformation

    public void addPreviousStageInformation(SessionData data,
                                            org.dom4j.Element command)

  Decrements the stage number by one and adds to the command the data form and allowed actions that the user might perform of the previous stage.

  Parameters:
    `data` - the gathered data through the command stages.
    `command` - the command element to be sent to the command requester.

### addStageActions

    protected void addStageActions(SessionData data,
                                   org.dom4j.Element command)

  Adds the allowed actions to follow from the current stage. Possible actions are: `prev`, `next` and `complete`.

  Parameters:
    `data` - the gathered data through the command stages or `null` if the command does not have stages or the requester is requesting the execution for the first time.
    `command` - the command element to be sent to the command requester.

### get

    protected String get(Map<String,List<String>> data,
                         String key,
                         int value)

Overview | Package | Class | Tree | Deprecated | Index | Help
| Openfire 3.8.2 Javadoc
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

Copyright © 2003-2008 Jive Software.