Class AdHocCommand
- java.lang.Object
-
- org.jivesoftware.openfire.commands.AdHocCommand
-
- Direct Known Subclasses:
AddGroup
,AddGroupUsers
,AddUser
,AuthenticateUser
,ChangeUserPassword
,CreateMUCRoom
,DeleteGroup
,DeleteGroupUsers
,DeleteUser
,DisableUser
,EditAdminList
,EditAllowedList
,EditBlockedList
,EndUserSession
,GetAdminConsoleInfo
,GetListActiveUsers
,GetListDisabledUsers
,GetListGroups
,GetListGroupUsers
,GetListIdleUsers
,GetListOnlineUsers
,GetListRegisteredUsers
,GetNumberActiveUsers
,GetNumberDisabledUsers
,GetNumberIdleUsers
,GetNumberOnlineUsers
,GetNumberRegisteredUsers
,GetNumberUserSessions
,GetServerStats
,GetUserRoster
,GetUsersPresence
,GroupAdminAdded
,GroupAdminRemoved
,GroupCreated
,GroupDeleting
,GroupMemberAdded
,GroupMemberRemoved
,GroupModified
,HttpBindStatus
,PacketsNotification
,PendingSubscriptionsCommand
,Ping
,ReEnableUser
,SendAnnouncementToOnlineUsers
,UpdateGroup
,UserCreated
,UserDeleting
,UserModified
,UserProperties
,VCardCreated
,VCardDeleting
,VCardModified
public abstract class AdHocCommand extends Object
An ad-hoc command is a stateless object responsible 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 acode
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).- Author:
- Gaston Dombiak
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
AdHocCommand.Action
static class
AdHocCommand.Status
-
Constructor Summary
Constructors Constructor Description AdHocCommand()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description 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 command.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)
-
-
-
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 command. This information is usually used when returning commands as disco#items. Admins can later usesetLabel(String)
to set a new label and reset to the default value at any time.- Returns:
- the default label used for describing this command.
-
getMaxStages
public abstract int getMaxStages(@Nonnull 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
- metadata and the gathered data through the command stages.- Returns:
- the max number of stages for this command.
-
execute
public abstract void execute(@Nonnull SessionData data, org.dom4j.Element command)
Executes the command with the specified session data.- Parameters:
data
- metadata and the gathered data through the command 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(@Nonnull 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
- metadata and the gathered data through the command stages.command
- the command element to be sent to the command requester.
-
getActions
protected abstract List<AdHocCommand.Action> getActions(@Nonnull SessionData data)
Returns a collection with the allowed actions based on the current stage as defined in the SessionData. Possible actions are:prev
,next
andcomplete
. This method will never be invoked for commands that have no stages.- Parameters:
data
- metadata and the gathered data through the command stages.- Returns:
- a collection with the allowed actions based on the current stage as defined in the SessionData.
-
getExecuteAction
protected abstract AdHocCommand.Action getExecuteAction(@Nonnull 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
- metadata and the gathered data through the command stages.- Returns:
- which of the actions available for the current stage is considered the equivalent to "execute".
-
addNextStageInformation
public void addNextStageInformation(@Nonnull 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
- metadata and the gathered data through the command stages.command
- the command element to be sent to the command requester.
-
addPreviousStageInformation
public void addPreviousStageInformation(@Nonnull 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
- metadata and the gathered data through the command stages.command
- the command element to be sent to the command requester.
-
addStageActions
protected void addStageActions(@Nonnull SessionData data, org.dom4j.Element command)
Adds the allowed actions to follow from the current stage. Possible actions are:prev
,next
andcomplete
.- Parameters:
data
- metadata and the gathered data through the command stages.command
- the command element to be sent to the command requester.
-
-