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;
  }
  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);
        }
      }
    }
  }