Package org.nasutekds.server.util.args

Examples of org.nasutekds.server.util.args.StringArgument


    registerServerSubCmd = new SubCommand(argParser,
        SubCommandNameEnum.REGISTER_SERVER.toString(),
        INFO_ADMIN_SUBCMD_REGISTER_SERVER_DESCRIPTION.get());
    subCommands.add(registerServerSubCmd);

    registerServerServerIdArg = new StringArgument("serverID", null,
        OPTION_LONG_SERVERID, false, true, INFO_SERVERID_PLACEHOLDER.get(),
        INFO_ADMIN_ARG_SERVERID_DESCRIPTION.get());
    registerServerSubCmd.addArgument(registerServerServerIdArg);

    registerServerSetArg = new StringArgument(OPTION_LONG_SET,
        OPTION_SHORT_SET, OPTION_LONG_SET, false, true, true,
        INFO_VALUE_SET_PLACEHOLDER.get(), null, null,
        INFO_DSCFG_DESCRIPTION_PROP_VAL.get());
    registerServerSubCmd.addArgument(registerServerSetArg);

    // unregister-server subcommand
    unregisterServerSubCmd = new SubCommand(argParser,
        SubCommandNameEnum.UNREGISTER_SERVER.toString(),
        INFO_ADMIN_SUBCMD_UNREGISTER_SERVER_DESCRIPTION.get());
    subCommands.add(unregisterServerSubCmd);

    unregisterServerServerIDArg = new StringArgument("serverID", null,
        OPTION_LONG_SERVERID, false, true, INFO_SERVERID_PLACEHOLDER.get(),
        INFO_ADMIN_ARG_SERVERID_DESCRIPTION.get());
    unregisterServerSubCmd.addArgument(unregisterServerServerIDArg);

    // list-servers subcommand
    listServersSubCmd = new SubCommand(argParser,
        SubCommandNameEnum.LIST_SERVERS.toString(),
        INFO_ADMIN_SUBCMD_LIST_SERVERS_DESCRIPTION.get());
    subCommands.add(listServersSubCmd);

    // get-server-properties subcommand
    getServerPropertiesSubCmd = new SubCommand(argParser,
        SubCommandNameEnum.GET_SERVER_PROPERTIES.toString(),
        INFO_ADMIN_SUBCMD_GET_SERVER_PROPERTIES_DESCRIPTION.get());
    subCommands.add(getServerPropertiesSubCmd);

    getServerPropertiesServerIdArg = new StringArgument("serverID", null,
        OPTION_LONG_SERVERID, false, true, INFO_SERVERID_PLACEHOLDER.get(),
        INFO_ADMIN_ARG_SERVERID_DESCRIPTION.get());
    getServerPropertiesServerIdArg.setMultiValued(true);
    getServerPropertiesSubCmd.addArgument(getServerPropertiesServerIdArg);


    // set-server-properties subcommand
    setServerPropertiesSubCmd = new SubCommand(argParser,
        SubCommandNameEnum.SET_SERVER_PROPERTIES.toString(),
        INFO_ADMIN_SUBCMD_SET_SERVER_PROPERTIES_DESCRIPTION.get());
    subCommands.add(setServerPropertiesSubCmd);

    setServerPropertiesServerIdArg = new StringArgument("serverID", null,
        OPTION_LONG_SERVERID, true, true, INFO_SERVERID_PLACEHOLDER.get(),
        INFO_ADMIN_ARG_SERVERID_DESCRIPTION.get());
    setServerPropertiesSubCmd.addArgument(setServerPropertiesServerIdArg);

    setServerPropertiesSetArg = new StringArgument(OPTION_LONG_SET,
        OPTION_SHORT_SET, OPTION_LONG_SET, false, true, true,
        INFO_VALUE_SET_PLACEHOLDER.get(), null, null,
        INFO_DSCFG_DESCRIPTION_PROP_VAL.get());
    setServerPropertiesSubCmd.addArgument(setServerPropertiesSetArg);


    // Create association between ADSContext enum and server
    // properties
    // Server properties are mapped to Argument.
    serverProperties = new HashMap<ServerProperty, Argument>();
    readonlyServerProperties = new HashSet<ServerProperty>();

    /**
     * The ID used to identify the server.
     */
    {
      ServerProperty prop = ServerProperty.ID;
      String attName = prop.getAttributeName();
      StringArgument arg = new StringArgument(attName, null,
          prop.getAttributeName(), false, false, true, Message.raw(""), null,
          null, null);
      serverProperties.put(prop, arg);
    }

    /**
     * The host name of the server.
     */
    {
      ServerProperty prop = ServerProperty.HOST_NAME;
      String attName = prop.getAttributeName();
      readonlyServerProperties.add(prop);
      StringArgument arg = new StringArgument(attName, null, attName, true,
          false, true, Message.raw(""), "localhost", null, null);
      serverProperties.put(prop, arg);
    }

    /**
     * The LDAP port of the server.
     */
    {
      ServerProperty prop = ServerProperty.LDAP_PORT;
      String attName = prop.getAttributeName();
      IntegerArgument arg = new IntegerArgument(attName, null, attName, true,
          true, true, Message.raw(attName), 389, null, null);
      serverProperties.put(prop, arg);
    }

    /**
     * The JMX port of the server.
     */
    {
      ServerProperty prop = ServerProperty.JMX_PORT;
      String attName = prop.getAttributeName();
      IntegerArgument arg = new IntegerArgument(attName, null, attName,
          false, true, Message.raw(attName), null);
      arg.setMultiValued(true);
      serverProperties.put(prop, arg);
    }

    /**
     * The JMX secure port of the server.
     */
    {
      ServerProperty prop = ServerProperty.JMXS_PORT;
      String attName = prop.getAttributeName();
      IntegerArgument arg = new IntegerArgument(attName, null, attName,
          false, true, Message.raw(attName), null);
      arg.setMultiValued(true);
      serverProperties.put(prop, arg);
    }

    /**
     * The LDAPS port of the server.
     */
    {
      ServerProperty prop = ServerProperty.LDAPS_PORT;
      String attName = prop.getAttributeName();
      IntegerArgument arg = new IntegerArgument(attName, null, attName,
          false, true, Message.raw(attName), null);
      arg.setMultiValued(true);
      serverProperties.put(prop, arg);
    }

    /**
     * The certificate used by the server.
     */
    {
      ServerProperty prop = ServerProperty.CERTIFICATE;
      String attName = prop.getAttributeName();
      StringArgument arg = new StringArgument(attName, null, attName, false,
          false, true, Message.raw(attName), null, null, null);
      serverProperties.put(prop, arg);
    }

    /**
     * The path where the server is installed.
     */
    {
      ServerProperty prop = ServerProperty.INSTANCE_PATH;
      String attName = prop.getAttributeName();
      StringArgument arg = new StringArgument(attName, null, attName, false,
          false, true, Message.raw(attName), null, null, null);
      serverProperties.put(prop, arg);
    }

    /**
     * The description of the server.
     */
    {
      ServerProperty prop = ServerProperty.DESCRIPTION;
      String attName = prop.getAttributeName();
      StringArgument arg = new StringArgument(attName, null, attName, false,
          false, true, Message.raw(attName), null, null, null);
      serverProperties.put(prop, arg);
    }

    /**
     * The OS of the machine where the server is installed.
     */
    {
      ServerProperty prop = ServerProperty.HOST_OS;
      String attName = prop.getAttributeName();
      StringArgument arg = new StringArgument(attName, null, attName, false,
          false, true, Message.raw(attName), null, null, null);
      serverProperties.put(prop, arg);
    }

    /**
     * Whether LDAP is enabled or not.
     */
    {
      ServerProperty prop = ServerProperty.LDAP_ENABLED;
      String attName = prop.getAttributeName();
      BooleanArgument arg = new BooleanArgument(attName, null, attName, null);
      arg.setDefaultValue("false");
      serverProperties.put(prop, arg);
    }

    /**
     * Whether LDAPS is enabled or not.
     */
    {
      ServerProperty prop = ServerProperty.LDAPS_ENABLED;
      String attName = prop.getAttributeName();
      BooleanArgument arg = new BooleanArgument(attName, null, attName, null);
      arg.setDefaultValue("false");
      serverProperties.put(prop, arg);
    }

    /**
     * Whether StartTLS is enabled or not.
     */
    {
      ServerProperty prop = ServerProperty.STARTTLS_ENABLED;
      String attName = prop.getAttributeName();
      BooleanArgument arg = new BooleanArgument(attName, null, attName, null);
      arg.setDefaultValue("false");
      serverProperties.put(prop, arg);
    }

    /**
     * Whether JMX is enabled or not.
     */
    {
      ServerProperty prop = ServerProperty.JMX_ENABLED;
      String attName = prop.getAttributeName();
      BooleanArgument arg = new BooleanArgument(attName, null, attName, null);
      arg.setDefaultValue("false");
      serverProperties.put(prop, arg);
    }

    /**
     * Whether JMXS is enabled or not.
     */
    {
      ServerProperty prop = ServerProperty.JMXS_ENABLED;
      String attName = prop.getAttributeName();
      BooleanArgument arg = new BooleanArgument(attName, null, attName, null);
      arg.setDefaultValue("false");
      serverProperties.put(prop, arg);
    }

    /**
     * The location of the server.
     */
    {
      ServerProperty prop = ServerProperty.LOCATION;
      String attName = prop.getAttributeName();
      StringArgument arg = new StringArgument(attName, null, attName, false,
          false, true, Message.raw(attName), null, null, null);
      serverProperties.put(prop, arg);
    }

    /**
     * The list of groups in which the server is registered.
     */
    {
      ServerProperty prop = ServerProperty.GROUPS;
      String attName = prop.getAttributeName();
      StringArgument arg = new StringArgument(attName, null, attName, false,
          true, true, Message.raw(attName), null, null, null);
      arg.setHidden(true);
      serverProperties.put(prop, arg);
    }

   /**
    * The INSTANCE_KEY_ID used to identify the server key ID.
    */
    {
      ServerProperty prop = ServerProperty.INSTANCE_KEY_ID;
      String attName = prop.getAttributeName();
      StringArgument arg = new StringArgument(attName, null, prop
          .getAttributeName(), false, false, true, Message.raw(""), null, null,
          null);
      serverProperties.put(prop, arg);
    }

    /**
     * The INSTANCE_PUBLIC_KEY_CERTIFICATE associated to the server.
     */
    {
      ServerProperty prop = ServerProperty.INSTANCE_PUBLIC_KEY_CERTIFICATE;
      String attName = prop.getAttributeName();
      StringArgument arg = new StringArgument(attName, null, prop
          .getAttributeName(), false, false, true, Message.raw(""), null, null,
          null);
      serverProperties.put(prop, arg);
    }
  }
