/** * Returns the <code>AdHocCommandManager</code> related to the * <code>connection</code>. * * @param connection the XMPP connection. * @return the AdHocCommandManager associated with the connection. */ public static synchronized AdHocCommandManager getAddHocCommandsManager(XMPPConnection connection) { AdHocCommandManager ahcm = instances.get(connection); if (ahcm == null) { ahcm = new AdHocCommandManager(connection); instances.put(connection, ahcm); } return ahcm; }
/** * Registers a new command with this command manager, which is related to a * connection. The <tt>node</tt> is an unique identifier of that command for * the connection related to this command manager. The <tt>name</tt> is the * human readable name of the command. The <tt>class</tt> is the class of * the command, which must extend {@link LocalCommand} and have a default * constructor. * * @param node the unique identifier of the command. * @param name the human readable name of the command. * @param clazz the class of the command, which must extend {@link LocalCommand}. */ public void registerCommand(String node, String name, final Class<? extends LocalCommand> clazz) { registerCommand(node, name, new LocalCommandFactory() { @Override public LocalCommand getInstance() throws InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException, SecurityException { return clazz.getConstructor().newInstance(); } }); }
/** * 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)); }
return respondError(response, StanzaError.Condition.item_not_found); command = newInstanceOfCmd(commandNode, sessionId); return respondError(response, xmppError); return respondError(response, StanzaError.Condition.forbidden); return respondError(response, StanzaError.Condition.bad_request, AdHocCommand.SpecificErrorCondition.malformedAction); return respondError(response, StanzaError.Condition.bad_request, AdHocCommand.SpecificErrorCondition.badAction); return respondError(response, StanzaError.getBuilder(error)); return respondError(response, StanzaError.Condition.bad_request, AdHocCommand.SpecificErrorCondition.badSessionid); return respondError(response, StanzaError.Condition.not_allowed, AdHocCommand.SpecificErrorCondition.sessionExpired); return respondError(response, StanzaError.Condition.bad_request, AdHocCommand.SpecificErrorCondition.malformedAction); return respondError(response, StanzaError.Condition.bad_request, AdHocCommand.SpecificErrorCondition.badAction); return respondError(response, StanzaError.getBuilder(error));
private AdHocCommandManager(Connection connection) { super(); this.connection = connection; init(); }
/** * Publish the commands to an specific JID. * * @param jid the full JID to publish the commands to. * @throws XMPPException if the operation failed for some reason. */ public void publishCommands(String jid) throws XMPPException { ServiceDiscoveryManager serviceDiscoveryManager = ServiceDiscoveryManager .getInstanceFor(connection); // Collects the commands to publish as items DiscoverItems discoverItems = new DiscoverItems(); Collection<AdHocCommandInfo> xCommandsList = getRegisteredCommands(); for (AdHocCommandInfo info : xCommandsList) { DiscoverItems.Item item = new DiscoverItems.Item(info.getOwnerJID()); item.setName(info.getName()); item.setNode(info.getNode()); discoverItems.addItem(item); } serviceDiscoveryManager.publishItems(jid, discoNode, discoverItems); }
/** * 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); }
respondError(response, XMPPError.Condition.item_not_found); return; LocalCommand command = newInstanceOfCmd(commandNode, sessionId); respondError(response, XMPPError.Condition.forbidden); return; respondError(response, XMPPError.Condition.bad_request, AdHocCommand.SpecificErrorCondition.malformedAction); return; respondError(response, XMPPError.Condition.bad_request, AdHocCommand.SpecificErrorCondition.badAction); return; respondError(response, error); e.printStackTrace(); respondError(response, XMPPError.Condition.bad_request, AdHocCommand.SpecificErrorCondition.badSessionid); return; respondError(response, XMPPError.Condition.not_allowed, AdHocCommand.SpecificErrorCondition.sessionExpired); return; respondError(response, XMPPError.Condition.bad_request, AdHocCommand.SpecificErrorCondition.malformedAction);
private AdHocCommandManager(Connection connection) { super(); this.connection = connection; init(); }
/** * Publish the commands to an specific JID. * * @param jid the full JID to publish the commands to. * @throws XMPPException if the operation failed for some reason. */ public void publishCommands(String jid) throws XMPPException { ServiceDiscoveryManager serviceDiscoveryManager = ServiceDiscoveryManager .getInstanceFor(connection); // Collects the commands to publish as items DiscoverItems discoverItems = new DiscoverItems(); Collection<AdHocCommandInfo> xCommandsList = getRegisteredCommands(); for (AdHocCommandInfo info : xCommandsList) { DiscoverItems.Item item = new DiscoverItems.Item(info.getOwnerJID()); item.setName(info.getName()); item.setNode(info.getNode()); discoverItems.addItem(item); } serviceDiscoveryManager.publishItems(jid, discoNode, discoverItems); }
AdHocCommandInfo commandInfo = new AdHocCommandInfo(node, name, connection().getUser(), factory);
respondError(response, XMPPError.Condition.item_not_found); return; LocalCommand command = newInstanceOfCmd(commandNode, sessionId); respondError(response, XMPPError.Condition.forbidden); return; respondError(response, XMPPError.Condition.bad_request, AdHocCommand.SpecificErrorCondition.malformedAction); return; respondError(response, XMPPError.Condition.bad_request, AdHocCommand.SpecificErrorCondition.badAction); return; respondError(response, error); e.printStackTrace(); respondError(response, XMPPError.Condition.bad_request, AdHocCommand.SpecificErrorCondition.badSessionid); return; respondError(response, XMPPError.Condition.not_allowed, AdHocCommand.SpecificErrorCondition.sessionExpired); return; respondError(response, XMPPError.Condition.bad_request, AdHocCommand.SpecificErrorCondition.malformedAction);
/** * Responds an error with an specific condition. * * @param response the response to send. * @param condition the condition of the error. * @param specificCondition the adhoc command error condition. * @throws NotConnectedException */ private static IQ respondError(AdHocCommandData response, StanzaError.Condition condition, AdHocCommand.SpecificErrorCondition specificCondition) { StanzaError.Builder error = StanzaError.getBuilder(condition).addExtension(new AdHocCommandData.SpecificError(specificCondition)); return respondError(response, error); }
public void connectionCreated(Connection connection) { new AdHocCommandManager(connection); } });
/** * Registers a new command with this command manager, which is related to a * connection. The <tt>node</tt> is an unique identifier of that command for * the connection related to this command manager. The <tt>name</tt> is the * human readable name of the command. The <tt>class</tt> is the class of * the command, which must extend {@link LocalCommand} and have a default * constructor. * * @param node the unique identifier of the command. * @param name the human readable name of the command. * @param clazz the class of the command, which must extend {@link LocalCommand}. */ public void registerCommand(String node, String name, final Class clazz) { registerCommand(node, name, new LocalCommandFactory() { public LocalCommand getInstance() throws InstantiationException, IllegalAccessException { return (LocalCommand)clazz.newInstance(); } }); }
private AdHocCommandManager(Connection connection) { super(); this.connection = connection; init(); }
/** * Publish the commands to an specific JID. * * @param jid the full JID to publish the commands to. * @throws XMPPException if the operation failed for some reason. */ public void publishCommands(String jid) throws XMPPException { ServiceDiscoveryManager serviceDiscoveryManager = ServiceDiscoveryManager .getInstanceFor(connection); // Collects the commands to publish as items DiscoverItems discoverItems = new DiscoverItems(); Collection<AdHocCommandInfo> xCommandsList = getRegisteredCommands(); for (AdHocCommandInfo info : xCommandsList) { DiscoverItems.Item item = new DiscoverItems.Item(info.getOwnerJID()); item.setName(info.getName()); item.setNode(info.getNode()); discoverItems.addItem(item); } serviceDiscoveryManager.publishItems(jid, discoNode, discoverItems); }
respondError(response, XMPPError.Condition.item_not_found); return; LocalCommand command = newInstanceOfCmd(commandNode, sessionId); respondError(response, XMPPError.Condition.forbidden); return; respondError(response, XMPPError.Condition.bad_request, AdHocCommand.SpecificErrorCondition.malformedAction); return; respondError(response, XMPPError.Condition.bad_request, AdHocCommand.SpecificErrorCondition.badAction); return; respondError(response, error); e.printStackTrace(); respondError(response, XMPPError.Condition.bad_request, AdHocCommand.SpecificErrorCondition.badSessionid); return; respondError(response, XMPPError.Condition.not_allowed, AdHocCommand.SpecificErrorCondition.sessionExpired); return; respondError(response, XMPPError.Condition.bad_request, AdHocCommand.SpecificErrorCondition.malformedAction);
/** * Responds an error with an specific condition. * * @param response the response to send. * @param condition the condition of the error. */ private void respondError(AdHocCommandData response, XMPPError.Condition condition) { respondError(response, new XMPPError(condition)); }
public void connectionCreated(Connection connection) { new AdHocCommandManager(connection); } });