/**
   * This method extracts the xmpp address and message text from the parameters passed in the
   * notification.
   *
   * @param arguments
   * @return String[]
   * @throws Exception
   */
  private String[] parseArguments(List<Argument> arguments) throws Exception {

    String[] parsedArgs = new String[XMPP_MAX];

    for (int i = 0; i < arguments.size(); i++) {

      Argument arg = arguments.get(i);

      if (NotificationManager.PARAM_XMPP_ADDRESS.equals(arg.getSwitch())) {
        parsedArgs[XMPP_TO] = arg.getValue();
      } else if (NotificationManager.PARAM_TEXT_MSG.equals(arg.getSwitch())) {
        parsedArgs[XMPP_MESSAGE] = arg.getValue();
      } else if (NotificationManager.PARAM_NUM_MSG.equals(arg.getSwitch())) {
        parsedArgs[XMPP_MESSAGE] = arg.getValue();
      }
    }

    for (int i = 0; i < XMPP_MAX; ++i) {
      if (parsedArgs[i] == null) {
        throw (new Exception("Incomplete argument set, missing argument: " + INDEX_TO_NAME[i]));
      }
    }

    return parsedArgs;
  }
  private void declareBeans(BSFManager bsfManager) throws BSFException {
    NodeDao nodeDao = Notifd.getInstance().getNodeDao();
    Integer nodeId;
    try {
      nodeId = Integer.valueOf(m_notifParams.get(NotificationManager.PARAM_NODE));
    } catch (NumberFormatException nfe) {
      nodeId = null;
    }

    OnmsNode node = null;
    OnmsAssetRecord assets = null;
    List<String> categories = new ArrayList<String>();
    String nodeLabel = null;
    String foreignSource = null;
    String foreignId = null;

    if (nodeId != null) {
      node = nodeDao.get(nodeId);
      nodeLabel = node.getLabel();
      assets = node.getAssetRecord();
      for (OnmsCategory cat : node.getCategories()) {
        categories.add(cat.getName());
      }
      foreignSource = node.getForeignSource();
      foreignId = node.getForeignId();
    }

    bsfManager.declareBean("bsf_notif_strategy", this, BSFNotificationStrategy.class);

    retrieveParams();
    bsfManager.declareBean("notif_params", m_notifParams, Map.class);

    bsfManager.declareBean("node_label", nodeLabel, String.class);
    bsfManager.declareBean("foreign_source", foreignSource, String.class);
    bsfManager.declareBean("foreign_id", foreignId, String.class);
    bsfManager.declareBean("node_assets", assets, OnmsAssetRecord.class);
    bsfManager.declareBean("node_categories", categories, List.class);
    bsfManager.declareBean("node", node, OnmsNode.class);

    for (Argument arg : m_arguments) {
      if (NotificationManager.PARAM_TEXT_MSG.equals(arg.getSwitch()))
        bsfManager.declareBean("text_message", arg.getValue(), String.class);
      if (NotificationManager.PARAM_NUM_MSG.equals(arg.getSwitch()))
        bsfManager.declareBean("numeric_message", arg.getValue(), String.class);
      if (NotificationManager.PARAM_NODE.equals(arg.getSwitch()))
        bsfManager.declareBean("node_id", arg.getValue(), String.class);
      if (NotificationManager.PARAM_INTERFACE.equals(arg.getSwitch()))
        bsfManager.declareBean("ip_addr", arg.getValue(), String.class);
      if (NotificationManager.PARAM_SERVICE.equals(arg.getSwitch()))
        bsfManager.declareBean("svc_name", arg.getValue(), String.class);
      if (NotificationManager.PARAM_SUBJECT.equals(arg.getSwitch()))
        bsfManager.declareBean("subject", arg.getValue(), String.class);
      if (NotificationManager.PARAM_EMAIL.equals(arg.getSwitch()))
        bsfManager.declareBean("email", arg.getValue(), String.class);
      if (NotificationManager.PARAM_PAGER_EMAIL.equals(arg.getSwitch()))
        bsfManager.declareBean("pager_email", arg.getValue(), String.class);
      if (NotificationManager.PARAM_XMPP_ADDRESS.equals(arg.getSwitch()))
        bsfManager.declareBean("xmpp_address", arg.getValue(), String.class);
      if (NotificationManager.PARAM_TEXT_PAGER_PIN.equals(arg.getSwitch()))
        bsfManager.declareBean("text_pin", arg.getValue(), String.class);
      if (NotificationManager.PARAM_NUM_PAGER_PIN.equals(arg.getSwitch()))
        bsfManager.declareBean("numeric_pin", arg.getValue(), String.class);
      if (NotificationManager.PARAM_WORK_PHONE.equals(arg.getSwitch()))
        bsfManager.declareBean("work_phone", arg.getValue(), String.class);
      if (NotificationManager.PARAM_HOME_PHONE.equals(arg.getSwitch()))
        bsfManager.declareBean("home_phone", arg.getValue(), String.class);
      if (NotificationManager.PARAM_MOBILE_PHONE.equals(arg.getSwitch()))
        bsfManager.declareBean("mobile_phone", arg.getValue(), String.class);
      if (NotificationManager.PARAM_TUI_PIN.equals(arg.getSwitch()))
        bsfManager.declareBean("phone_pin", arg.getValue(), String.class);
      if (NotificationManager.PARAM_MICROBLOG_USERNAME.equals(arg.getSwitch()))
        bsfManager.declareBean("microblog_username", arg.getValue(), String.class);
    }
  }