Пример #1
0
  public Hermes getHermesAsMessageFactory() throws HermesException {
    if (!TextUtils.isEmpty(
        HermesBrowser.getBrowser().getConfig().getMessageStoreMessageFactory())) {
      try {
        Hermes hermes =
            (Hermes)
                HermesBrowser.getBrowser()
                    .getContext()
                    .lookup(HermesBrowser.getBrowser().getConfig().getMessageStoreMessageFactory());

        if (hermes != null) {
          return hermes;
        }
      } catch (NamingException ex) {
        log.info(
            "cannot find configured message store message factory, using one from the tree instead: "
                + ex.getMessage(),
            ex);
      }
    }

    if (getLastSelectedHermesTreeNode() == null) {
      return getBrowserModel().getFirstHermesTreeNode().getHermes();
    } else {
      return getLastSelectedHermesTreeNode().getHermes();
    }
  }
Пример #2
0
  private void maybeRefocusDocument(TreeNode treeNode) {
    DocumentComponent found = null;

    if (treeNode instanceof DestinationConfigTreeNode) {
      final DestinationConfigTreeNode node = (DestinationConfigTreeNode) treeNode;
      found = HermesBrowser.getBrowser().getOpenQueueBrowser(node.getConfig());
    } else if (treeNode instanceof MessageStoreTreeNode) {
      final MessageStoreTreeNode node = (MessageStoreTreeNode) treeNode;
      found = HermesBrowser.getBrowser().getOpenStoreBrowser(node.getMessageStore());
    }

    if (found != null) {
      HermesBrowser.getBrowser().getDocumentPane().setActiveDocument(found.getName());
    }
  }
Пример #3
0
  private boolean doLocalTransfer(Transferable t, int action) {
    if (HermesBrowser.getBrowser().isRestrictedWithWarning()) {
      return false;
    }

    try {

      if (t.isDataFlavorSupported(JMSMessagesTransferable.FLAVOR)) {
        return doMessagesTransfer(
            (MessageGroup) t.getTransferData(JMSMessagesTransferable.FLAVOR), action);
      }

      if (t.isDataFlavorSupported(JMSAdministeredObjectTransferable.FLAVOR)) {
        return doContextContentTransfer(
            (HermesConfigGroup) t.getTransferData(JMSAdministeredObjectTransferable.FLAVOR));
      }

      if (t.isDataFlavorSupported(MessagesTransferable.BYTE_FLAVOR)) {

        return doBytesMessageTransfer(
            (Collection<byte[]>) t.getTransferData(MessagesTransferable.BYTE_FLAVOR));
      }
      if (t.isDataFlavorSupported(HermesAdministeredObjectTransferable.FLAVOR)) {
        if (getSelectionPath().getLastPathComponent() instanceof NamingConfigTreeNode) {
          final NamingConfigTreeNode namingConfigTreeNode =
              (NamingConfigTreeNode) getSelectionPath().getLastPathComponent();
          final Collection objects =
              (Collection) t.getTransferData(HermesAdministeredObjectTransferable.FLAVOR);
          final JNDIContextFactory contextFactory =
              new JNDIContextFactory(namingConfigTreeNode.getConfig());
          final BindToolDialog bindTool =
              new BindToolDialog(HermesBrowser.getBrowser(), contextFactory, "", objects);

          bindTool.pack();
          JideSwingUtilities.centerWindow(bindTool);
          bindTool.show();

          return true;
        }
      }
    } catch (Exception ex) {
      log.error(ex.getMessage(), ex);
      JOptionPane.showMessageDialog(
          this, "During transfer: " + ex.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
    }

    return false;
  }
Пример #4
0
  private boolean doJavaFileTransfer(List files) {
    List<DestinationConfigTreeNode> nodes = getSelectedDestinationNodes();

    if (nodes.size() > 0) {
      final StringBuffer question = new StringBuffer();
      final DestinationConfigTreeNode node = nodes.get(0);

      question.append("Are you sure you want to upload ");

      if (files.size() == 1) {
        question.append(" this file to " + node.getDestinationName());
      } else {
        question.append(" these " + files.size() + " files to " + node.getDestinationName());
      }

      question.append(" ?");

      if (JOptionPane.showConfirmDialog(
              HermesBrowser.getBrowser(),
              question.toString(),
              "Please confirm.",
              JOptionPane.YES_NO_OPTION)
          == JOptionPane.YES_OPTION) {

        HermesBrowser.getBrowser()
            .getActionFactory()
            .createSimpleSendMessageAction(
                getSelectedHermesNode().getHermes(),
                node.getDestinationName(),
                node.getDomain(),
                files,
                SendMessageTask.MAYBE_XML,
                false);
      } else {
        Hermes.ui.getDefaultMessageSink().add("File upload cancelled.");
      }
    }

    return false;
  }
Пример #5
0
  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;
  }
