/**
   * Method to return the ATPlugin for a particular and domain object
   *
   * @param domainObject The domain object to find a plugin for
   * @param category The category to find a domain object for
   * @return The plugin found or null if none can be located.
   */
  private ATPlugin getATPlugin(DomainObject domainObject, String category) {
    String editorType = getEditorTypeForDomainObject(domainObject);

    if (editorType != null) {
      ATPlugin foundPlugin = null;

      try {
        Iterator it = pluginManager.getRegistry().getPluginDescriptors().iterator();

        while (it.hasNext()) {
          PluginDescriptor pluginDescriptor = (PluginDescriptor) it.next();
          String id = pluginDescriptor.getId();
          ATPlugin plugin = (org.archiviststoolkit.plugin.ATPlugin) pluginManager.getPlugin(id);

          String cat = plugin.getCategory();
          String et = plugin.getEditorType();

          if (cat.indexOf(category) != -1 && et.indexOf(editorType) != -1) {
            foundPlugin = plugin;
            break;
          }
        }
      } catch (Exception e) {
        e.printStackTrace();
      }

      return foundPlugin;
    } else {
      return null;
    }
  }
  /**
   * Method to return an array list containing plugins of a certain editor type and category
   *
   * @param editorType The editor type
   * @param category The category
   * @return An array list of any plugins found
   */
  public ArrayList<ATPlugin> getEmbeddedEditorPlugins(String editorType, String category) {
    ArrayList<ATPlugin> foundPlugins = new ArrayList<ATPlugin>();

    try {
      Iterator it = pluginManager.getRegistry().getPluginDescriptors().iterator();

      while (it.hasNext()) {
        PluginDescriptor pluginDescriptor = (PluginDescriptor) it.next();
        String id = pluginDescriptor.getId();
        ATPlugin plugin = (org.archiviststoolkit.plugin.ATPlugin) pluginManager.getPlugin(id);

        String cat = plugin.getCategory();
        String et = plugin.getEditorType();

        // check to make sure that the plugin is of the right category and
        // editor type and that it has a panel that can be embedded into
        // the resource editor panel
        if (cat.indexOf(category) != -1
            && et.indexOf(editorType) != -1
            && plugin.getEmbeddedPanels() != null) {
          foundPlugins.add(plugin);
        }
      }
    } catch (Exception e) {
      e.printStackTrace();
    }

    return foundPlugins;
  }
  /**
   * Method to return the name of all plugins in a particular category. It is used to add plugins to
   * plugin menu in the main application frame
   *
   * @return HashMap containing the names and ids of all the plugins found
   */
  public HashMap getPluginNamesByCategory(String inCategory) {
    HashMap<String, String> pluginNames = new HashMap<String, String>();

    try {
      Iterator it = pluginManager.getRegistry().getPluginDescriptors().iterator();

      while (it.hasNext()) {
        PluginDescriptor pluginDescriptor = (PluginDescriptor) it.next();
        String id = pluginDescriptor.getId();
        ATPlugin plugin = (org.archiviststoolkit.plugin.ATPlugin) pluginManager.getPlugin(id);
        String name = plugin.getName();
        String category = plugin.getCategory();
        if (category.indexOf(inCategory) != -1) {
          if (plugin.getTaskList() == null) { // no list of task so just return the id and name
            pluginNames.put(id, name);
          } else { // list of task so return the name::task1::task2::task3 etc ...
            String nameWithTask = getNameWithTask(name, plugin.getTaskList());
            pluginNames.put(id, nameWithTask);
          }
        }
      }
    } catch (Exception e) {
      e.printStackTrace();
    }

    if (pluginNames.size() == 0) {
      return null; // no plugins in this category so return null
    } else {
      return pluginNames;
    }
  }