From 8d73d4b84c10e52c5ee187fde05b4d238c3655a9 Mon Sep 17 00:00:00 2001
From: matthew_swift <matthew_swift@localhost>
Date: Wed, 19 Dec 2007 14:13:39 +0000
Subject: [PATCH] Fix issue 2451 part #1: https://opends.dev.java.net/issues/show_bug.cgi?id=2451

---
 opendj-sdk/opends/resource/admin/cliMOProfile.xsl                                    |    8 ++++
 opendj-sdk/opends/resource/admin/admin-cli.xsd                                       |   14 +++++++
 opendj-sdk/opends/src/server/org/opends/server/tools/dsconfig/SubCommandHandler.java |   14 ------
 opendj-sdk/opends/src/server/org/opends/server/tools/dsconfig/CLIProfile.java        |   36 +++++++++++++++++
 4 files changed, 58 insertions(+), 14 deletions(-)

diff --git a/opendj-sdk/opends/resource/admin/admin-cli.xsd b/opendj-sdk/opends/resource/admin/admin-cli.xsd
index ddf5363..f9f2d55 100644
--- a/opendj-sdk/opends/resource/admin/admin-cli.xsd
+++ b/opendj-sdk/opends/resource/admin/admin-cli.xsd
@@ -69,6 +69,20 @@
           </xsd:complexType>
         </xsd:element>
       </xsd:sequence>
+      <xsd:attribute name="naming-argument-override"
+        type="adm:name-type" use="optional">
+        <xsd:annotation>
+          <xsd:documentation>
+            A command-line argument name which should be used to
+            override the default argument name used to identify managed
+            objects referenced by this relation. By default the
+            command-line argument name is derived by taking the last
+            word in the relation name and appending "-name". For
+            example, the relation "certificate-mapper" becomes
+            "mapper-name".
+          </xsd:documentation>
+        </xsd:annotation>
+      </xsd:attribute>
     </xsd:complexType>
   </xsd:element>
 </xsd:schema>
diff --git a/opendj-sdk/opends/resource/admin/cliMOProfile.xsl b/opendj-sdk/opends/resource/admin/cliMOProfile.xsl
index d6a5310..70dcb10 100644
--- a/opendj-sdk/opends/resource/admin/cliMOProfile.xsl
+++ b/opendj-sdk/opends/resource/admin/cliMOProfile.xsl
@@ -52,6 +52,14 @@
     <xsl:for-each select="$this-all-relations">
       <xsl:sort select="@name" />
       <!--
+        Generate the naming argument override if present
+      -->
+      <xsl:value-of
+        select="concat('relation.', @name,
+                       '.naming-argument-override=',
+                       adm:profile[@name='cli']/cli:relation/@naming-argument-override,
+                       '&#xa;')" />
+      <!--
         Generate list of properties which should be displayed by default in list-xxx operations.
       -->
       <xsl:value-of
diff --git a/opendj-sdk/opends/src/server/org/opends/server/tools/dsconfig/CLIProfile.java b/opendj-sdk/opends/src/server/org/opends/server/tools/dsconfig/CLIProfile.java
index 86a9fe0..0ce6927 100644
--- a/opendj-sdk/opends/src/server/org/opends/server/tools/dsconfig/CLIProfile.java
+++ b/opendj-sdk/opends/src/server/org/opends/server/tools/dsconfig/CLIProfile.java
@@ -34,6 +34,7 @@
 import java.util.Set;
 
 import org.opends.server.admin.AbstractManagedObjectDefinition;
+import org.opends.server.admin.InstantiableRelationDefinition;
 import org.opends.server.admin.ManagedObjectDefinitionResource;
 import org.opends.server.admin.RelationDefinition;
 
@@ -42,7 +43,7 @@
 /**
  * This class is used to access CLI profile annotations.
  */
-class CLIProfile {
+final class CLIProfile {
 
   // The singleton instance.
   private static final CLIProfile INSTANCE = new CLIProfile();
@@ -88,6 +89,39 @@
 
 
   /**
+   * Gets the naming argument which should be used for a relation
+   * definition.
+   *
+   * @param r
+   *          The relation definition.
+   * @return Returns the naming argument which should be used for a
+   *         relation definition.
+   */
+  public String getNamingArgument(InstantiableRelationDefinition<?, ?> r) {
+    String s = resource.getString(r.getParentDefinition(),
+        "relation." + r.getName() + ".naming-argument-override").trim();
+
+    if (s.length() == 0) {
+      // Use the last word in the managed object name as the argument
+      // prefix.
+      StringBuilder builder = new StringBuilder();
+      s = r.getChildDefinition().getName();
+      int i = s.lastIndexOf('-');
+      if (i < 0 || i == (s.length() - 1)) {
+        builder.append(s);
+      } else {
+        builder.append(s.substring(i + 1));
+      }
+      builder.append("-name");
+      s = builder.toString();
+    }
+
+    return s;
+  }
+
+
+
+  /**
    * Determines if instances of the specified managed object
    * definition are to be used for customization.
    *
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 a749766..e93717a 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
@@ -455,19 +455,7 @@
         AbstractManagedObjectDefinition<C, S> d, String name) {
       sz--;
 
-      // Use the last word in the managed object name as the argument
-      // prefix.
-      StringBuilder builder = new StringBuilder();
-
-      String s = d.getName();
-      int i = s.lastIndexOf('-');
-      if (i < 0 || i == (s.length() - 1)) {
-        builder.append(s);
-      } else {
-        builder.append(s.substring(i + 1));
-      }
-      builder.append("-name");
-      String argName = builder.toString();
+      String argName = CLIProfile.getInstance().getNamingArgument(r);
       StringArgument arg;
 
       try {

--
Gitblit v1.10.0