From 9314d4add5ffbc40b21347539a0e503964dae207 Mon Sep 17 00:00:00 2001
From: Matthew Swift <matthew.swift@forgerock.com>
Date: Sat, 18 Jan 2014 00:58:42 +0000
Subject: [PATCH] Simplify config framework exception hierarchy by removing and pulling up the following exceptions:
---
opendj-sdk/opendj-config/src/main/java/org/forgerock/opendj/config/PropertyException.java | 137 ++++++++++++++++++++++++++++++++++++++-------
1 files changed, 114 insertions(+), 23 deletions(-)
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 a193030..59ce8cf 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
@@ -26,49 +26,140 @@
package org.forgerock.opendj.config;
+import static com.forgerock.opendj.ldap.AdminMessages.ERR_DEFAULT_BEHAVIOR_PROPERTY_EXCEPTION;
+import static com.forgerock.opendj.ldap.AdminMessages.ERR_ILLEGAL_PROPERTY_VALUE_EXCEPTION;
+import static com.forgerock.opendj.ldap.AdminMessages.ERR_PROPERTY_IS_MANDATORY_EXCEPTION;
+import static com.forgerock.opendj.ldap.AdminMessages.ERR_PROPERTY_IS_READ_ONLY_EXCEPTION;
+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.LocalizableMessage;
/**
* 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;
+ /**
+ * 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(final PropertyDefinition<?> pd,
+ final Throwable cause) {
+ return new PropertyException(pd, ERR_DEFAULT_BEHAVIOR_PROPERTY_EXCEPTION.get(pd.getName()),
+ cause);
+ }
+
+ /**
+ * Creates a new illegal property value exception.
+ *
+ * @param pd
+ * The property definition.
+ * @param value
+ * The illegal property value.
+ * @return A new illegal property value exception.
+ */
+ public static PropertyException illegalPropertyValueException(final PropertyDefinition<?> pd,
+ final 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(final PropertyDefinition<?> pd,
+ final Object value, final 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(final 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(final 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(final 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(
+ final PropertyDefinition<?> pd, final Object p) {
+ return new PropertyException(pd, ERR_UNKNOWN_PROPERTY_DEFINITION_EXCEPTION.get(
+ pd.getName(), pd.getClass().getName()));
+ }
+
+ // Create the message.
+ private static LocalizableMessage createMessage(final PropertyDefinition<?> pd,
+ final Object value) {
+ final 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;
- /**
- * Creates property exception without a cause.
- *
- * @param pd
- * The property definition associated with the property that
- * caused the exception.
- * @param message
- * The message.
- */
- protected PropertyException(PropertyDefinition<?> pd, LocalizableMessage message) {
+ private PropertyException(final PropertyDefinition<?> pd, final LocalizableMessage 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, LocalizableMessage message, Throwable cause) {
+ private PropertyException(final PropertyDefinition<?> pd, final LocalizableMessage message,
+ final Throwable cause) {
super(message, cause);
this.pd = pd;
}
--
Gitblit v1.10.0