From fe6545499558bb95484defd311ed83eced6aedf4 Mon Sep 17 00:00:00 2001
From: matthew_swift <matthew_swift@localhost>
Date: Thu, 19 Jul 2007 14:54:30 +0000
Subject: [PATCH] Fix issues 1943 (unable to create je-index), 1996 (exception when creating components with empty names), and 1998 (exception when creating components with blank names).
---
opendj-sdk/opends/src/server/org/opends/server/tools/dsconfig/SubCommandHandler.java | 72 ++++++++++++++++++++++++++++--------
1 files changed, 56 insertions(+), 16 deletions(-)
diff --git a/opendj-sdk/opends/src/server/org/opends/server/tools/dsconfig/SubCommandHandler.java b/opendj-sdk/opends/src/server/org/opends/server/tools/dsconfig/SubCommandHandler.java
index a393f3d..ad503d5 100644
--- a/opendj-sdk/opends/src/server/org/opends/server/tools/dsconfig/SubCommandHandler.java
+++ b/opendj-sdk/opends/src/server/org/opends/server/tools/dsconfig/SubCommandHandler.java
@@ -52,6 +52,8 @@
import org.opends.server.admin.ManagedObjectPath;
import org.opends.server.admin.ManagedObjectPathSerializer;
import org.opends.server.admin.OptionalRelationDefinition;
+import org.opends.server.admin.PropertyDefinition;
+import org.opends.server.admin.PropertyDefinitionUsageBuilder;
import org.opends.server.admin.SingletonRelationDefinition;
import org.opends.server.admin.SizeUnit;
import org.opends.server.admin.Tag;
@@ -344,14 +346,20 @@
* The sub-command.
* @param path
* The managed object path.
+ * @param isCreate
+ * Indicates whether the sub-command is a create-xxx
+ * sub-command, in which case the final path element will
+ * have different usage information.
* @return Returns the naming arguments.
* @throws ArgumentException
* If one or more naming arguments could not be
* registered.
*/
public static List<StringArgument> create(SubCommand subCommand,
- ManagedObjectPath<?, ?> path) throws ArgumentException {
- NamingArgumentBuilder builder = new NamingArgumentBuilder(subCommand);
+ ManagedObjectPath<?, ?> path, boolean isCreate)
+ throws ArgumentException {
+ NamingArgumentBuilder builder = new NamingArgumentBuilder(subCommand,
+ path.size(), isCreate);
path.serialize(builder);
if (builder.e != null) {
@@ -372,16 +380,22 @@
// The sub-command.
private final SubCommand subCommand;
+ // Indicates whether the sub-command is a create-xxx
+ // sub-command, in which case the final path element will
+ // have different usage information.
+ private final boolean isCreate;
+
+ // The number of path elements to expect.
+ private int sz;
- /**
- * Creates a new naming argument builder.
- *
- * @param subCommand
- * Add the naming arguments to this sub-command.
- */
- public NamingArgumentBuilder(SubCommand subCommand) {
+
+ // Private constructor.
+ private NamingArgumentBuilder(SubCommand subCommand, int sz,
+ boolean isCreate) {
this.subCommand = subCommand;
+ this.sz = sz;
+ this.isCreate = isCreate;
}
@@ -393,6 +407,8 @@
void appendManagedObjectPathElement(
InstantiableRelationDefinition<? super C, ? super S> r,
AbstractManagedObjectDefinition<C, S> d, String name) {
+ sz--;
+
// Use the last word in the managed object name as the argument
// prefix.
StringBuilder builder = new StringBuilder();
@@ -406,12 +422,32 @@
}
builder.append("-name");
String argName = builder.toString();
+ StringArgument arg;
try {
- StringArgument arg = new StringArgument(argName, null, argName, true,
- true, "{NAME}", MSGID_DSCFG_DESCRIPTION_NAME, d
- .getUserFriendlyName());
+ if (isCreate && sz == 0) {
+ // The final path element in create-xxx sub-commands should
+ // have a different usage.
+ PropertyDefinition<?> pd = r.getNamingPropertyDefinition();
+ if (pd != null) {
+ // Use syntax and description from naming property.
+ PropertyDefinitionUsageBuilder b =
+ new PropertyDefinitionUsageBuilder(false);
+ String usage = "{" + b.getUsage(pd) + "}";
+ arg = new StringArgument(argName, null, argName, true, true, usage,
+ MSGID_DSCFG_DESCRIPTION_NAME_CREATE_EXT, d
+ .getUserFriendlyName(), pd.getName(), pd.getSynopsis());
+ } else {
+ arg = new StringArgument(argName, null, argName, true, true,
+ "{NAME}", MSGID_DSCFG_DESCRIPTION_NAME_CREATE, d
+ .getUserFriendlyName());
+ }
+ } else {
+ // A normal naming argument.
+ arg = new StringArgument(argName, null, argName, true, true,
+ "{NAME}", MSGID_DSCFG_DESCRIPTION_NAME, d.getUserFriendlyName());
+ }
subCommand.addArgument(arg);
arguments.add(arg);
} catch (ArgumentException e) {
@@ -428,7 +464,7 @@
void appendManagedObjectPathElement(
OptionalRelationDefinition<? super C, ? super S> r,
AbstractManagedObjectDefinition<C, S> d) {
- // No implementation required.
+ sz--;
}
@@ -440,7 +476,7 @@
void appendManagedObjectPathElement(
SingletonRelationDefinition<? super C, ? super S> r,
AbstractManagedObjectDefinition<C, S> d) {
- // No implementation required.
+ sz--;
}
}
@@ -601,14 +637,18 @@
* The sub-command.
* @param p
* The managed object path.
+ * @param isCreate
+ * Indicates whether the sub-command is a create-xxx
+ * sub-command, in which case the final path element will
+ * have different usage information.
* @return Returns the naming arguments.
* @throws ArgumentException
* If one or more naming arguments could not be
* registered.
*/
protected final List<StringArgument> createNamingArgs(SubCommand subCommand,
- ManagedObjectPath<?, ?> p) throws ArgumentException {
- return NamingArgumentBuilder.create(subCommand, p);
+ ManagedObjectPath<?, ?> p, boolean isCreate) throws ArgumentException {
+ return NamingArgumentBuilder.create(subCommand, p, isCreate);
}
--
Gitblit v1.10.0