From f37a50cbb1c1aaffad3573b5dc10442adf9fcfbe Mon Sep 17 00:00:00 2001
From: Matthew Swift <matthew.swift@forgerock.com>
Date: Sat, 18 Jan 2014 01:12:08 +0000
Subject: [PATCH] Simplify config framework exception hierarchy by removing AdminRuntimeException + additional minor cleanup.

---
 /dev/null                                                                                                           |   78 ---------------------------------------
 opendj-sdk/opendj-config/src/main/java/org/forgerock/opendj/config/server/ServerManagedObjectDecodingException.java |    4 +-
 opendj-sdk/opendj-config/src/main/java/org/forgerock/opendj/config/client/ManagedObjectDecodingException.java       |    4 +-
 opendj-sdk/opendj-config/src/main/java/org/forgerock/opendj/config/PropertyException.java                           |   33 +++++++++++-----
 4 files changed, 27 insertions(+), 92 deletions(-)

diff --git a/opendj-sdk/opendj-config/src/main/java/org/forgerock/opendj/config/AdminRuntimeException.java b/opendj-sdk/opendj-config/src/main/java/org/forgerock/opendj/config/AdminRuntimeException.java
deleted file mode 100644
index 742a7d0..0000000
--- a/opendj-sdk/opendj-config/src/main/java/org/forgerock/opendj/config/AdminRuntimeException.java
+++ /dev/null
@@ -1,78 +0,0 @@
-/*
- * CDDL HEADER START
- *
- * The contents of this file are subject to the terms of the
- * Common Development and Distribution License, Version 1.0 only
- * (the "License").  You may not use this file except in compliance
- * with the License.
- *
- * You can obtain a copy of the license at legal-notices/CDDLv1_0.txt
- * or http://forgerock.org/license/CDDLv1.0.html.
- * See the License for the specific language governing permissions
- * and limitations under the License.
- *
- * When distributing Covered Code, include this CDDL HEADER in each
- * file and include the License file at legal-notices/CDDLv1_0.txt.
- * If applicable, add the following below this CDDL HEADER, with the
- * fields enclosed by brackets "[]" replaced with your own identifying
- * information:
- *      Portions Copyright [yyyy] [name of copyright owner]
- *
- * CDDL HEADER END
- *
- *
- *      Copyright 2008-2009 Sun Microsystems, Inc.
- */
-
-package org.forgerock.opendj.config;
-
-import org.forgerock.i18n.LocalizableMessage;
-
-/**
- * Exceptions thrown when interacting with administration framework that
- * applications are not expected to catch.
- */
-public abstract class AdminRuntimeException extends RuntimeException {
-
-    /**
-     * Fake serialization ID.
-     */
-    private static final long serialVersionUID = 1L;
-
-    // LocalizableMessage that explains the problem.
-    private final LocalizableMessage message;
-
-    /**
-     * Create an admin runtime exception with a message and cause.
-     *
-     * @param message
-     *            The message.
-     * @param cause
-     *            The cause.
-     */
-    protected AdminRuntimeException(LocalizableMessage message, Throwable cause) {
-        super(message.toString(), cause);
-        this.message = message;
-    }
-
-    /**
-     * Create an admin runtime exception with a message.
-     *
-     * @param message
-     *            The message.
-     */
-    protected AdminRuntimeException(LocalizableMessage message) {
-        super(message.toString());
-        this.message = message;
-    }
-
-    /**
-     * Returns the message that explains the problem that occurred.
-     *
-     * @return Returns the message describing the problem that occurred (never
-     *         <code>null</code>).
-     */
-    public LocalizableMessage getLocalizableMessageObject() {
-        return this.message;
-    }
-}
diff --git a/opendj-sdk/opendj-config/src/main/java/org/forgerock/opendj/config/PropertyException.java b/opendj-sdk/opendj-config/src/main/java/org/forgerock/opendj/config/PropertyException.java
index 59ce8cf..9eb6966 100644
--- a/opendj-sdk/opendj-config/src/main/java/org/forgerock/opendj/config/PropertyException.java
+++ b/opendj-sdk/opendj-config/src/main/java/org/forgerock/opendj/config/PropertyException.java
@@ -33,13 +33,14 @@
 import static com.forgerock.opendj.ldap.AdminMessages.ERR_PROPERTY_IS_SINGLE_VALUED_EXCEPTION;
 import static com.forgerock.opendj.ldap.AdminMessages.ERR_UNKNOWN_PROPERTY_DEFINITION_EXCEPTION;
 
+import org.forgerock.i18n.LocalizableException;
 import org.forgerock.i18n.LocalizableMessage;
 
 /**
  * Exceptions thrown as a result of errors that occurred when decoding and
  * modifying property values.
  */
