From f602b47990df4c70cd62e679702b013aca1c855c Mon Sep 17 00:00:00 2001
From: matthew_swift <matthew_swift@localhost>
Date: Tue, 17 Jul 2007 15:37:09 +0000
Subject: [PATCH] Fix issue 1923: dsconfig - provide better help when users attempt to reset a mandatory property.
---
opends/src/server/org/opends/server/messages/ToolMessages.java | 15 +++++++++++++++
opends/src/server/org/opends/server/tools/dsconfig/ArgumentExceptionFactory.java | 24 ++++++++++++++++++++++++
opends/src/server/org/opends/server/tools/dsconfig/SetPropSubCommandHandler.java | 12 ++++++++++++
3 files changed, 51 insertions(+), 0 deletions(-)
diff --git a/opends/src/server/org/opends/server/messages/ToolMessages.java b/opends/src/server/org/opends/server/messages/ToolMessages.java
index f1d57ae..40cd98d 100644
--- a/opends/src/server/org/opends/server/messages/ToolMessages.java
+++ b/opends/src/server/org/opends/server/messages/ToolMessages.java
@@ -9023,6 +9023,17 @@
public static final int MSGID_VERIFYINDEX_DESCRIPTION_COUNT_ERRORS =
CATEGORY_MASK_TOOLS | SEVERITY_MASK_INFORMATIONAL | 1199;
+ /**
+ * The message ID for the message that will be used if the user
+ * attempts to modify a property which is mandatory and which does
+ * not have any default values. This takes three arguments which are
+ * the name of the managed object, the name of the mandatory
+ * property, and the name of the option which should be used to give
+ * the property a new value.
+ */
+ public static final int MSGID_DSCFG_ERROR_UNABLE_TO_RESET_MANDATORY_PROPERTY =
+ CATEGORY_MASK_TOOLS | SEVERITY_MASK_SEVERE_ERROR | 1200;
+
/**
* Associates a set of generic messages with the message IDs defined in this
@@ -11415,6 +11426,10 @@
"The %s property \"%s\" is mandatory and must " +
"be specified");
+ registerMessage(MSGID_DSCFG_ERROR_UNABLE_TO_RESET_MANDATORY_PROPERTY,
+ "The %s property \"%s\" is mandatory cannot be reset. " +
+ "Use the \"%s\" option to specify a new value");
+
registerMessage(MSGID_DSCFG_ERROR_PROPERTY_SINGLE_VALUED,
"It is not possible to specify multiple values for the " +
"%s property \"%s\" as it is single-valued");
diff --git a/opends/src/server/org/opends/server/tools/dsconfig/ArgumentExceptionFactory.java b/opends/src/server/org/opends/server/tools/dsconfig/ArgumentExceptionFactory.java
index 52af844..db45bcc 100644
--- a/opends/src/server/org/opends/server/tools/dsconfig/ArgumentExceptionFactory.java
+++ b/opends/src/server/org/opends/server/tools/dsconfig/ArgumentExceptionFactory.java
@@ -293,6 +293,30 @@
/**
+ * Creates an argument exception which should be used when an
+ * attempt is made to reset a mandatory property that does not have
+ * any default values.
+ *
+ * @param d
+ * The managed object definition.
+ * @param name
+ * The name of the mandatory property.
+ * @param setOption
+ * The name of the option which should be used to set the
+ * property's values.
+ * @return Returns an argument exception.
+ */
+ public static ArgumentException unableToResetMandatoryProperty(
+ AbstractManagedObjectDefinition d, String name, String setOption) {
+ int msgID = MSGID_DSCFG_ERROR_UNABLE_TO_RESET_MANDATORY_PROPERTY;
+ String message = getMessage(msgID, d.getUserFriendlyPluralName(), name,
+ setOption);
+ return new ArgumentException(msgID, message);
+ }
+
+
+
+ /**
* Creates an argument exception which should be used when a
* property name is not recognized.
*
diff --git a/opends/src/server/org/opends/server/tools/dsconfig/SetPropSubCommandHandler.java b/opends/src/server/org/opends/server/tools/dsconfig/SetPropSubCommandHandler.java
index cf8ccc7..f489108 100644
--- a/opends/src/server/org/opends/server/tools/dsconfig/SetPropSubCommandHandler.java
+++ b/opends/src/server/org/opends/server/tools/dsconfig/SetPropSubCommandHandler.java
@@ -48,8 +48,10 @@
import org.opends.server.admin.OptionalRelationDefinition;
import org.opends.server.admin.PropertyDefinition;
import org.opends.server.admin.PropertyException;
+import org.opends.server.admin.PropertyOption;
import org.opends.server.admin.RelationDefinition;
import org.opends.server.admin.SingletonRelationDefinition;
+import org.opends.server.admin.UndefinedDefaultBehaviorProvider;
import org.opends.server.admin.client.AuthorizationException;
import org.opends.server.admin.client.CommunicationException;
import org.opends.server.admin.client.ConcurrentModificationException;
@@ -348,6 +350,16 @@
throw ArgumentExceptionFactory.unknownProperty(d, m);
}
+ // Mandatory properties which have no defined defaults cannot be
+ // reset.
+ if (pd.hasOption(PropertyOption.MANDATORY)) {
+ if (pd.getDefaultBehaviorProvider()
+ instanceof UndefinedDefaultBehaviorProvider) {
+ throw ArgumentExceptionFactory.unableToResetMandatoryProperty(d, m,
+ OPTION_DSCFG_LONG_SET);
+ }
+ }
+
// Save the modification type.
lastModTypes.put(m, ModificationType.SET);
--
Gitblit v1.10.0