/** * Returns a command that represents an instance of a command in a remote * host. It is used to execute remote commands. The concept is similar to * RMI. Every invocation on this command is equivalent to an invocation in * the remote command. * * @param jid the full JID of the host of the remote command * @param node the identifier of the command * @return a local instance equivalent to the remote command. */ public RemoteCommand getRemoteCommand(Jid jid, String node) { return new RemoteCommand(connection(), node, jid); }
@Override public String getElementName() { return condition.toString(); } @Override
@Override public void connectionCreated(XMPPConnection connection) { getAddHocCommandsManager(connection); } });
/** * Returns true if the <code>action</code> is available in the current stage. * The {@link Action#cancel cancel} action is always allowed. To define the * available actions use the <code>addActionAvailable</code> method. * * @param action * The action to check if it is available. * @return True if the action is available for the current stage. */ protected boolean isValidAction(Action action) { return getActions().contains(action) || Action.cancel.equals(action); }
@Override public void execute() throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException { executeAction(Action.execute); }
/** * The sessionID is an unique identifier of an execution request. This is * automatically handled and should not be called. * * @param sessionID the unique session id of this execution */ public void setSessionID(String sessionID) { this.sessionID = sessionID; getData().setSessionID(sessionID); }
@Override void setData(AdHocCommandData data) { data.setSessionID(sessionID); super.setData(data); }
public LocalCommand getCommandInstance() throws InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException, SecurityException { return factory.getInstance(); }
/** * Creates a new RemoteCommand that uses an specific connection to execute a * command identified by <code>node</code> in the host identified by * <code>jid</code> * * @param connection the connection to use for the execution. * @param node the identifier of the command. * @param jid the JID of the host. */ protected RemoteCommand(XMPPConnection connection, String node, Jid jid) { super(); this.connection = connection; this.jid = jid; this.setNode(node); }
/** * Responds an error with an specific condition. * * @param response the response to send. * @param condition the condition of the error. * @throws NotConnectedException */ private static IQ respondError(AdHocCommandData response, StanzaError.Condition condition) { return respondError(response, StanzaError.getBuilder(condition)); }
public RemoteCommand addUser(Jid service) { return adHocCommandManager.getRemoteCommand(service, COMMAND_NODE_HASHSIGN + "add-user"); }
/** * Check if this command has been completed successfully. * * @return <code>true</code> if this command is completed. * @since 4.2 */ public boolean isCompleted() { return getStatus() == Status.completed; }
@Override public void prev() throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException { executeAction(Action.prev); }
public ServiceAdministrationManager(XMPPConnection connection) { super(connection); adHocCommandManager = AdHocCommandManager.getAddHocCommandsManager(connection); }
public RemoteCommand deleteUser(Jid service) { return adHocCommandManager.getRemoteCommand(service, COMMAND_NODE_HASHSIGN + "delete-user"); }
@Override public void next(Form form) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException { executeAction(Action.next, form); }
@Override public void complete(Form form) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException { executeAction(Action.complete, form); }
/** * Executes the default action of the command with the information provided * in the Form. This form must be the answer form of the previous stage. If * there is a problem executing the command it throws an XMPPException. * * @param form the form answer of the previous stage. * @throws XMPPErrorException if an error occurs. * @throws NoResponseException if there was no response from the server. * @throws NotConnectedException * @throws InterruptedException */ public void execute(Form form) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException { executeAction(Action.execute, form); }
@Override public void cancel() throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException { executeAction(Action.cancel); }
private void executeAction(Action action) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException { executeAction(action, null); }