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

matthew_swift
30.49.2007 4bb5ff428b255cafabf3613501196496acd9cb8c
Modify the HelpSubCommandHandler so that it is no longer a singleton. Being a singleton meant that multiple instances of dsconfig would share the same help sub-system and re-initialize it, potentially causing problems.
2 files modified
105 ■■■■■ changed files
opends/src/server/org/opends/server/tools/dsconfig/HelpSubCommandHandler.java 100 ●●●●● patch | view | raw | blame | history
opends/src/server/org/opends/server/tools/dsconfig/PropertyValueReader.java 5 ●●●●● patch | view | raw | blame | history
opends/src/server/org/opends/server/tools/dsconfig/HelpSubCommandHandler.java
@@ -392,67 +392,9 @@
   * @throws ArgumentException
   *           If the sub-command could not be created successfully.
   */
  public static synchronized HelpSubCommandHandler create(
      ConsoleApplication app, SubCommandArgumentParser parser)
      throws ArgumentException {
    if (INSTANCE == null) {
      INSTANCE = new HelpSubCommandHandler(app, parser);
    }
    return INSTANCE;
  }
  /**
   * Gets the application-wide help sub-command handler.
   *
   * @return Returns the application-wide help sub-command handler.
   */
  public static synchronized HelpSubCommandHandler getInstance() {
    if (INSTANCE == null) {
      throw new RuntimeException("Help sub-command handler not initialized");
    } else {
      return INSTANCE;
    }
  }
  // The singleton instance.
  private static HelpSubCommandHandler INSTANCE = null;
  // The sub-command associated with this handler.
  private final SubCommand subCommand;
  // The argument which should be used to specify the type of managed
  // object to be retrieved.
  private final StringArgument typeArgument;
  // A table listing all the available types of managed object.
  private final Map<String, AbstractManagedObjectDefinition<?, ?>> types;
  // Private constructor.
  private HelpSubCommandHandler(ConsoleApplication app,
  public static HelpSubCommandHandler create(ConsoleApplication app,
      SubCommandArgumentParser parser) throws ArgumentException {
    super(app);
    // Create the sub-command.
    String name = "list-properties";
    int descriptionID = MSGID_DSCFG_DESCRIPTION_SUBCMD_HELPPROP;
    this.subCommand = new SubCommand(parser, name, false, 0, 0, null,
        descriptionID);
    this.typeArgument = new StringArgument(OPTION_DSCFG_LONG_TYPE,
        OPTION_DSCFG_SHORT_TYPE, OPTION_DSCFG_LONG_TYPE, false, false, true,
        "{TYPE}", null, null, MSGID_DSCFG_DESCRIPTION_HELP_TYPE);
    this.subCommand.addArgument(this.typeArgument);
    // Register common arguments.
    registerAdvancedModeArgument(this.subCommand,
        MSGID_DSCFG_DESCRIPTION_ADVANCED_HELP);
    registerPropertyNameArgument(this.subCommand);
    this.types = new TreeMap<String, AbstractManagedObjectDefinition<?, ?>>();
    return new HelpSubCommandHandler(app, parser);
  }
@@ -468,7 +410,7 @@
   * @param out
   *          The output stream.
   */
  public void displayVerboseSingleProperty(
  public static void displayVerboseSingleProperty(
      AbstractManagedObjectDefinition<?, ?> d, String name, PrintStream out) {
    PropertyDefinition<?> pd = d.getPropertyDefinition(name);
@@ -573,6 +515,42 @@
  // The sub-command associated with this handler.
  private final SubCommand subCommand;
  // The argument which should be used to specify the type of managed
  // object to be retrieved.
  private final StringArgument typeArgument;
  // A table listing all the available types of managed object.
  private final Map<String, AbstractManagedObjectDefinition<?, ?>> types;
  // Private constructor.
  private HelpSubCommandHandler(ConsoleApplication app,
      SubCommandArgumentParser parser) throws ArgumentException {
    super(app);
    // Create the sub-command.
    String name = "list-properties";
    int descriptionID = MSGID_DSCFG_DESCRIPTION_SUBCMD_HELPPROP;
    this.subCommand = new SubCommand(parser, name, false, 0, 0, null,
        descriptionID);
    this.typeArgument = new StringArgument(OPTION_DSCFG_LONG_TYPE,
        OPTION_DSCFG_SHORT_TYPE, OPTION_DSCFG_LONG_TYPE, false, false, true,
        "{TYPE}", null, null, MSGID_DSCFG_DESCRIPTION_HELP_TYPE);
    this.subCommand.addArgument(this.typeArgument);
    // Register common arguments.
    registerAdvancedModeArgument(this.subCommand,
        MSGID_DSCFG_DESCRIPTION_ADVANCED_HELP);
    registerPropertyNameArgument(this.subCommand);
    this.types = new TreeMap<String, AbstractManagedObjectDefinition<?, ?>>();
  }
  /**
   * {@inheritDoc}
   */
opends/src/server/org/opends/server/tools/dsconfig/PropertyValueReader.java
@@ -99,10 +99,9 @@
     * {@inheritDoc}
     */
    public void display(ConsoleApplication app) {
      HelpSubCommandHandler help = HelpSubCommandHandler.getInstance();
      app.println();
      help.displayVerboseSingleProperty(mo.getManagedObjectDefinition(), pd
          .getName(), app.getErrorStream());
      HelpSubCommandHandler.displayVerboseSingleProperty(mo
          .getManagedObjectDefinition(), pd.getName(), app.getErrorStream());
    }
  }