View Full Code Here


    createGroupSubCmd = new SubCommand(argParser,
        SubCommandNameEnum.CREATE_GROUP.toString(),
        INFO_ADMIN_SUBCMD_CREATE_GROUP_DESCRIPTION.get());
    subCommands.add(createGroupSubCmd);

    createGroupDescriptionArg = new StringArgument("description",
        OPTION_SHORT_DESCRIPTION, OPTION_LONG_DESCRIPTION, false, false,
        true, INFO_DESCRIPTION_PLACEHOLDER.get(), "", null,
        INFO_ADMIN_ARG_DESCRIPTION_DESCRIPTION.get());
    createGroupSubCmd.addArgument(createGroupDescriptionArg);

    createGroupGroupNameArg = new StringArgument("groupName",
        OPTION_SHORT_GROUPNAME, OPTION_LONG_GROUPNAME, true, true,
        INFO_GROUPNAME_PLACEHOLDER.get(),
        INFO_ADMIN_ARG_CREATE_GROUP_GROUPNAME_DESCRIPTION.get());
    createGroupSubCmd.addArgument(createGroupGroupNameArg);

    // modify-group
    modifyGroupSubCmd = new SubCommand(argParser,
        SubCommandNameEnum.MODIFY_GROUP.toString(),
        INFO_ADMIN_SUBCMD_MODIFY_GROUP_DESCRIPTION.get());
    subCommands.add(modifyGroupSubCmd);

    modifyGroupDescriptionArg = new StringArgument("new-description",
        OPTION_SHORT_DESCRIPTION, OPTION_LONG_DESCRIPTION, false, false,
        true, INFO_DESCRIPTION_PLACEHOLDER.get(), "", null,
        INFO_ADMIN_ARG_NEW_DESCRIPTION_DESCRIPTION.get());
    modifyGroupSubCmd.addArgument(modifyGroupDescriptionArg);

    modifyGroupGroupIdArg = new StringArgument("new-groupName",
        OPTION_SHORT_NEWGROUPNAME, OPTION_LONG_NEWGROUPNAME, false, false, true,
        INFO_GROUPNAME_PLACEHOLDER.get(), "", null,
        INFO_ADMIN_ARG_NEW_GROUPNAME_DESCRIPTION.get());
    modifyGroupSubCmd.addArgument(modifyGroupGroupIdArg);

    modifyGroupGroupNameArg = new StringArgument("groupName",
        OPTION_SHORT_GROUPNAME, OPTION_LONG_GROUPNAME, true, true,
        INFO_GROUPNAME_PLACEHOLDER.get(),
        INFO_ADMIN_ARG_GROUPNAME_DESCRIPTION.get());
    modifyGroupSubCmd.addArgument(modifyGroupGroupNameArg);

    // delete-group
    deleteGroupSubCmd = new SubCommand(argParser,SubCommandNameEnum.DELETE_GROUP
        .toString(), INFO_ADMIN_SUBCMD_DELETE_GROUP_DESCRIPTION.get());
    subCommands.add(deleteGroupSubCmd);

    deleteGroupGroupNameArg = new StringArgument("groupName",
        OPTION_SHORT_GROUPNAME, OPTION_LONG_GROUPNAME, true, true,
        INFO_GROUPNAME_PLACEHOLDER.get(),
        INFO_ADMIN_ARG_GROUPNAME_DESCRIPTION.get());
    deleteGroupSubCmd.addArgument(deleteGroupGroupNameArg);

    // list-groups
    listGroupSubCmd = new SubCommand(argParser, "list-groups",
        INFO_ADMIN_SUBCMD_LIST_GROUPS_DESCRIPTION.get());
    subCommands.add(listGroupSubCmd);

    // add-to-group
    addToGroupSubCmd = new SubCommand(argParser,
        SubCommandNameEnum.ADD_TO_GROUP.toString(),
        INFO_ADMIN_SUBCMD_ADD_TO_GROUP_DESCRIPTION.get());
    subCommands.add(addToGroupSubCmd);

    addToGoupMemberNameArg = new StringArgument("memberName",
        OPTION_SHORT_MEMBERNAME, OPTION_LONG_MEMBERNAME, true, true,
        INFO_MEMBERNAME_PLACEHOLDER.get(),
        INFO_ADMIN_ARG_ADD_MEMBERNAME_DESCRIPTION.get());
    addToGroupSubCmd.addArgument(addToGoupMemberNameArg);

    addToGroupGroupNameArg = new StringArgument("groupName",
        OPTION_SHORT_GROUPNAME, OPTION_LONG_GROUPNAME, true, true,
        INFO_GROUPNAME_PLACEHOLDER.get(),
        INFO_ADMIN_ARG_GROUPNAME_DESCRIPTION.get());
    addToGroupSubCmd.addArgument(addToGroupGroupNameArg);

    // remove-from-group
    removeFromGroupSubCmd = new SubCommand(argParser,
        SubCommandNameEnum.REMOVE_FROM_GROUP.toString(),
        INFO_ADMIN_SUBCMD_REMOVE_FROM_GROUP_DESCRIPTION.get());
    subCommands.add(removeFromGroupSubCmd);

    removeFromGoupMemberNameArg = new StringArgument("memberName",
        OPTION_SHORT_MEMBERNAME, OPTION_LONG_MEMBERNAME, true, true,
        INFO_MEMBERNAME_PLACEHOLDER.get(),
        INFO_ADMIN_ARG_REMOVE_MEMBERNAME_DESCRIPTION.get());
    removeFromGroupSubCmd.addArgument(removeFromGoupMemberNameArg);

    removeFromGroupGroupNameArg = new StringArgument("groupName",
        OPTION_SHORT_GROUPNAME, OPTION_LONG_GROUPNAME, true, true,
        INFO_GROUPNAME_PLACEHOLDER.get(),
        INFO_ADMIN_ARG_GROUPNAME_DESCRIPTION.get());
    removeFromGroupSubCmd.addArgument(removeFromGroupGroupNameArg);


    // list-members
    listMembersSubCmd = new SubCommand(argParser,SubCommandNameEnum.LIST_MEMBERS
        .toString(), INFO_ADMIN_SUBCMD_LIST_MEMBERS_DESCRIPTION.get());
    subCommands.add(listMembersSubCmd);

    listMembersGroupNameArg = new StringArgument("groupName",
        OPTION_SHORT_GROUPNAME, OPTION_LONG_GROUPNAME, true, true,
        INFO_GROUPNAME_PLACEHOLDER.get(),
        INFO_ADMIN_ARG_GROUPNAME_DESCRIPTION.get());
    listMembersSubCmd.addArgument(listMembersGroupNameArg);

    // list-membership
    listMembershipSubCmd = new SubCommand(argParser,
        SubCommandNameEnum.LIST_MEMBERSHIP.toString(),
        INFO_ADMIN_SUBCMD_LIST_MEMBERSHIP_DESCRIPTION.get());
    subCommands.add(listMembershipSubCmd);

    listMembershipMemberNameArg = new StringArgument("memberName",
        OPTION_SHORT_MEMBERNAME, OPTION_LONG_MEMBERNAME, true, true,
        INFO_MEMBERNAME_PLACEHOLDER.get(),
        INFO_ADMIN_ARG_MEMBERNAME_DESCRIPTION.get());
    listMembershipSubCmd.addArgument(listMembershipMemberNameArg);