-public final class PropertyException extends AdminRuntimeException {
+public final class PropertyException extends RuntimeException implements LocalizableException {
 
     /**
      * Version ID required by serializable classes.
@@ -94,7 +95,7 @@
     }
 
     /**
-     * Create a new property is mandatory exception.
+     * Creates a new property is mandatory exception.
      *
      * @param pd
      *            The property definition.
@@ -105,7 +106,7 @@
     }
 
     /**
-     * Create a new property is read-only exception.
+     * Creates a new property is read-only exception.
      *
      * @param pd
      *            The property definition.
@@ -116,7 +117,7 @@
     }
 
     /**
-     * Create a new property is single valued exception.
+     * Creates a new property is single valued exception.
      *
      * @param pd
      *            The property definition.
@@ -149,27 +150,39 @@
                 builder.getUsage(pd));
     }
 
+    // LocalizableMessage that explains the problem.
+    private final LocalizableMessage message;
+
     // The property definition associated with the property that caused
     // the exception.
     private final PropertyDefinition<?> pd;
 
     private PropertyException(final PropertyDefinition<?> pd, final LocalizableMessage message) {
-        super(message);
+        super(message.toString());
+        this.message = message;
         this.pd = pd;
     }
 
     private PropertyException(final PropertyDefinition<?> pd, final LocalizableMessage message,
             final Throwable cause) {
-        super(message, cause);
+        super(message.toString(), cause);
+        this.message = message;
         this.pd = pd;
     }
 
     /**
-     * Get the property definition associated with the property that caused the
-     * exception.
+     * {@inheritDoc}
+     */
+    public LocalizableMessage getMessageObject() {
+        return message;
+    }
+
+    /**
+     * Returns the property definition associated with the property that caused
+     * the exception.
      *
-     * @return Returns the property definition associated with the property that
-     *         caused the exception.
+     * @return The property definition associated with the property that caused
+     *         the exception.
      */
     public final PropertyDefinition<?> getPropertyDefinition() {
         return pd;
diff --git a/opendj-sdk/opendj-config/src/main/java/org/forgerock/opendj/config/client/ManagedObjectDecodingException.java b/opendj-sdk/opendj-config/src/main/java/org/forgerock/opendj/config/client/ManagedObjectDecodingException.java
index b0483b0..39e418d 100644
--- a/opendj-sdk/opendj-config/src/main/java/org/forgerock/opendj/config/client/ManagedObjectDecodingException.java
+++ b/opendj-sdk/opendj-config/src/main/java/org/forgerock/opendj/config/client/ManagedObjectDecodingException.java
@@ -58,7 +58,7 @@
         ManagedObjectDefinition<?, ?> d = partialManagedObject.getManagedObjectDefinition();
         if (causes.size() == 1) {
             return ERR_MANAGED_OBJECT_DECODING_EXCEPTION_SINGLE.get(d.getUserFriendlyName(), causes.iterator().next()
-                .getLocalizableMessageObject());
+                .getMessageObject());
         } else {
             LocalizableMessageBuilder builder = new LocalizableMessageBuilder();
 
@@ -67,7 +67,7 @@
                 if (!isFirst) {
                     builder.append("; ");
                 }
-                builder.append(cause.getLocalizableMessageObject());
+                builder.append(cause.getMessageObject());
                 isFirst = false;
             }
 
diff --git a/opendj-sdk/opendj-config/src/main/java/org/forgerock/opendj/config/server/ServerManagedObjectDecodingException.java b/opendj-sdk/opendj-config/src/main/java/org/forgerock/opendj/config/server/ServerManagedObjectDecodingException.java
index 756507f..48df7b7 100644
--- a/opendj-sdk/opendj-config/src/main/java/org/forgerock/opendj/config/server/ServerManagedObjectDecodingException.java
+++ b/opendj-sdk/opendj-config/src/main/java/org/forgerock/opendj/config/server/ServerManagedObjectDecodingException.java
@@ -59,7 +59,7 @@
         ManagedObjectDefinition<?, ?> d = partialManagedObject.getManagedObjectDefinition();
         if (causes.size() == 1) {
             return ERR_MANAGED_OBJECT_DECODING_EXCEPTION_SINGLE.get(d.getUserFriendlyName(), causes.iterator().next()
-                    .getLocalizableMessageObject());
+                    .getMessageObject());
         } else {
             LocalizableMessageBuilder builder = new LocalizableMessageBuilder();
 
@@ -68,7 +68,7 @@
                 if (!isFirst) {
                     builder.append("; ");
                 }
-                builder.append(cause.getLocalizableMessageObject());
+                builder.append(cause.getMessageObject());
                 isFirst = false;
             }
 

--
Gitblit v1.10.0