Example #1
0
    @Override
    public void refreshStatus(StatusDestination pDestination) {

      final Map<String, String> lCommandNamesToFactories = new TreeMap<>();
      for (Map.Entry<String, CommandFactory> lEntry : mCommandNameToFactoryMap.entrySet()) {
        lCommandNamesToFactories.put(lEntry.getKey(), lEntry.getValue().getClass().getName());
      }

      for (FxpCommandFactory lCommandFactory : PluginManager.instance().getAllCommandFactories()) {
        for (String lCommandName : lCommandFactory.getCommandElementNames()) {
          lCommandNamesToFactories.put(lCommandName, lCommandFactory.getClass().getName());
        }
      }

      StatusTable lTable =
          pDestination.addTable("Available commands", "Command name", "Providing factory");
      lTable.setRowProvider(
          new StatusTable.RowProvider() {
            @Override
            public void generateRows(StatusTable.RowDestination pRowDestination) {
              for (Map.Entry<String, String> lMapEntry : lCommandNamesToFactories.entrySet()) {
                pRowDestination
                    .addRow()
                    .setColumn(lMapEntry.getKey())
                    .setColumn(lMapEntry.getValue());
              }
            }
          });
    }
Example #2
0
  /**
   * Returns an instance of a <code>Command</code> represented by the XML element specified.
   *
   * @param pMarkupDOM the element that represents the command
   * @return an instance of the command that encapsulates the command logic
   */
  public Command getCommand(Mod pMod, DOM pMarkupDOM) {

    String lCommandName = pMarkupDOM.getLocalName();

    CommandFactory lCommandFactory = mCommandNameToFactoryMap.get(lCommandName);
    if (lCommandFactory != null) {
      try {
        return lCommandFactory.create(pMod, pMarkupDOM);
      } catch (Throwable th) {
        throw new ExInternal(
            "Error instantiating command \""
                + lCommandName
                + "\"\n("
                + Joiner.on(", ").withKeyValueSeparator("=").join(pMarkupDOM.getAttributeMap())
                + ")",
            th);
      }
    } else {
      // Check plugins
      Command lPluginCommand =
          PluginManager.instance().resolvePluginCommand(lCommandName, pMarkupDOM);

      if (lPluginCommand == null) {
        throw new ExInternal(
            "Serious error: no Factory registered for command \"" + lCommandName + "\"");
      } else {
        return lPluginCommand;
      }
    }
  }