public MessageRenderer createRenderer(ClassLoader classLoader, RendererConfig rConfig)
      throws InvocationTargetException, HermesException, InstantiationException,
          IllegalAccessException, ClassNotFoundException {
    Thread.currentThread().setContextClassLoader(classLoader);
    MessageRenderer renderer =
        (MessageRenderer) classLoader.loadClass(rConfig.getClassName()).newInstance();
    MessageRenderer.Config rendererConfig = renderer.createConfig();

    if (rendererConfig != null) {
      Properties rendererProperties = HermesBrowser.getConfigDAO().getRendererProperties(rConfig);

      BeanUtils.populate(rendererConfig, rendererProperties);
    }

    renderer.setConfig(rendererConfig);

    return renderer;
  }
  private boolean doContextContentTransfer(HermesConfigGroup transferData)
      throws NamingException, JMSException {
    if (transferData.getDestinations().size() != 0 && transferData.getFactories().size() != 0) {
      HermesBrowser.getBrowser()
          .showErrorDialog("Can only drop ConnectionFactories or Destinations, not both");

      return false;
    }

    if (transferData.getDestinations().size() > 0) {
      Hermes hermes = null;

      if (transferData.getHermesId() != null) {
        hermes =
            (Hermes) HermesBrowser.getBrowser().getContext().lookup(transferData.getHermesId());
      } else if (getSelectedHermesNode() != null) {
        hermes = getSelectedHermesNode().getHermes();
      }

      if (hermes != null) {
        StringBuffer question = new StringBuffer();

        if (transferData.getDestinations().size() == 1) {
          question.append("Do you want to add this destination to " + hermes.getId() + " ?");
        } else {
          question.append(
              "Do you want to add these "
                  + transferData.getDestinations().size()
                  + " destinations to "
                  + hermes.getId()
                  + " ?");
        }

        if (JOptionPane.showConfirmDialog(
                HermesBrowser.getBrowser(),
                question.toString(),
                "Please confirm.",
                JOptionPane.YES_NO_OPTION)
            == JOptionPane.YES_OPTION) {
          for (Iterator iter = transferData.getDestinations().iterator(); iter.hasNext(); ) {
            DestinationConfig dConfig = (DestinationConfig) iter.next();

            if (dConfig.getDomain() == Domain.UNKNOWN.getId()) {
              Object options[] = {"Queue", "Topic"};

              int n =
                  JOptionPane.showOptionDialog(
                      HermesBrowser.getBrowser(),
                      "The destination "
                          + dConfig.getName()
                          + " implements both Queue and Topic interfaces, please select the domain you wish to use it in.",
                      "Select domain",
                      JOptionPane.YES_NO_OPTION,
                      JOptionPane.QUESTION_MESSAGE,
                      null,
                      options,
                      options[1]);

              if (n == JOptionPane.YES_OPTION) {
                dConfig.setDomain(Domain.QUEUE.getId());
                HermesBrowser.getBrowser().addDestinationConfig(hermes, dConfig);
              } else if (n == JOptionPane.NO_OPTION) {
                dConfig.setDomain(Domain.TOPIC.getId());
                HermesBrowser.getBrowser().addDestinationConfig(hermes, dConfig);
              } else {
                // NOP
              }
            } else {
              HermesBrowser.getBrowser().addDestinationConfig(hermes, dConfig);
            }
          }

          HermesBrowser.getBrowser().saveConfig();
        }
      } else {
        Hermes.ui.getDefaultMessageSink().add("No session selected for drop target");
      }
    } else {
      final String newName =
          JOptionPane.showInputDialog(HermesBrowser.getBrowser(), "Session name:", "");

      if (newName != null && !newName.equals("")) {
        if (!getAllHermesIds().contains(newName)) {
          FactoryConfig fConfig = (FactoryConfig) transferData.getFactories().iterator().next();

          HermesBrowser.getConfigDAO().renameSession(fConfig, newName);

          HermesBrowser.getBrowser().getConfig().getFactory().add(fConfig);
          HermesBrowser.getBrowser().saveConfig();
          HermesBrowser.getBrowser().loadConfig();
        } else {
          HermesBrowser.getBrowser().showErrorDialog("Session " + newName + " is already in use.");
        }
      }
    }

    return true;
  }
  public void setConfig(ClassLoader classLoader, HermesConfig config) throws HermesException {
    boolean gotDefaultRenderer = false;

    for (Iterator iter = config.getRenderer().iterator(); iter.hasNext(); ) {
      RendererConfig rConfig = (RendererConfig) iter.next();

      try {
        MessageRenderer renderer = createRenderer(classLoader, rConfig);

        if (renderer.getClass().getName().equals(DefaultMessageRenderer.class.getName())) {
          gotDefaultRenderer = true;
        }

        renderersByClass.put(rConfig.getClassName(), renderer);
        renderersByName.put(renderer.getDisplayName(), renderer);
      } catch (Throwable t) {
        log.error("cannot load renderer " + rConfig.getClassName() + ": " + t.getMessage(), t);

        if (HermesBrowser.getBrowser() != null) {
          JOptionPane.showMessageDialog(
              HermesBrowser.getBrowser(),
              "Cannot load renderer "
                  + rConfig.getClassName()
                  + ":\n"
                  + t.getClass().getName()
                  + "\n"
                  + t.getMessage(),
              "Error",
              JOptionPane.ERROR_MESSAGE);
        }
      }
    }

    renderers.clear();

    //
    // Handle upgrades to Hermes 1.6 where this may be missing.

    if (!gotDefaultRenderer) {
      RendererConfig rConfig = new RendererConfig();

      rConfig.setClassName(DefaultMessageRenderer.class.getName());

      config.getRenderer().add(rConfig);

      renderers.add(new DefaultMessageRenderer());
    }

    final StringTokenizer rendererClasses =
        new StringTokenizer(
            System.getProperty(
                SystemProperties.RENDERER_CLASSES, SystemProperties.DEFAULT_RENDERER_CLASSES),
            ",");

    while (rendererClasses.hasMoreTokens()) {
      final String rendererClassName = rendererClasses.nextToken();

      if (renderersByClass.containsKey(rendererClassName)) {
        renderers.add(renderersByClass.get(rendererClassName));
      } else {
        try {
          MessageRenderer renderer =
              (MessageRenderer) Class.forName(rendererClassName).newInstance();
          renderers.add(renderer);

          renderersByClass.put(rendererClassName, renderer);
          renderersByName.put(renderer.getDisplayName(), renderer);
        } catch (Throwable t) {
          log.error("cannot instantiate renderer: " + rendererClassName + ": " + t.getMessage(), t);
        }
      }
    }

    log.debug("renderer chain:");

    for (MessageRenderer r : renderers) {
      log.debug(r.getDisplayName() + ": " + r.getClass().getName());
    }

    for (Iterator hIter = HermesBrowser.getConfigDAO().getAllSessions(config).iterator();
        hIter.hasNext(); ) {
      SessionConfig sConfig = (SessionConfig) hIter.next();

      for (Iterator iter2 =
              HermesBrowser.getConfigDAO().getAllDestinations(config, sConfig.getId()).iterator();
          iter2.hasNext(); ) {
        DestinationConfig dConfig = (DestinationConfig) iter2.next();

        if (dConfig.getRenderer() != null) {
          // @@TODO Remove the old destination specific renderers.

          dConfig.setRenderer(null);
        }
      }
    }
  }