From d46701cdbecec6f6c10f57432f3e6a484752f42c Mon Sep 17 00:00:00 2001
From: Matthew Swift <matthew.swift@forgerock.com>
Date: Sat, 18 Jan 2014 00:55:24 +0000
Subject: [PATCH] Simplify config framework exception hierarchy by removing and pulling up the following exceptions:
---
opendj3-server-dev/src/server/org/opends/server/admin/PropertyException.java | 185 ++++++++++++++++++++++++++++++++++++++-------
1 files changed, 155 insertions(+), 30 deletions(-)
diff --git a/opendj3-server-dev/src/server/org/opends/server/admin/PropertyException.java b/opendj3-server-dev/src/server/org/opends/server/admin/PropertyException.java
index 2347ef2..5134d1f 100644
--- a/opendj3-server-dev/src/server/org/opends/server/admin/PropertyException.java
+++ b/opendj3-server-dev/src/server/org/opends/server/admin/PropertyException.java
@@ -22,62 +22,186 @@
*
*
* Copyright 2008 Sun Microsystems, Inc.
+ * Portions copyright 2014 ForgeRock AS.
*/
package org.opends.server.admin;
+import static org.opends.messages.AdminMessages.*;
+
import org.opends.messages.Message;
/**
- * Exceptions thrown as a result of errors that occurred when decoding
- * and modifying property values.
+ * Exceptions thrown as a result of errors that occurred when decoding and
+ * modifying property values.
*/
-public abstract class PropertyException extends AdminRuntimeException {
+public final class PropertyException extends AdminRuntimeException
+{
/**
* Version ID required by serializable classes.
*/
private static final long serialVersionUID = -8465109598081914482L;
- // The property definition associated with the property that caused
- // the exception.
- private final PropertyDefinition<?> pd;
+
+
+ /**
+ * Creates a new default behavior exception with a cause.
+ *
+ * @param pd
+ * The property definition whose default values could not be
+ * determined.
+ * @param cause
+ * The exception that prevented the default values from being
+ * determined.
+ * @return A new default behavior exception with a cause.
+ */
+ public static PropertyException defaultBehaviorException(
+ PropertyDefinition<?> pd, Throwable cause)
+ {
+ return new PropertyException(pd,
+ ERR_DEFAULT_BEHAVIOR_PROPERTY_EXCEPTION.get(pd.getName()), cause);
+ }
/**
- * Creates property exception without a cause.
+ * Creates a new illegal property value exception.
*
* @param pd
- * The property definition associated with the property
- * that caused the exception.
- * @param message
- * The message.
+ * The property definition.
+ * @param value
+ * The illegal property value.
+ * @return A new illegal property value exception.
*/
- protected PropertyException(PropertyDefinition<?> pd, Message message) {
+ public static PropertyException illegalPropertyValueException(
+ PropertyDefinition<?> pd, Object value)
+ {
+ return new PropertyException(pd, createMessage(pd, value));
+ }
+
+
+
+ /**
+ * Creates a new illegal property value exception.
+ *
+ * @param pd
+ * The property definition.
+ * @param value
+ * The illegal property value.
+ * @param cause
+ * The cause.
+ * @return A new illegal property value exception.
+ */
+ public static PropertyException illegalPropertyValueException(
+ PropertyDefinition<?> pd, Object value, Throwable cause)
+ {
+ return new PropertyException(pd, createMessage(pd, value), cause);
+ }
+
+
+
+ /**
+ * Create a new property is mandatory exception.
+ *
+ * @param pd
+ * The property definition.
+ * @return A new property is mandatory exception.
+ */
+ public static PropertyException propertyIsMandatoryException(
+ PropertyDefinition<?> pd)
+ {
+ return new PropertyException(pd, ERR_PROPERTY_IS_MANDATORY_EXCEPTION.get(pd
+ .getName()));
+ }
+
+
+
+ /**
+ * Create a new property is read-only exception.
+ *
+ * @param pd
+ * The property definition.
+ * @return A new property is read-only exception.
+ */
+ public static PropertyException propertyIsReadOnlyException(
+ PropertyDefinition<?> pd)
+ {
+ return new PropertyException(pd, ERR_PROPERTY_IS_READ_ONLY_EXCEPTION.get(pd
+ .getName()));
+ }
+
+
+
+ /**
+ * Create a new property is single valued exception.
+ *
+ * @param pd
+ * The property definition.
+ * @return A new property is single valued exception.
+ */
+ public static PropertyException propertyIsSingleValuedException(
+ PropertyDefinition<?> pd)
+ {
+ return new PropertyException(pd,
+ ERR_PROPERTY_IS_SINGLE_VALUED_EXCEPTION.get(pd.getName()));
+ }
+
+
+
+ /**
+ * Creates a new unknown property definition exception.
+ *
+ * @param pd
+ * The unknown property definition.
+ * @param p
+ * The visitor parameter if there was one.
+ * @return A new unknown property definition exception.
+ */
+ public static PropertyException unknownPropertyDefinitionException(
+ PropertyDefinition<?> pd, Object p)
+ {
+ return new PropertyException(pd,
+ ERR_UNKNOWN_PROPERTY_DEFINITION_EXCEPTION.get(pd.getName(), pd
+ .getClass().getName()));
+ }
+
+
+
+ // Create the message.
+ private static Message createMessage(PropertyDefinition<?> pd, Object value)
+ {
+ PropertyDefinitionUsageBuilder builder = new PropertyDefinitionUsageBuilder(
+ true);
+ return ERR_ILLEGAL_PROPERTY_VALUE_EXCEPTION.get(String.valueOf(value),
+ pd.getName(), builder.getUsage(pd));
+ }
+
+
+
+ /*
+ * The property definition associated with the property that caused the
+ * exception.
+ */
+ private final PropertyDefinition<?> pd;
+
+
+
+ private PropertyException(PropertyDefinition<?> pd, Message message)
+ {
super(message);
this.pd = pd;
}
- /**
- * Creates property exception with a cause.
- *
- * @param pd
- * The property definition associated with the property
- * that caused the exception.
- * @param message
- * The message.
- * @param cause
- * The cause.
- */
- protected PropertyException(PropertyDefinition<?> pd, Message message,
- Throwable cause) {
+ private PropertyException(PropertyDefinition<?> pd, Message message,
+ Throwable cause)
+ {
super(message, cause);
this.pd = pd;
}
@@ -85,13 +209,14 @@
/**
- * Get the property definition associated with the property that
- * caused the exception.
+ * Get 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 Returns the property definition associated with the property that
+ * caused the exception.
*/
- public final PropertyDefinition<?> getPropertyDefinition() {
+ public final PropertyDefinition<?> getPropertyDefinition()
+ {
return pd;
}
--
Gitblit v1.10.0