From 8532a5133e996e61765be126f8b4d25984745fd1 Mon Sep 17 00:00:00 2001
From: matthew_swift <matthew_swift@localhost>
Date: Mon, 03 Sep 2007 13:33:50 +0000
Subject: [PATCH] Partial fix for issue 1451: admin framework constraint and dependency support.

---
 opends/src/server/org/opends/server/admin/client/OperationRejectedException.java |  109 +++++++++++++++++++++++++++++++++++++++---------------
 1 files changed, 78 insertions(+), 31 deletions(-)

diff --git a/opends/src/server/org/opends/server/admin/client/OperationRejectedException.java b/opends/src/server/org/opends/server/admin/client/OperationRejectedException.java
index 45095ee..a2736f0 100644
--- a/opends/src/server/org/opends/server/admin/client/OperationRejectedException.java
+++ b/opends/src/server/org/opends/server/admin/client/OperationRejectedException.java
@@ -26,15 +26,29 @@
  */
 
 package org.opends.server.admin.client;
-import org.opends.messages.Message;
 
 
 
+import static org.opends.messages.AdminMessages.*;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+
+import org.opends.messages.Message;
+import org.opends.messages.MessageBuilder;
+import org.opends.server.util.Validator;
+
+
 
 /**
- * This exception is thrown when the server refuses to create, delete,
- * or modify a managed object due to some server-side constraint that
- * cannot be satisified and which cannot be enforced by the client.
+ * This exception is thrown when the client or server refuses to
+ * create, delete, or modify a managed object due to one or more
+ * constraints that cannot be satisfied.
+ * <p>
+ * Operations can be rejected either by a client-side constraint
+ * violation triggered by {@link ClientConstraintHandler}, or by a
+ * server-side error.
  * <p>
  * For example, the Directory Server might not be able perform an
  * operation due to some OS related problem, such as lack of disk
@@ -49,48 +63,81 @@
 
 
 
-  /**
-   * Create an operation rejected exception.
-   */
-  public OperationRejectedException() {
-    // No implementation required.
+  // Merge the messages into a single message.
+  private static Message getSingleMessage(Collection<Message> messages) {
+    Validator.ensureNotNull(messages);
+    Validator.ensureTrue(!messages.isEmpty());
+
+    MessageBuilder builder = new MessageBuilder();
+
+    boolean isFirst = true;
+    for (Message m : messages) {
+      if (!isFirst) {
+        builder.append("; ");
+      }
+      builder.append(m);
+      isFirst = false;
+    }
+
+    return builder.toMessage();
   }
 
+  // The messages describing the constraint violations that occurred.
+  private final Collection<Message> messages;
+
 
 
   /**
-   * Create an operation rejected exception with a cause.
+   * Creates a new operation rejected exception with the provided
+   * messages.
    *
-   * @param cause
-   *          The cause.
+   * @param messages
+   *          The messages describing the constraint violations that
+   *          occurred (must be non-<code>null</code> and
+   *          non-empty).
    */
-  public OperationRejectedException(Throwable cause) {
-    super(cause);
+  public OperationRejectedException(Collection<Message> messages) {
+    super(getSingleMessage(messages));
+
+    this.messages = new ArrayList<Message>(messages);
   }
 
 
 
   /**
-   * Create an operation rejected exception with a message and cause.
+   * Creates a new operation rejected exception with the provided
+   * message.
    *
    * @param message
-   *          The message.
-   * @param cause
-   *          The cause.
-   */
-  public OperationRejectedException(Message message, Throwable cause) {
-    super(message, cause);
-  }
-
-
-
-  /**
-   * Create an operation rejected exception with a message.
-   *
-   * @param message
-   *          The message.
+   *          The message describing the constraint violation that
+   *          occurred (must be non-<code>null</code> and
+   *          non-empty).
    */
   public OperationRejectedException(Message message) {
-    super(message);
+    this(Collections.singleton(message));
   }
+
+
+
+  /**
+   * Creates a new operation rejected exception with a default
+   * message.
+   */
+  public OperationRejectedException() {
+    this(ERR_OPERATION_REJECTED_DEFAULT.get());
+  }
+
+
+
+  /**
+   * Gets an unmodifiable collection view of the messages describing
+   * the constraint violations that occurred.
+   *
+   * @return Returns an unmodifiable collection view of the messages
+   *         describing the constraint violations that occurred.
+   */
+  public Collection<Message> getMessages() {
+    return Collections.unmodifiableCollection(messages);
+  }
+
 }

--
Gitblit v1.10.0