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

Nicolas Capponi
04.13.2013 e538344449d345daa6e5ecb9b05ceba5427408e9
opendj-admin/src/main/java/org/opends/server/admin/server/ServerManagedObjectDecodingException.java
@@ -27,8 +27,6 @@
package org.opends.server.admin.server;
import static com.forgerock.opendj.ldap.AdminMessages.*;
import java.util.Collection;
@@ -42,107 +40,90 @@
import org.opends.server.admin.PropertyException;
import static com.forgerock.opendj.util.Validator.*;
/**
 * The requested server managed object was found but one or more of
 * its properties could not be decoded successfully.
 * The requested server managed object was found but one or more of its
 * properties could not be decoded successfully.
 */
public class ServerManagedObjectDecodingException extends DecodingException {
  /**
   * Version ID required by serializable classes.
   */
  private static final long serialVersionUID = 1598401431084729853L;
    /**
     * Version ID required by serializable classes.
     */
    private static final long serialVersionUID = 1598401431084729853L;
    // Create the message.
    private static LocalizableMessage createMessage(ServerManagedObject<?> partialManagedObject,
            Collection<PropertyException> causes) {
        ensureNotNull(causes);
        ensureTrue(!causes.isEmpty(), "causes should nnot be empty");
        ManagedObjectDefinition<?, ?> d = partialManagedObject.getManagedObjectDefinition();
        if (causes.size() == 1) {
            return ERR_MANAGED_OBJECT_DECODING_EXCEPTION_SINGLE.get(d.getUserFriendlyName(), causes.iterator().next()
                    .getLocalizableMessageObject());
        } else {
            LocalizableMessageBuilder builder = new LocalizableMessageBuilder();
  // Create the message.
  private static LocalizableMessage createMessage(
      ServerManagedObject<?> partialManagedObject,
      Collection<PropertyException> causes) {
    ensureNotNull(causes);
    ensureTrue(!causes.isEmpty(), "causes should nnot be empty");
            boolean isFirst = true;
            for (PropertyException cause : causes) {
                if (!isFirst) {
                    builder.append("; ");
                }
                builder.append(cause.getLocalizableMessageObject());
                isFirst = false;
            }
    ManagedObjectDefinition<?, ?> d = partialManagedObject
        .getManagedObjectDefinition();
    if (causes.size() == 1) {
      return ERR_MANAGED_OBJECT_DECODING_EXCEPTION_SINGLE.get(d
          .getUserFriendlyName(), causes.iterator().next().getMessageObject());
    } else {
      LocalizableMessageBuilder builder = new MessageBuilder();
      boolean isFirst = true;
      for (PropertyException cause : causes) {
        if (!isFirst) {
          builder.append("; ");
            return ERR_MANAGED_OBJECT_DECODING_EXCEPTION_PLURAL.get(d.getUserFriendlyName(), builder.toMessage());
        }
        builder.append(cause.getMessageObject());
        isFirst = false;
      }
      return ERR_MANAGED_OBJECT_DECODING_EXCEPTION_PLURAL.get(d
          .getUserFriendlyName(), builder.toMessage());
    }
  }
  // The exception(s) that caused this decoding exception.
  private final Collection<PropertyException> causes;
    // The exception(s) that caused this decoding exception.
    private final Collection<PropertyException> causes;
  // The partially created server managed object.
  private final ServerManagedObject<?> partialManagedObject;
    // The partially created server managed object.
    private final ServerManagedObject<?> partialManagedObject;
    /**
     * Create a new property decoding exception.
     *
     * @param partialManagedObject
     *            The partially created server managed object containing
     *            properties which were successfully decoded and empty
     *            properties for those which were not (this may include empty
     *            mandatory properties).
     * @param causes
     *            The exception(s) that caused this decoding exception.
     */
    public ServerManagedObjectDecodingException(ServerManagedObject<?> partialManagedObject,
            Collection<PropertyException> causes) {
        super(createMessage(partialManagedObject, causes));
        this.partialManagedObject = partialManagedObject;
        this.causes = Collections.unmodifiableList(new LinkedList<PropertyException>(causes));
    }
  /**
   * Create a new property decoding exception.
   *
   * @param partialManagedObject
   *          The partially created server managed object containing
   *          properties which were successfully decoded and empty
   *          properties for those which were not (this may include
   *          empty mandatory properties).
   * @param causes
   *          The exception(s) that caused this decoding exception.
   */
  public ServerManagedObjectDecodingException(
      ServerManagedObject<?> partialManagedObject,
      Collection<PropertyException> causes) {
    super(createMessage(partialManagedObject, causes));
    /**
     * Get an unmodifiable collection view of the causes of this exception.
     *
     * @return Returns an unmodifiable collection view of the causes of this
     *         exception.
     */
    public Collection<PropertyException> getCauses() {
        return causes;
    }
    this.partialManagedObject = partialManagedObject;
    this.causes = Collections
        .unmodifiableList(new LinkedList<PropertyException>(causes));
  }
  /**
   * Get an unmodifiable collection view of the causes of this
   * exception.
   *
   * @return Returns an unmodifiable collection view of the causes of
   *         this exception.
   */
  public Collection<PropertyException> getCauses() {
    return causes;
  }
  /**
   * Get the partially created server managed object containing
   * properties which were successfully decoded and empty properties
   * for those which were not (this may include empty mandatory
   * properties).
   *
   * @return Returns the partially created server managed object
   *         containing properties which were successfully decoded and
   *         empty properties for those which were not (this may
   *         include empty mandatory properties).
   */
  public ServerManagedObject<?> getPartialManagedObject() {
    return partialManagedObject;
  }
    /**
     * Get the partially created server managed object containing properties
     * which were successfully decoded and empty properties for those which were
     * not (this may include empty mandatory properties).
     *
     * @return Returns the partially created server managed object containing
     *         properties which were successfully decoded and empty properties
     *         for those which were not (this may include empty mandatory
     *         properties).
     */
    public ServerManagedObject<?> getPartialManagedObject() {
        return partialManagedObject;
    }
}