mirror of https://github.com/OpenIdentityPlatform/OpenDJ.git

matthew_swift
03.36.2007 de19fe2956d5a4b3817834191c51989664f8c47c
opends/src/server/org/opends/server/admin/client/IllegalManagedObjectNameException.java
@@ -26,10 +26,12 @@
 */
package org.opends.server.admin.client;
import static org.opends.messages.AdminMessages.*;
import org.opends.messages.Message;
import org.opends.server.admin.IllegalPropertyValueStringException;
import org.opends.server.admin.OperationsException;
import org.opends.server.admin.PropertyDefinition;
@@ -53,6 +55,30 @@
   */
  private static final long serialVersionUID = 7491748228684293291L;
  // Create the message
  private static Message createMessage(String illegalName,
      PropertyDefinition<?> namingPropertyDefinition) {
    if (illegalName.length() == 0) {
      return ERR_ILLEGAL_MANAGED_OBJECT_NAME_EXCEPTION_EMPTY.get();
    } else if (illegalName.trim().length() == 0) {
      return ERR_ILLEGAL_MANAGED_OBJECT_NAME_EXCEPTION_BLANK.get();
    } else if (namingPropertyDefinition != null) {
      try {
        namingPropertyDefinition.decodeValue(illegalName);
      } catch (IllegalPropertyValueStringException e) {
        PropertyDefinitionUsageBuilder builder =
          new PropertyDefinitionUsageBuilder(true);
        return ERR_ILLEGAL_MANAGED_OBJECT_NAME_EXCEPTION_SYNTAX.get(
            illegalName, namingPropertyDefinition.getName(), builder
                .getUsage(namingPropertyDefinition));
      }
    }
    return ERR_ILLEGAL_MANAGED_OBJECT_NAME_EXCEPTION_OTHER.get(illegalName);
  }
  // The illegal name.
  private final String illegalName;
@@ -85,6 +111,8 @@
   */
  public IllegalManagedObjectNameException(String illegalName,
      PropertyDefinition<?> namingPropertyDefinition) {
    super(createMessage(illegalName, namingPropertyDefinition));
    this.illegalName = illegalName;
    this.namingPropertyDefinition = namingPropertyDefinition;
  }
@@ -112,34 +140,4 @@
    return namingPropertyDefinition;
  }
  /**
   * {@inheritDoc}
   */
  @Override
  public Message getMessageObject() {
    if (illegalName.length() == 0) {
      return Message.raw("Empty managed object names are not permitted");
    } else if (illegalName.trim().length() == 0) {
      return Message.raw("Blank managed object names are not permitted");
    } else if (namingPropertyDefinition != null) {
      try {
        namingPropertyDefinition.decodeValue(illegalName);
      } catch (IllegalPropertyValueStringException e) {
        String msg = "The managed object name \"%s\" is not a valid value "
            + "for the naming property \"%s\", which must have the following "
            + "syntax: %s";
        PropertyDefinitionUsageBuilder builder =
          new PropertyDefinitionUsageBuilder(true);
        return Message.raw(String.format(msg, illegalName,
                namingPropertyDefinition.getName(),
                builder.getUsage(namingPropertyDefinition)));
      }
    }
    return Message.raw("The managed object name \"" + illegalName +
            "\" is not permitted");
  }
}