View Full Code Here

  }

  private static StringArgument getArgument(
      StringArgument argToClone, Collection<?> values)
  {
    StringArgument arg;
    try
    {
      arg = new StringArgument(argToClone.getName(),
          argToClone.getShortIdentifier(), argToClone.getLongIdentifier(),
          argToClone.isRequired(), argToClone.isMultiValued(),
          argToClone.needsValue(),
          argToClone.getValuePlaceholder(),
          argToClone.getDefaultValue(),
          argToClone.getPropertyName(),
          argToClone.getDescription());
    }
    catch (ArgumentException e)
    {
      // This is a bug.
      throw new RuntimeException("Unexpected error: "+e, e);
    }
    for (Object v : values)
    {
      arg.addValue(String.valueOf(v));
    }
    return arg;
  }
View Full Code Here

    BooleanArgument overwriteExisting;
    BooleanArgument showUsage;
    BooleanArgument singleValueChanges;
    BooleanArgument doCheckSchema;
    StringArgument  configClass;
    StringArgument  configFile;
    StringArgument  outputLDIF;
    StringArgument  sourceLDIF;
    StringArgument  targetLDIF;
    StringArgument  ignoreAttrsFile;
    StringArgument  ignoreEntriesFile;


    Message toolDescription = INFO_LDIFDIFF_TOOL_DESCRIPTION.get();
    ArgumentParser argParser = new ArgumentParser(CLASS_NAME, toolDescription,
                                                  false);
    try
    {
      sourceLDIF = new StringArgument(
              "sourceldif", 's', "sourceLDIF", true,
              false, true, INFO_FILE_PLACEHOLDER.get(), null, null,
              INFO_LDIFDIFF_DESCRIPTION_SOURCE_LDIF.get());
      argParser.addArgument(sourceLDIF);

      targetLDIF = new StringArgument(
              "targetldif", 't', "targetLDIF", true,
              false, true, INFO_FILE_PLACEHOLDER.get(), null, null,
              INFO_LDIFDIFF_DESCRIPTION_TARGET_LDIF.get());
      argParser.addArgument(targetLDIF);

      outputLDIF = new StringArgument(
              "outputldif", 'o', "outputLDIF", false,
              false, true, INFO_FILE_PLACEHOLDER.get(), null, null,
              INFO_LDIFDIFF_DESCRIPTION_OUTPUT_LDIF.get());
      argParser.addArgument(outputLDIF);

      ignoreAttrsFile = new StringArgument(
              "ignoreattrs", 'a', "ignoreAttrs", false,
              false, true, INFO_FILE_PLACEHOLDER.get(), null, null,
              INFO_LDIFDIFF_DESCRIPTION_IGNORE_ATTRS.get());
      argParser.addArgument(ignoreAttrsFile);

      ignoreEntriesFile = new StringArgument(
              "ignoreentries", 'e', "ignoreEntries", false,
              false, true, INFO_FILE_PLACEHOLDER.get(), null, null,
              INFO_LDIFDIFF_DESCRIPTION_IGNORE_ENTRIES.get());
      argParser.addArgument(ignoreEntriesFile);

      overwriteExisting =
           new BooleanArgument(
                   "overwriteexisting", 'O',
                   "overwriteExisting",
                   INFO_LDIFDIFF_DESCRIPTION_OVERWRITE_EXISTING.get());
      argParser.addArgument(overwriteExisting);

      singleValueChanges =
           new BooleanArgument(
                   "singlevaluechanges", 'S', "singleValueChanges",
                   INFO_LDIFDIFF_DESCRIPTION_SINGLE_VALUE_CHANGES.get());
      argParser.addArgument(singleValueChanges);

      doCheckSchema =
        new BooleanArgument(
                "checkschema", null, "checkSchema",
                INFO_LDIFDIFF_DESCRIPTION_CHECK_SCHEMA.get());
      argParser.addArgument(doCheckSchema);

      configFile = new StringArgument("configfile", 'c', "configFile", false,
                                      false, true,
                                      INFO_CONFIGFILE_PLACEHOLDER.get(), null,
                                      null,
                                      INFO_DESCRIPTION_CONFIG_FILE.get());
      configFile.setHidden(true);
      argParser.addArgument(configFile);

      configClass = new StringArgument("configclass", OPTION_SHORT_CONFIG_CLASS,
                             OPTION_LONG_CONFIG_CLASS, false,
                             false, true, INFO_CONFIGCLASS_PLACEHOLDER.get(),
                             ConfigFileHandler.class.getName(), null,
                             INFO_DESCRIPTION_CONFIG_CLASS.get());
      configClass.setHidden(true);
      argParser.addArgument(configClass);

      showUsage = new BooleanArgument("showusage", OPTION_SHORT_HELP,
                                      OPTION_LONG_HELP,
                                      INFO_DESCRIPTION_USAGE.get());
      argParser.addArgument(showUsage);
      argParser.setUsageArgument(showUsage);
    }
    catch (ArgumentException ae)
    {

      Message message = ERR_CANNOT_INITIALIZE_ARGS.get(ae.getMessage());
      err.println(message);
      return 1;
    }


    // Parse the command-line arguments provided to the program.
    try
    {
      argParser.parseArguments(args);
    }
    catch (ArgumentException ae)
    {

      Message message = ERR_ERROR_PARSING_ARGS.get(ae.getMessage());

      err.println(message);
      err.println(argParser.getUsage());
      return LDAPResultCode.CLIENT_SIDE_PARAM_ERROR;
    }


    // If we should just display usage or version information,
    // then print it and exit.
    if (argParser.usageOrVersionDisplayed())
    {
      return 0;
    }

    if (doCheckSchema.isPresent() && !configFile.isPresent())
    {
      String scriptName = System.getProperty(PROPERTY_SCRIPT_NAME);
      if (scriptName == null)
      {
        scriptName = "ldif-diff";
      }
      Message message = WARN_LDIFDIFF_NO_CONFIG_FILE.get(scriptName);
      err.println(message);
    }


    boolean checkSchema = configFile.isPresent() && doCheckSchema.isPresent();
    if (! serverInitialized)
    {
      // Bootstrap the Directory Server configuration for use as a client.
      DirectoryServer directoryServer = DirectoryServer.getInstance();
      DirectoryServer.bootstrapClient();


      // If we're to use the configuration then initialize it, along with the
      // schema.
      if (checkSchema)
      {
        try
        {
          DirectoryServer.initializeJMX();
        }
        catch (Exception e)
        {

          Message message = ERR_LDIFDIFF_CANNOT_INITIALIZE_JMX.get(
                  String.valueOf(configFile.getValue()),
                                      e.getMessage());
          err.println(message);
          return 1;
        }

        try
        {
          directoryServer.initializeConfiguration(configClass.getValue(),
                                                  configFile.getValue());
        }
        catch (Exception e)
        {
          Message message = ERR_LDIFDIFF_CANNOT_INITIALIZE_CONFIG.get(
                  String.valueOf(configFile.getValue()),
                                      e.getMessage());
          err.println(message);
          return 1;
        }

        try
        {
          directoryServer.initializeSchema();
        }
        catch (Exception e)
        {
          Message message = ERR_LDIFDIFF_CANNOT_INITIALIZE_SCHEMA.get(
                  String.valueOf(configFile.getValue()),
                  e.getMessage());
          err.println(message);
          return 1;
        }
      }
    }

    // Read in ignored entries and attributes if any
    BufferedReader ignReader = null;
    Collection<DN> ignoreEntries = new HashSet<DN>();
    Collection<String> ignoreAttrs   = new HashSet<String>();

    if (ignoreAttrsFile.getValue() != null)
    {
      try
      {
        ignReader = new BufferedReader(
          new FileReader(ignoreAttrsFile.getValue()));
        String line = null;
        while ((line = ignReader.readLine()) != null)
        {
          ignoreAttrs.add(line.toLowerCase());
        }
        ignReader.close();
      }
      catch (Exception e)
      {
        Message message = ERR_LDIFDIFF_CANNOT_READ_FILE_IGNORE_ATTRIBS.get(
                ignoreAttrsFile.getValue(),
                String.valueOf(e));
        err.println(message);
        return 1;
      }
      finally
      {
        try
        {
          ignReader.close();
        }
        catch (Exception e) {}
      }
    }

    if (ignoreEntriesFile.getValue() != null)
    {
      try
      {
        ignReader = new BufferedReader(
          new FileReader(ignoreEntriesFile.getValue()));
        String line = null;
        while ((line = ignReader.readLine()) != null)
        {
          try
          {
            DN dn = DN.decode(line);
            ignoreEntries.add(dn);
          }
          catch (DirectoryException e)
          {
            Message message = INFO_LDIFDIFF_CANNOT_PARSE_STRING_AS_DN.get(
                    line, ignoreEntriesFile.getValue());
            err.println(message);
          }
        }
        ignReader.close();
      }
      catch (Exception e)
      {
        Message message = ERR_LDIFDIFF_CANNOT_READ_FILE_IGNORE_ENTRIES.get(
                ignoreEntriesFile.getValue(),
                String.valueOf(e));
        err.println(message);
        return 1;
      }
      finally
View Full Code Here

        OPTION_LONG_QUIET,
        INFO_JAVAPROPERTIES_DESCRIPTION_SILENT.get());
    quietArg.setPropertyName(OPTION_LONG_QUIET);
    addArgument(quietArg);

    propertiesFileArg = new StringArgument("propertiesFile",
        'p', "propertiesFile", false,
        false, true, INFO_PATH_PLACEHOLDER.get(), getDefaultPropertiesValue(),
        "propertiesFile",
        INFO_JAVAPROPERTIES_DESCRIPTION_PROPERTIES_FILE.get(
            getDefaultPropertiesValue()));
    propertiesFileArg.setHidden(true);
    addArgument(propertiesFileArg);

    destinationFileArg = new StringArgument("destinationFile",
        'd', "destinationFile", false,
        false, true, INFO_PATH_PLACEHOLDER.get(), getDefaultDestinationValue(),
        "destinationFile",
        INFO_JAVAPROPERTIES_DESCRIPTION_DESTINATION_FILE.get(
            getDefaultDestinationValue()));
