// Create the message.
  private static Message createMessage(
      ServerManagedObject<?> partialManagedObject, Collection<PropertyException> causes) {
    Validator.ensureNotNull(causes);
    Validator.ensureTrue(!causes.isEmpty());

    ManagedObjectDefinition<?, ?> d = partialManagedObject.getManagedObjectDefinition();
    if (causes.size() == 1) {
      return ERR_MANAGED_OBJECT_DECODING_EXCEPTION_SINGLE.get(
          d.getUserFriendlyName(), causes.iterator().next().getMessageObject());
    } else {
      MessageBuilder builder = new MessageBuilder();

      boolean isFirst = true;
      for (PropertyException cause : causes) {
        if (!isFirst) {
          builder.append("; ");
        }
        builder.append(cause.getMessageObject());
        isFirst = false;
      }

      return ERR_MANAGED_OBJECT_DECODING_EXCEPTION_PLURAL.get(
          d.getUserFriendlyName(), builder.toMessage());
    }
  }
 /**
  * Concatenate a list of messages into a single message.
  *
  * @param reasons The list of messages to concatenate.
  * @param unacceptableReason The single message to which messages should be appended.
  */
 protected final void generateUnacceptableReason(
     Collection<Message> reasons, MessageBuilder unacceptableReason) {
   boolean isFirst = true;
   for (Message reason : reasons) {
     if (isFirst) {
       isFirst = false;
     } else {
       unacceptableReason.append("  ");
     }
     unacceptableReason.append(reason);
   }
 }
 /** {@inheritDoc} */
 @Override
 public boolean valueIsAcceptable(ByteSequence value, MessageBuilder invalidReason) {
   String strValue = value.toString();
   boolean matches = pattern.matcher(strValue).matches();
   if (!matches) {
     Message message =
         WARN_ATTR_SYNTAX_LDAPSYNTAX_REGEX_INVALID_VALUE.get(strValue, pattern.pattern());
     invalidReason.append(message);
   }
   return matches;
 }
    /** {@inheritDoc} */
    @Override
    public boolean valueIsAcceptable(ByteSequence value, MessageBuilder invalidReason) {
      // The value is acceptable if it belongs to the set.
      boolean isAllowed = entries.contains(value);

      if (!isAllowed) {
        Message message = WARN_ATTR_SYNTAX_LDAPSYNTAX_ENUM_INVALID_VALUE.get(value.toString(), oid);
        invalidReason.append(message);
      }

      return isAllowed;
    }
  /**
   * Indicates whether the provided value is acceptable for use in an attribute with this syntax. If
   * it is not, then the reason may be appended to the provided buffer.
   *
   * @param value The value for which to make the determination.
   * @param invalidReason The buffer to which the invalid reason should be appended.
   * @return <CODE>true</CODE> if the provided value is acceptable for use with this syntax, or
   *     <CODE>false</CODE> if not.
   */
  @Override
  public boolean valueIsAcceptable(ByteSequence value, MessageBuilder invalidReason) {
    // We'll use the decodeAttributeType method to determine if the value is
    // acceptable.
    try {
      decodeLDAPSyntax(value, DirectoryServer.getSchema(), true);
      return true;
    } catch (DirectoryException de) {
      if (debugEnabled()) {
        TRACER.debugCaught(DebugLogLevel.ERROR, de);
      }

      invalidReason.append(de.getMessageObject());
      return false;
    }
  }
  /** {@inheritDoc} */
  @Override()
  public boolean passwordIsAcceptable(
      ByteString newPassword,
      Set<ByteString> currentPasswords,
      Operation operation,
      Entry userEntry,
      MessageBuilder invalidReason) {
    // Get a handle to the current configuration and see if we need to count
    // the number of repeated characters in the password.
    RepeatedCharactersPasswordValidatorCfg config = currentConfig;
    int maxRepeats = config.getMaxConsecutiveLength();
    if (maxRepeats <= 0) {
      // We don't need to check anything, so the password will be acceptable.
      return true;
    }

    // Get the password as a string.  If we should use case-insensitive
    // validation, then convert it to use all lowercase characters.
    String passwordString = newPassword.toString();
    if (!config.isCaseSensitiveValidation()) {
      passwordString = passwordString.toLowerCase();
    }

    // Create variables to keep track of the last character we've seen and how
    // many times we have seen it.
    char lastCharacter = '\u0000';
    int consecutiveCount = 0;

    // Iterate through the characters in the password.  If the consecutive
    // count ever gets too high, then fail.
    for (int i = 0; i < passwordString.length(); i++) {
      char currentCharacter = passwordString.charAt(i);
      if (currentCharacter == lastCharacter) {
        consecutiveCount++;
        if (consecutiveCount > maxRepeats) {
          Message message = ERR_REPEATEDCHARS_VALIDATOR_TOO_MANY_CONSECUTIVE.get(maxRepeats);
          invalidReason.append(message);
          return false;
        }
      } else {
        lastCharacter = currentCharacter;
        consecutiveCount = 1;
      }
    }

    return true;
  }
  /**
   * Indicates whether the provided value is acceptable for use in an attribute with this syntax. If
   * it is not, then the reason may be appended to the provided buffer.
   *
   * @param value The value for which to make the determination.
   * @param invalidReason The buffer to which the invalid reason should be appended.
   * @return <CODE>true</CODE> if the provided value is acceptable for use with this syntax, or
   *     <CODE>false</CODE> if not.
   */
  public boolean valueIsAcceptable(ByteSequence value, MessageBuilder invalidReason) {
    // Check to see if the provided value was null.  If so, then that's not
    // acceptable.
    if (value == null) {

      invalidReason.append(ERR_ATTR_SYNTAX_OTHER_MAILBOX_EMPTY_VALUE.get());
      return false;
    }

    // Get the value as a string and determine its length.  If it is empty, then
    // that's not acceptable.
    String valueString = value.toString();
    int valueLength = valueString.length();
    if (valueLength == 0) {

      invalidReason.append(ERR_ATTR_SYNTAX_OTHER_MAILBOX_EMPTY_VALUE.get());
      return false;
    }

    // Iterate through the characters in the vale until we find a dollar sign.
    // Every character up to that point must be a printable string character.
    int pos = 0;
    for (; pos < valueLength; pos++) {
      char c = valueString.charAt(pos);
      if (c == '$') {
        if (pos == 0) {

          invalidReason.append(ERR_ATTR_SYNTAX_OTHER_MAILBOX_NO_MBTYPE.get(valueString));
          return false;
        }

        pos++;
        break;
      } else if (!PrintableString.isPrintableCharacter(c)) {

        invalidReason.append(
            ERR_ATTR_SYNTAX_OTHER_MAILBOX_ILLEGAL_MBTYPE_CHAR.get(
                valueString, String.valueOf(c), pos));
        return false;
      }
    }

    // Make sure there is at least one character left for the mailbox.
    if (pos >= valueLength) {

      invalidReason.append(ERR_ATTR_SYNTAX_OTHER_MAILBOX_NO_MAILBOX.get(valueString));
      return false;
    }

    // The remaining characters in the value must be IA5 (ASCII) characters.
    for (; pos < valueLength; pos++) {
      char c = valueString.charAt(pos);
      if (c != (c & 0x7F)) {

        invalidReason.append(
            ERR_ATTR_SYNTAX_OTHER_MAILBOX_ILLEGAL_MB_CHAR.get(valueString, String.valueOf(c), pos));
        return false;
      }
    }

    // If we've gotten here, then the value is OK.
    return true;
  }