Пример #6
0
  private boolean doBytesMessageTransfer(Collection<byte[]> messages) {
    List<DestinationConfigTreeNode> nodes = getSelectedDestinationNodes();

    lastDndAction = TransferHandler.COPY;

    if (nodes.size() > 0 && messages.size() > 0) {
      final DestinationConfigTreeNode destinationNode = nodes.get(0);
      final HermesTreeNode hermesNode = getSelectedHermesNode();

      if (hermesNode != null && destinationNode != null) {
        HermesBrowser.getBrowser()
            .getActionFactory()
            .createMessageCopyAction(
                hermesNode.getHermes(),
                destinationNode.getDestinationName(),
                destinationNode.getDomain(),
                messages,
                true,
                true);
      }
    }

    return true;
  }
Пример #7
0
  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;
  }
Пример #8
0
  private boolean doMessagesTransfer(MessageGroup messages, int action) {
    List<DestinationConfigTreeNode> nodes = getSelectedDestinationNodes();

    if (nodes.size() > 0) {
      final DestinationConfigTreeNode destinationNode = nodes.get(0);

      final HermesTreeNode hermesNode = getSelectedHermesNode();

      if (hermesNode != null && destinationNode != null) {
        Collection<Message> selected = messages.getSelectedMessages();
        Message[] messagesArray =
            messages.getSelectedMessages().toArray(new Message[selected.size()]);

        if (selected.size() == 1
            && action == TransferHandler.COPY
            && MessageEditorDialog.canEdit(messagesArray[0])) {
          try {
            Message message = selected.iterator().next();
            MessageEditorDialog dialog =
                new MessageEditorDialog(
                    message,
                    destinationNode.getDestinationName(),
                    destinationNode.getDomain(),
                    new AbstractEditedMessageHandler(hermesNode.getHermes()) {
                      @Override
                      public void onMessage(Message message) {
                        HermesBrowser.getBrowser()
                            .getActionFactory()
                            .createMessageCopyAction(
                                hermesNode.getHermes(),
                                destinationNode.getDestinationName(),
                                destinationNode.getDomain(),
                                new ArrayList(Arrays.asList(message)),
                                false,
                                true);
                      }
                    });
            dialog.setLocationRelativeTo(HermesBrowser.getBrowser());
            dialog.setVisible(true);
          } catch (JMSException ex) {
            HermesBrowser.getBrowser().showErrorDialog(ex);
          }

        } else {

          if (action == TransferHandler.COPY) {
            HermesBrowser.getBrowser()
                .getActionFactory()
                .createMessageCopyAction(
                    hermesNode.getHermes(),
                    destinationNode.getDestinationName(),
                    destinationNode.getDomain(),
                    selected,
                    true,
                    true);
          } else {
            HermesBrowser.getBrowser()
                .getActionFactory()
                .createMessageMoveAction(
                    hermesNode.getHermes(),
                    destinationNode.getDestinationName(),
                    destinationNode.getDomain(),
                    selected);
          }
        }
      }
    } else {
      if (getSelectionPath() != null) {
        if (getSelectionPath().getLastPathComponent() instanceof RepositoryTreeNode) {
          final RepositoryTreeNode node =
              (RepositoryTreeNode) getSelectionPath().getLastPathComponent();

          try {
            node.getRepository().addMessages(messages.getHermes(), messages.getSelectedMessages());
          } catch (JMSException e) {
            throw new HermesRuntimeException(e);
          }
        } else if (getSelectionPath().getLastPathComponent() instanceof MessageStoreTreeNode) {
          final MessageStoreTreeNode node =
              (MessageStoreTreeNode) getSelectionPath().getLastPathComponent();

          HermesBrowser.getBrowser()
              .getThreadPool()
              .invokeLater(
                  new AddToMessageStoreTask(
                      node.getMessageStore(), messages.getSelectedMessages()));
        }
      } else {
        HermesBrowser.getBrowser().showErrorDialog("No session/destination selected for copy");
      }
    }
    return true;
  }
Пример #9
0
  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);
        }
      }
    }
  }