Пример #1
0
  /**
   * Retrieves the value of the specified attribute as a string.
   *
   * @param attributeName The name of the target attribute.
   * @return The string value of the specified attribute, or {@code null} if it does not exist in
   *     the entry.
   */
  protected final String getString(final String attributeName) {
    final String valueStr = entry.getAttributeValue(attributeName);
    if ((valueStr == null) && debugEnabled(DebugType.MONITOR)) {
      debugMonitor(entry, "No value for string attribute " + attributeName);
    }

    return valueStr;
  }
Пример #2
0
  /**
   * Gets the most appropriate monitor class from the provided entry.
   *
   * @param entry The entry from which to extract the monitor class.
   * @return The most appropriate monitor class from the provided entry, or the generic monitor
   *     object class if no appropriate subclass could be identified.
   */
  private static String getMonitorClass(final Entry entry) {
    String monitorOC = null;
    final String[] ocNames = entry.getObjectClassValues();
    for (final String oc : ocNames) {
      if (oc.equalsIgnoreCase("top")
          || oc.equalsIgnoreCase("extensibleObject")
          || oc.equalsIgnoreCase(GENERIC_MONITOR_OC)) {
        // This isn't the class we're looking for.
        continue;
      } else if (oc.equalsIgnoreCase(NumericGaugeMonitorEntry.NUMERIC_GAUGE_MONITOR_OC)
          || oc.equalsIgnoreCase(IndicatorGaugeMonitorEntry.INDICATOR_GAUGE_MONITOR_OC)) {
        // These classes are subclasses of the base gauge monitor class.
        // We'll allow them even if the monitor class is already set.
        monitorOC = oc;
      } else if (oc.equalsIgnoreCase(GaugeMonitorEntry.GAUGE_MONITOR_OC)) {
        // This is a superclass for the numeric and indicator gauge classes.
        // We'll use it only if the monitor class isn't set, but we won't
        // complain if the monitor class is already set.
        if (monitorOC == null) {
          monitorOC = oc;
        }
      } else {
        if (monitorOC != null) {
          if (debugEnabled(DebugType.MONITOR)) {
            debugMonitor(
                entry, "Multiple monitor subclasses detected:  " + monitorOC + " and " + oc);
          }
        }

        monitorOC = oc;
      }
    }

    if (monitorOC == null) {
      if (entry.hasObjectClass(GENERIC_MONITOR_OC)) {
        debugMonitor(entry, "No appropriate monitor subclass");
      } else {
        debugMonitor(entry, "Missing the generic monitor class");
      }

      return GENERIC_MONITOR_OC;
    } else {
      return monitorOC;
    }
  }
Пример #3
0
  /**
   * Retrieves the set of values of the specified attribute as a string list.
   *
   * @param attributeName The name of the target attribute.
   * @return The string values of the specified attribute, or an empty list if the specified
   *     attribute does not exist in the entry.
   */
  protected final List<String> getStrings(final String attributeName) {
    final String[] valueStrs = entry.getAttributeValues(attributeName);
    if (valueStrs == null) {
      if (debugEnabled(DebugType.MONITOR)) {
        debugMonitor(entry, "No values for string attribute " + attributeName);
      }

      return Collections.emptyList();
    }

    return Collections.unmodifiableList(Arrays.asList(valueStrs));
  }
Пример #4
0
  /**
   * Retrieves the value of the specified attribute as a {@code Boolean} object.
   *
   * @param attributeName The name of the target attribute.
   * @return The {@code Boolean} object parsed from the specified attribute, or {@code null} if the
   *     attribute does not exist in the entry or it cannot be parsed as a {@code Boolean} value.
   */
  protected final Boolean getBoolean(final String attributeName) {
    final String valueStr = entry.getAttributeValue(attributeName);
    if (valueStr == null) {
      if (debugEnabled(DebugType.MONITOR)) {
        debugMonitor(entry, "No value for Boolean attribute " + attributeName);
      }

      return null;
    } else if (valueStr.equalsIgnoreCase("true")) {
      return Boolean.TRUE;
    } else if (valueStr.equalsIgnoreCase("false")) {
      return Boolean.FALSE;
    } else {
      if (debugEnabled(DebugType.MONITOR)) {
        debugMonitor(
            entry, "Invalid value '" + valueStr + "' for Boolean attribute " + attributeName);
      }

      return null;
    }
  }
Пример #5
0
  /**
   * Retrieves the value of the specified attribute as a {@code Long} object.
   *
   * @param attributeName The name of the target attribute.
   * @return The {@code Long} object parsed from the specified attribute, or {@code null} if the
   *     attribute does not exist in the entry or it cannot be parsed as a {@code Long} value.
   */
  protected final Long getLong(final String attributeName) {
    final String valueStr = entry.getAttributeValue(attributeName);
    if (valueStr == null) {
      if (debugEnabled(DebugType.MONITOR)) {
        debugMonitor(entry, "No value for Long attribute " + attributeName);
      }

      return null;
    } else {
      try {
        return Long.parseLong(valueStr);
      } catch (Exception e) {
        debugException(e);

        if (debugEnabled(DebugType.MONITOR)) {
          debugMonitor(
              entry, "Invalid value '" + valueStr + "' for Long attribute " + attributeName);
        }

        return null;
      }
    }
  }
Пример #6
0
  /**
   * Retrieves the value of the specified attribute as a {@code Date} object.
   *
   * @param attributeName The name of the target attribute.
   * @return The {@code Date} object parsed from the specified attribute, or {@code null} if the
   *     attribute does not exist in the entry or it cannot be parsed as a {@code Date} value.
   */
  protected final Date getDate(final String attributeName) {
    final String valueStr = entry.getAttributeValue(attributeName);
    if (valueStr == null) {
      if (debugEnabled(DebugType.MONITOR)) {
        debugMonitor(entry, "No value for Date attribute " + attributeName);
      }

      return null;
    } else {
      try {
        return decodeGeneralizedTime(valueStr);
      } catch (Exception e) {
        debugException(e);

        if (debugEnabled(DebugType.MONITOR)) {
          debugMonitor(
              entry, "Invalid value '" + valueStr + "' for Date attribute " + attributeName);
        }

        return null;
      }
    }
  }