View Full Code Here

    ArgumentGroup taskGroup = new ArgumentGroup(
      INFO_DESCRIPTION_TASK_TASK_ARGS.get(), 1000);

    try {
      StringArgument propertiesFileArgument = new StringArgument(
        "propertiesFilePath",
        null, OPTION_LONG_PROP_FILE_PATH,
        false, false, true, INFO_PROP_FILE_PATH_PLACEHOLDER.get(), null, null,
        INFO_DESCRIPTION_PROP_FILE_PATH.get());
      argParser.addArgument(propertiesFileArgument);
View Full Code Here

  private int mainWait(String[] args)
  {
    // Create all of the command-line arguments for this program.
    BooleanArgument showUsage      = null;
    IntegerArgument timeout        = null;
    StringArgument  logFilePath    = null;
    StringArgument  targetFilePath = null;
    StringArgument  outputFilePath = null;
    BooleanArgument useLastKnownGoodConfig = null;
    BooleanArgument quietMode              = null;

    Message toolDescription = INFO_WAIT4DEL_TOOL_DESCRIPTION.get();
    ArgumentParser argParser = new ArgumentParser(CLASS_NAME, toolDescription,
                                                  false);

    try
    {
      targetFilePath =
           new StringArgument("targetfile", 'f', "targetFile", true, false,
                              true, INFO_PATH_PLACEHOLDER.get(), null, null,
                              INFO_WAIT4DEL_DESCRIPTION_TARGET_FILE.get());
      argParser.addArgument(targetFilePath);


      logFilePath = new StringArgument(
              "logfile", 'l', "logFile", false, false,
              true, INFO_PATH_PLACEHOLDER.get(), null, null,
              INFO_WAIT4DEL_DESCRIPTION_LOG_FILE.get());
      argParser.addArgument(logFilePath);


      outputFilePath = new StringArgument(
              "outputfile", 'o', "outputFile",
              false, false,
              true, INFO_PATH_PLACEHOLDER.get(), null, null,
              INFO_WAIT4DEL_DESCRIPTION_OUTPUT_FILE.get());
      argParser.addArgument(outputFilePath);


      timeout = new IntegerArgument("timeout", 't', "timeout", true, false,
                                    true, INFO_SECONDS_PLACEHOLDER.get(),
                                    DirectoryServer.DEFAULT_TIMEOUT,
                                    null, true, 0, false,
                                    0, INFO_WAIT4DEL_DESCRIPTION_TIMEOUT.get());
      argParser.addArgument(timeout);


      // Not used in this class, but required by the start-ds script
      // (see issue #3814)
      useLastKnownGoodConfig =
           new BooleanArgument("lastknowngoodconfig", 'L',
                               "useLastKnownGoodConfig",
                               INFO_DSCORE_DESCRIPTION_LASTKNOWNGOODCFG.get());
      argParser.addArgument(useLastKnownGoodConfig);

      // Not used in this class, but required by the start-ds script
      // (see issue #3814)
      quietMode = new BooleanArgument("quiet", 'Q', "quiet",
                                      INFO_DESCRIPTION_QUIET.get());
      argParser.addArgument(quietMode);

      showUsage = new BooleanArgument("help", 'H', "help",
                                      INFO_WAIT4DEL_DESCRIPTION_HELP.get());
      argParser.addArgument(showUsage);
      argParser.setUsageArgument(showUsage);
    }
    catch (ArgumentException ae)
    {
      Message message = ERR_CANNOT_INITIALIZE_ARGS.get(ae.getMessage());
      println(message);
      return EXIT_CODE_INTERNAL_ERROR;
    }


    // Parse the command-line arguments provided to the program.
    try
    {
      argParser.parseArguments(args);
    }
    catch (ArgumentException ae)
    {
      Message message = ERR_ERROR_PARSING_ARGS.get(ae.getMessage());

      println(message);
      println(Message.raw(argParser.getUsage()));
      return EXIT_CODE_INTERNAL_ERROR;
    }


    // If we should just display usage or version information,
    // then print it and exit.
    if (argParser.usageOrVersionDisplayed())
    {
      return EXIT_CODE_SUCCESS;
    }


    // Get the file to watch.  If it doesn't exist now, then exit immediately.
    File targetFile = new File(targetFilePath.getValue());
    if (! targetFile.exists())
    {
      return EXIT_CODE_SUCCESS;
    }


    // If a log file was specified, then open it.
    long logFileOffset = 0L;
    RandomAccessFile logFile = null;
    if (logFilePath.isPresent())
    {
      try
      {
        File f = new File(logFilePath.getValue());
        if (f.exists())
        {
          logFile = new RandomAccessFile(f, "r");
          logFileOffset = logFile.length();
          logFile.seek(logFileOffset);
        }
      }
      catch (Exception e)
      {
        Message message = WARN_WAIT4DEL_CANNOT_OPEN_LOG_FILE.get(
                logFilePath.getValue(), String.valueOf(e));
        println(message);

        logFile = null;
      }
    }


    // If an output file was specified and we could open the log file, open it
    // and append data to it.
    RandomAccessFile outputFile = null;
    long outputFileOffset = 0L;
    if (logFile != null)
    {
      if (outputFilePath.isPresent())
      {
        try
        {
          File f = new File(outputFilePath.getValue());
          if (f.exists())
          {
            outputFile = new RandomAccessFile(f, "rw");
            outputFileOffset = outputFile.length();
            outputFile.seek(outputFileOffset);
          }
        }
        catch (Exception e)
        {
          Message message = WARN_WAIT4DEL_CANNOT_OPEN_OUTPUT_FILE.get(
                  outputFilePath.getValue(), String.valueOf(e));
          println(message);

          outputFile = null;
        }
      }
View Full Code Here

        's',
        "script-friendly",
        INFO_DESCRIPTION_SCRIPT_FRIENDLY.get());
    defaultArgs.add(1, scriptFriendlyArg);

    StringArgument propertiesFileArgument = new StringArgument(
        "propertiesFilePath", null, OPTION_LONG_PROP_FILE_PATH, false, false,
        true, INFO_PROP_FILE_PATH_PLACEHOLDER.get(), null, null,
        INFO_DESCRIPTION_PROP_FILE_PATH.get());
    defaultArgs.add(propertiesFileArgument);
    setFilePropertiesArgument(propertiesFileArgument);
View Full Code Here

    // Remove it from the default location and redefine it.
    defaultArgs.remove(secureArgsList.adminUidArg);

    int index = 0;

    baseDNsArg = new StringArgument("baseDNs", OPTION_SHORT_BASEDN,
        OPTION_LONG_BASEDN, false, true, true, INFO_BASEDN_PLACEHOLDER.get(),
        null,
        null, INFO_DESCRIPTION_REPLICATION_BASEDNS.get());
    baseDNsArg.setPropertyName(OPTION_LONG_BASEDN);
    defaultArgs.add(index++, baseDNsArg);

    secureArgsList.adminUidArg = new StringArgument("adminUID", 'I',
        OPTION_LONG_ADMIN_UID, false, false, true,
        INFO_ADMINUID_PLACEHOLDER.get(),
        Constants.GLOBAL_ADMIN_UID, null,
        INFO_DESCRIPTION_REPLICATION_ADMIN_UID.get(
            ENABLE_REPLICATION_SUBCMD_NAME));
    secureArgsList.adminUidArg.setPropertyName(OPTION_LONG_ADMIN_UID);
    secureArgsList.adminUidArg.setHidden(false);
    defaultArgs.add(index++, secureArgsList.adminUidArg);

    secureArgsList.bindPasswordArg = new StringArgument(
        OPTION_LONG_ADMIN_PWD.toLowerCase(),
        OPTION_SHORT_BINDPWD, OPTION_LONG_ADMIN_PWD, false, false, true,
        INFO_BINDPWD_PLACEHOLDER.get(), null, null,
        INFO_DESCRIPTION_REPLICATION_ADMIN_BINDPASSWORD.get());
    defaultArgs.add(index++, secureArgsList.bindPasswordArg);

    secureArgsList.bindPasswordFileArg = new FileBasedArgument(
        OPTION_LONG_ADMIN_PWD_FILE.toLowerCase(),
        OPTION_SHORT_BINDPWD_FILE, OPTION_LONG_ADMIN_PWD_FILE, false, false,
        INFO_BINDPWD_FILE_PLACEHOLDER.get(), null, null,
        INFO_DESCRIPTION_REPLICATION_ADMIN_BINDPASSWORDFILE.get());
    defaultArgs.add(index++, secureArgsList.bindPasswordFileArg);

    defaultArgs.remove(verboseArg);

    quietArg = new BooleanArgument(
        OPTION_LONG_QUIET,
        OPTION_SHORT_QUIET,
        OPTION_LONG_QUIET,
        INFO_REPLICATION_DESCRIPTION_QUIET.get());
    defaultArgs.add(index++, quietArg);

    noPromptArg = new BooleanArgument(
        OPTION_LONG_NO_PROMPT,
        OPTION_SHORT_NO_PROMPT,
        OPTION_LONG_NO_PROMPT,
        INFO_DESCRIPTION_NO_PROMPT.get());
    defaultArgs.add(index++, noPromptArg);

    displayEquivalentArgument = new BooleanArgument(
        OPTION_DSCFG_LONG_DISPLAY_EQUIVALENT,
        null, OPTION_DSCFG_LONG_DISPLAY_EQUIVALENT,
        INFO_REPLICATION_DESCRIPTION_DISPLAY_EQUIVALENT.get());
    defaultArgs.add(index++, displayEquivalentArgument);

    equivalentCommandFileArgument = new StringArgument(
        OPTION_LONG_EQUIVALENT_COMMAND_FILE_PATH, null,
        OPTION_LONG_EQUIVALENT_COMMAND_FILE_PATH, false, false, true,
        INFO_PATH_PLACEHOLDER.get(), null, null,
        INFO_REPLICATION_DESCRIPTION_EQUIVALENT_COMMAND_FILE_PATH.get());
    defaultArgs.add(index++, equivalentCommandFileArgument);

    advancedArg = new BooleanArgument(OPTION_DSCFG_LONG_ADVANCED,
        OPTION_DSCFG_SHORT_ADVANCED,
        OPTION_DSCFG_LONG_ADVANCED,
        INFO_REPLICATION_DESCRIPTION_ADVANCED.get());
    defaultArgs.add(index++, advancedArg);

    configClassArg =
      new StringArgument("configclass", OPTION_SHORT_CONFIG_CLASS,
                         OPTION_LONG_CONFIG_CLASS, true, false,
                         true, INFO_CONFIGCLASS_PLACEHOLDER.get(),
                         ConfigFileHandler.class.getName(), null,
                         INFO_DESCRIPTION_CONFIG_CLASS.get());
    configClassArg.setHidden(true);
    defaultArgs.add(index++, configClassArg);

    configFileArg =
      new StringArgument("configfile", 'f', "configFile", true, false,
                         true, INFO_CONFIGFILE_PLACEHOLDER.get(), null,
                         null,
                         INFO_DESCRIPTION_CONFIG_FILE.get());
    configFileArg.setHidden(true);
    defaultArgs.add(index++, configFileArg);

    for (int i=0; i<index; i++)
    {
      Argument arg = defaultArgs.get(i);
      arg.setPropertyName(arg.getLongIdentifier());
    }

    this.propertiesFileArgument = new StringArgument(
        "propertiesFilePath", null, OPTION_LONG_PROP_FILE_PATH, false, false,
        true, INFO_PROP_FILE_PATH_PLACEHOLDER.get(), null, null,
        INFO_DESCRIPTION_PROP_FILE_PATH.get());
    defaultArgs.add(this.propertiesFileArgument);
    setFilePropertiesArgument(this.propertiesFileArgument);
View Full Code Here

   */
  private void createEnableReplicationSubCommand()
  throws ArgumentException
  {

    hostName1Arg = new StringArgument("host1", OPTION_SHORT_HOST,
        "host1", false, false, true, INFO_HOST_PLACEHOLDER.get(),
        getDefaultHostValue(),
        null, INFO_DESCRIPTION_ENABLE_REPLICATION_HOST1.get());

    port1Arg = new IntegerArgument("port1", OPTION_SHORT_PORT, "port1",
        false, false, true, INFO_PORT_PLACEHOLDER.get(),
        defaultAdminPort, null,
        true, 1,
        true, 65336,
        INFO_DESCRIPTION_ENABLE_REPLICATION_SERVER_PORT1.get());

    bindDn1Arg = new StringArgument("bindDN1", OPTION_SHORT_BINDDN,
        "bindDN1", false, false, true, INFO_BINDDN_PLACEHOLDER.get(),
        "cn=Directory Manager", null,
        INFO_DESCRIPTION_ENABLE_REPLICATION_BINDDN1.get());

    bindPassword1Arg = new StringArgument("bindPassword1",
        null, "bindPassword1", false, false, true,
        INFO_BINDPWD_PLACEHOLDER.get(), null, null,
        INFO_DESCRIPTION_ENABLE_REPLICATION_BINDPASSWORD1.get());

    bindPasswordFile1Arg = new FileBasedArgument("bindPasswordFile1",
        null, "bindPasswordFile1", false, false,
        INFO_BINDPWD_FILE_PLACEHOLDER.get(), null, null,
        INFO_DESCRIPTION_ENABLE_REPLICATION_BINDPASSWORDFILE1.get());

    replicationPort1Arg = new IntegerArgument("replicationPort1", 'r',
        "replicationPort1", false, false, true, INFO_PORT_PLACEHOLDER.get(),
        8989, null,
        true, 1,
        true, 65336,
        INFO_DESCRIPTION_ENABLE_REPLICATION_PORT1.get());

    secureReplication1Arg = new BooleanArgument("secureReplication1", null,
        "secureReplication1",
        INFO_DESCRIPTION_ENABLE_SECURE_REPLICATION1.get());

    noReplicationServer1Arg = new BooleanArgument(
        "noreplicationserver1", null, "noReplicationServer1",
        INFO_DESCRIPTION_ENABLE_REPLICATION_NO_REPLICATION_SERVER1.get());

    onlyReplicationServer1Arg = new BooleanArgument(
        "onlyreplicationserver1", null, "onlyReplicationServer1",
        INFO_DESCRIPTION_ENABLE_REPLICATION_ONLY_REPLICATION_SERVER1.get());

    hostName2Arg = new StringArgument("host2", 'O',
        "host2", false, false, true, INFO_HOST_PLACEHOLDER.get(),
        getDefaultHostValue(),
        null, INFO_DESCRIPTION_ENABLE_REPLICATION_HOST2.get());

    port2Arg = new IntegerArgument("port2", null, "port2",
        false, false, true, INFO_PORT_PLACEHOLDER.get(), defaultAdminPort, null,
        true, 1,
        true, 65336,
        INFO_DESCRIPTION_ENABLE_REPLICATION_SERVER_PORT2.get());

    bindDn2Arg = new StringArgument("bindDN2", null,
        "bindDN2", false, false, true, INFO_BINDDN_PLACEHOLDER.get(),
        "cn=Directory Manager", null,
        INFO_DESCRIPTION_ENABLE_REPLICATION_BINDDN2.get());

    bindPassword2Arg = new StringArgument("bindPassword2",
        null, "bindPassword2", false, false, true,
        INFO_BINDPWD_PLACEHOLDER.get(), null, null,
        INFO_DESCRIPTION_ENABLE_REPLICATION_BINDPASSWORD2.get());

    bindPasswordFile2Arg = new FileBasedArgument("bindPasswordFile2",
View Full Code Here

TOP

Related Classes of org.nasutekds.server.util.args.StringArgument

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.