/**
  * Creates a new instance of a command to be used by a new execution request
  *
  * @param commandNode the command node that identifies it.
  * @param sessionID the session id of this execution.
  * @return the command instance to execute.
  * @throws XMPPException if there is problem creating the new instance.
  */
 private LocalCommand newInstanceOfCmd(String commandNode, String sessionID) throws XMPPException {
   AdHocCommandInfo commandInfo = commands.get(commandNode);
   LocalCommand command;
   try {
     command = (LocalCommand) commandInfo.getCommandInstance();
     command.setSessionID(sessionID);
     command.setName(commandInfo.getName());
     command.setNode(commandInfo.getNode());
   } catch (InstantiationException e) {
     e.printStackTrace();
     throw new XMPPException(new XMPPError(XMPPError.Condition.interna_server_error));
   } catch (IllegalAccessException e) {
     e.printStackTrace();
     throw new XMPPException(new XMPPError(XMPPError.Condition.interna_server_error));
   }
   return command;
 }
  /**
   * 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);
  }