mirror of https://github.com/OpenIdentityPlatform/OpenDJ.git

jvergara
04.13.2009 283a18593e644225e24b5463d1bf948d4cb3b706
Fix for issue 3968 (dsconfig --displayCommand does not provide valid value with duration and size syntaxes)
Use the property definition to retrieve the string representation of the attribute (instead of calling String.valueOf or doing some analysis of the class of the value).
3 files modified
77 ■■■■■ changed files
opendj-sdk/opends/src/server/org/opends/server/tools/dsconfig/CreateSubCommandHandler.java 19 ●●●● patch | view | raw | blame | history
opendj-sdk/opends/src/server/org/opends/server/tools/dsconfig/SetPropSubCommandHandler.java 27 ●●●●● patch | view | raw | blame | history
opendj-sdk/opends/src/server/org/opends/server/tools/dsconfig/SubCommandHandler.java 31 ●●●●● patch | view | raw | blame | history
opendj-sdk/opends/src/server/org/opends/server/tools/dsconfig/CreateSubCommandHandler.java
@@ -772,7 +772,7 @@
        app.printVerboseMessage(msg);
        if (handler != null) {
          for (PropertyEditorModification mod : editor.getModifications()) {
          for (PropertyEditorModification<?> mod : editor.getModifications()) {
            try {
              Argument arg = createArgument(mod);
              handler.getCommandBuilder().addArgument(arg);
@@ -1492,12 +1492,13 @@
   * @return the argument representing the modification.
   * @throws ArgumentException if there is a problem creating the argument.
   */
  private static Argument createArgument(PropertyEditorModification mod)
  private static <T> Argument createArgument(PropertyEditorModification<T> mod)
  throws ArgumentException
  {
    StringArgument arg;
    String propName = mod.getPropertyDefinition().getName();
    PropertyDefinition<T> propertyDefinition = mod.getPropertyDefinition();
    String propName = propertyDefinition.getName();
    switch (mod.getType())
    {
@@ -1506,9 +1507,9 @@
          OPTION_DSCFG_SHORT_SET, OPTION_DSCFG_LONG_SET, false, true, true,
          INFO_VALUE_SET_PLACEHOLDER.get(), null, null,
          INFO_DSCFG_DESCRIPTION_PROP_VAL.get());
      for (Object value : mod.getModificationValues())
      for (T value : mod.getModificationValues())
      {
        arg.addValue(propName+':'+getArgumentValue(value));
        arg.addValue(propName+':'+getArgumentValue(propertyDefinition, value));
      }
      break;
    case SET:
@@ -1516,9 +1517,9 @@
          OPTION_DSCFG_SHORT_SET, OPTION_DSCFG_LONG_SET, false, true, true,
          INFO_VALUE_SET_PLACEHOLDER.get(), null, null,
          INFO_DSCFG_DESCRIPTION_PROP_VAL.get());
      for (Object value : mod.getModificationValues())
      for (T value : mod.getModificationValues())
      {
        arg.addValue(propName+':'+getArgumentValue(value));
        arg.addValue(propName+':'+getArgumentValue(propertyDefinition, value));
      }
      break;
    case RESET:
@@ -1533,9 +1534,9 @@
          null, OPTION_DSCFG_LONG_REMOVE, false, true,
          true, INFO_VALUE_SET_PLACEHOLDER.get(), null, null,
          INFO_DSCFG_DESCRIPTION_REMOVE_PROP_VAL.get());
      for (Object value : mod.getModificationValues())
      for (T value : mod.getModificationValues())
      {
        arg.addValue(propName+':'+getArgumentValue(value));
        arg.addValue(propName+':'+getArgumentValue(propertyDefinition, value));
      }
      arg = null;
      break;
opendj-sdk/opends/src/server/org/opends/server/tools/dsconfig/SetPropSubCommandHandler.java
@@ -312,7 +312,7 @@
          Message msg = INFO_DSCFG_CONFIRM_MODIFY_SUCCESS.get(ufn);
          app.printVerboseMessage(msg);
          for (PropertyEditorModification mod : editor.getModifications())
          for (PropertyEditorModification<?> mod : editor.getModifications())
          {
            try
            {
@@ -476,8 +476,11 @@
                            OPTION_DSCFG_LONG_SET, false, true, true,
                            INFO_VALUE_SET_PLACEHOLDER.get(), null, null,
                            INFO_DSCFG_DESCRIPTION_PROP_VAL.get());
                        arg.addValue(cvc.getPropertyDefinition().getName()+':'+
                            getArgumentValue(cvc.getValue()));
                        PropertyDefinition<?> propertyDefinition =
                          cvc.getPropertyDefinition();
                        arg.addValue(propertyDefinition.getName()+':'+
                            castAndGetArgumentValue(propertyDefinition,
                                cvc.getValue()));
                        builder.addArgument(arg);
                      }
                      catch (Throwable t)
@@ -989,15 +992,17 @@
   * command-line) that is equivalent to the modification proposed by the user
   * in the provided PropertyEditorModification object.
   * @param mod the object describing the modification made.
   * @param <T> the type of the property to be retrieved.
   * @return the argument representing the modification.
   * @throws ArgumentException if there is a problem creating the argument.
   */
  private static Argument createArgument(PropertyEditorModification mod)
  private static <T> Argument createArgument(PropertyEditorModification<T> mod)
  throws ArgumentException
  {
    StringArgument arg;
    String propName = mod.getPropertyDefinition().getName();
    PropertyDefinition<T> propertyDefinition = mod.getPropertyDefinition();
    String propName = propertyDefinition.getName();
    switch (mod.getType())
    {
@@ -1013,9 +1018,9 @@
          OPTION_DSCFG_SHORT_REMOVE, OPTION_DSCFG_LONG_REMOVE, false, true,
          true, INFO_VALUE_SET_PLACEHOLDER.get(), null, null,
          INFO_DSCFG_DESCRIPTION_REMOVE_PROP_VAL.get());
      for (Object value : mod.getModificationValues())
      for (T value : mod.getModificationValues())
      {
        arg.addValue(propName+':'+getArgumentValue(value));
        arg.addValue(propName+':'+getArgumentValue(propertyDefinition, value));
      }
      break;
    case ADD:
@@ -1023,9 +1028,9 @@
          OPTION_DSCFG_SHORT_ADD, OPTION_DSCFG_LONG_ADD, false, true, true,
          INFO_VALUE_SET_PLACEHOLDER.get(), null, null,
          INFO_DSCFG_DESCRIPTION_ADD_PROP_VAL.get());
      for (Object value : mod.getModificationValues())
      for (T value : mod.getModificationValues())
      {
        arg.addValue(propName+':'+getArgumentValue(value));
        arg.addValue(propName+':'+getArgumentValue(propertyDefinition, value));
      }
      break;
    case SET:
@@ -1033,9 +1038,9 @@
          OPTION_DSCFG_SHORT_SET, OPTION_DSCFG_LONG_SET, false, true, true,
          INFO_VALUE_SET_PLACEHOLDER.get(), null, null,
          INFO_DSCFG_DESCRIPTION_PROP_VAL.get());
      for (Object value : mod.getModificationValues())
      for (T value : mod.getModificationValues())
      {
        arg.addValue(propName+':'+getArgumentValue(value));
        arg.addValue(propName+':'+getArgumentValue(propertyDefinition, value));
      }
      break;
    default:
opendj-sdk/opends/src/server/org/opends/server/tools/dsconfig/SubCommandHandler.java
@@ -72,7 +72,6 @@
import org.opends.server.admin.client.ManagedObjectDecodingException;
import org.opends.server.admin.client.ManagementContext;
import org.opends.server.tools.ClientException;
import org.opends.server.types.CommonSchemaElements;
import org.opends.server.util.ServerConstants;
import org.opends.server.util.args.Argument;
import org.opends.server.util.args.ArgumentException;
@@ -1399,24 +1398,36 @@
    }
  }
  /**
   * Returns the string value for a given object as it will be displayed
   * in the equivalent command-line.  The code will cast the provided object
   * using the property definition.
   * @param propertyDefinition the property definition.
   * @param o the value.
   * @param <T> the type of the property to be retrieved.
   * @return the String value to be displayed in the equivalent command-line.
   */
  protected static <T> String castAndGetArgumentValue(
      PropertyDefinition<T> propertyDefinition, Object o)
  {
    String value = propertyDefinition.encodeValue(
        propertyDefinition.castValue(o));
    return value;
  }
  /**
   * Returns the string value for a given object as it will be displayed
   * in the equivalent command-line.
   * @param propertyDefinition the property definition.
   * @param o the value.
   * @param <T> the type of the property to be retrieved.
   * @return the String value to be displayed in the equivalent command-line.
   */
  protected static String getArgumentValue(Object o)
  protected static <T> String getArgumentValue(
      PropertyDefinition<T> propertyDefinition, T o)
  {
    String value;
    if (o instanceof CommonSchemaElements)
    {
      value = ((CommonSchemaElements)o).getNameOrOID();
    }
    else
    {
      value = String.valueOf(o);
    }
    value = propertyDefinition.encodeValue(o);
    return value;
  }