| | |
| | | * This class provides a command-line tool which enables administrators to configure the Directory Server. |
| | | */ |
| | | public final class DSConfig extends ConsoleApplication { |
| | | |
| | | /** |
| | | * This class provides additional information about subcommands for generated reference documentation. |
| | | */ |
| | | private final class DSConfigSubCommandUsageHandler implements SubCommandUsageHandler { |
| | | |
| | | /** Marker to open a DocBook XML paragraph. */ |
| | | private String op = "<para>"; |
| | | |
| | | /** Marker to close a DocBook XML paragraph. */ |
| | | private String cp = "</para>"; |
| | | |
| | | /** {@inheritDoc} */ |
| | | @Override |
| | | public String getArgumentAdditionalInfo(SubCommand sc, Argument a, String nameOption) { |
| | | StringBuilder sb = new StringBuilder(); |
| | |
| | | return sb.toString(); |
| | | } |
| | | |
| | | private boolean isHidden(AbstractManagedObjectDefinition defn) { |
| | | private boolean isHidden(AbstractManagedObjectDefinition<?, ?> defn) { |
| | | return defn == null || defn.hasOption(ManagedObjectOption.HIDDEN); |
| | | } |
| | | |
| | |
| | | } |
| | | } |
| | | |
| | | /** {@inheritDoc} */ |
| | | @Override |
| | | public String getProperties(SubCommand sc) { |
| | | final AbstractManagedObjectDefinition<?, ?> defn = getManagedObjectDefinition(sc); |
| | |
| | | return defn == null || defn.hasOption(RelationOption.HIDDEN); |
| | | } |
| | | |
| | | |
| | | private List<AbstractManagedObjectDefinition<?, ?>> getLeafChildren( |
| | | AbstractManagedObjectDefinition<?, ?> defn) { |
| | | final ArrayList<AbstractManagedObjectDefinition<?, ?>> results = new ArrayList<>(); |
| | |
| | | } else if (defaultBehavior instanceof DefinedDefaultBehaviorProvider) { |
| | | DefinedDefaultBehaviorProvider<?> behavior = (DefinedDefaultBehaviorProvider<?>) defaultBehavior; |
| | | final Collection<String> defaultValues = behavior.getDefaultValues(); |
| | | if (defaultValues.size() == 0) { |
| | | if (defaultValues.isEmpty()) { |
| | | b.append(op).append(REF_DSCFG_DEFAULT_BEHAVIOR_NONE.get()).append(cp).append(EOL); |
| | | } else if (defaultValues.size() == 1) { |
| | | b.append(op).append(REF_DSCFG_DEFAULT_BEHAVIOR.get(defaultValues.iterator().next())) |
| | |
| | | |
| | | /** A menu call-back which runs a sub-command interactively. */ |
| | | private class SubCommandHandlerMenuCallback implements MenuCallback<Integer> { |
| | | |
| | | /** The sub-command handler. */ |
| | | private final SubCommandHandler handler; |
| | | |
| | |
| | | this.handler = handler; |
| | | } |
| | | |
| | | /** {@inheritDoc} */ |
| | | @Override |
| | | public MenuResult<Integer> invoke(ConsoleApplication app) throws ClientException { |
| | | try { |
| | |
| | | |
| | | /** The interactive mode sub-menu implementation. */ |
| | | private class SubMenuCallback implements MenuCallback<Integer> { |
| | | |
| | | /** The menu. */ |
| | | private final Menu<Integer> menu; |
| | | |
| | |
| | | : singularMsg.get(userFriendlyName); |
| | | } |
| | | |
| | | /** {@inheritDoc} */ |
| | | @Override |
| | | public final MenuResult<Integer> invoke(ConsoleApplication app) throws ClientException { |
| | | try { |
| | |
| | | return app.run(args); |
| | | } |
| | | |
| | | /** The argument which should be used to request advanced mode. */ |
| | | private BooleanArgument advancedModeArgument; |
| | | |
| | | /** |
| | | * The factory which the application should use to retrieve its management context. |
| | | */ |
| | | /** The factory which the application should use to retrieve its management context. */ |
| | | private LDAPManagementContextFactory factory; |
| | | |
| | | /** |
| | | * Flag indicating whether or not the global arguments have already been initialized. |
| | | */ |
| | | /** Flag indicating whether or not the global arguments have already been initialized. */ |
| | | private boolean globalArgumentsInitialized; |
| | | |
| | | /** The sub-command handler factory. */ |
| | | private SubCommandHandlerFactory handlerFactory; |
| | | |
| | | /** Mapping of sub-commands to their implementations. */ |
| | | private final Map<SubCommand, SubCommandHandler> handlers = new HashMap<>(); |
| | | |
| | | /** Indicates whether or not a sub-command was provided. */ |
| | | private boolean hasSubCommand = true; |
| | | |
| | | /** The command-line argument parser. */ |
| | | private final SubCommandArgumentParser parser; |
| | | |
| | | /** The argument which should be used to request advanced mode. */ |
| | | private BooleanArgument advancedModeArgument; |
| | | /** The argument which should be used to request non interactive behavior. */ |
| | | private BooleanArgument noPromptArgument; |
| | | /** The argument that the user must set to display the equivalent non-interactive mode argument. */ |
| | | private BooleanArgument displayEquivalentArgument; |
| | | /** The argument that allows the user to dump the equivalent non-interactive command to a file. */ |
| | | private StringArgument equivalentCommandFileArgument; |
| | | |
| | | /** The argument which should be used to request quiet output. */ |
| | | private BooleanArgument quietArgument; |
| | | /** The argument which should be used to request script-friendly output. */ |
| | | private BooleanArgument scriptFriendlyArgument; |
| | | /** The argument which should be used to request usage information. */ |
| | | private BooleanArgument showUsageArgument; |
| | | /** The argument which should be used to request verbose output. */ |
| | | private BooleanArgument verboseArgument; |
| | | |
| | | /** The argument which should be used to read dsconfig commands from standard input. */ |
| | | private BooleanArgument batchArgument; |
| | | /** The argument which should be used to read dsconfig commands from a file. */ |
| | | private StringArgument batchFileArgument; |
| | | |
| | | /** The argument which should be used to request non interactive behavior. */ |
| | | private BooleanArgument noPromptArgument; |
| | | |
| | | /** |
| | | * The argument that the user must set to display the equivalent non-interactive mode argument. |
| | | */ |
| | | private BooleanArgument displayEquivalentArgument; |
| | | |
| | | /** |
| | | * The argument that allows the user to dump the equivalent non-interactive command to a file. |
| | | */ |
| | | private StringArgument equivalentCommandFileArgument; |
| | | |
| | | /** The command-line argument parser. */ |
| | | private final SubCommandArgumentParser parser; |
| | | |
| | | /** The argument which should be used to request quiet output. */ |
| | | private BooleanArgument quietArgument; |
| | | |
| | | /** The argument which should be used to request script-friendly output. */ |
| | | private BooleanArgument scriptFriendlyArgument; |
| | | |
| | | /** The argument which should be used to request usage information. */ |
| | | private BooleanArgument showUsageArgument; |
| | | |
| | | /** The argument which should be used to request verbose output. */ |
| | | private BooleanArgument verboseArgument; |
| | | |
| | | /** The argument which should be used to indicate the properties file. */ |
| | | private StringArgument propertiesFileArgument; |
| | | |
| | | /** |
| | | * The argument which should be used to indicate that we will not look for properties file. |
| | | */ |
| | | /** The argument which should be used to indicate that we will not look for properties file. */ |
| | | private BooleanArgument noPropertiesFileArgument; |
| | | |
| | | /** |
| | |
| | | } |
| | | } |
| | | |
| | | /** {@inheritDoc} */ |
| | | @Override |
| | | public boolean isAdvancedMode() { |
| | | return advancedModeArgument.isPresent(); |
| | | } |
| | | |
| | | /** {@inheritDoc} */ |
| | | @Override |
| | | public boolean isInteractive() { |
| | | return !noPromptArgument.isPresent(); |
| | | } |
| | | |
| | | /** {@inheritDoc} */ |
| | | @Override |
| | | public boolean isMenuDrivenMode() { |
| | | return !hasSubCommand; |
| | | } |
| | | |
| | | /** {@inheritDoc} */ |
| | | @Override |
| | | public boolean isQuiet() { |
| | | return quietArgument.isPresent(); |
| | | } |
| | | |
| | | /** {@inheritDoc} */ |
| | | @Override |
| | | public boolean isScriptFriendly() { |
| | | return scriptFriendlyArgument.isPresent(); |
| | | } |
| | | |
| | | /** {@inheritDoc} */ |
| | | @Override |
| | | public boolean isVerbose() { |
| | | return verboseArgument.isPresent(); |
| | |
| | | */ |
| | | private void initializeGlobalArguments() throws ArgumentException { |
| | | if (!globalArgumentsInitialized) { |
| | | |
| | | verboseArgument = CommonArguments.getVerbose(); |
| | | quietArgument = CommonArguments.getQuiet(); |
| | | scriptFriendlyArgument = CommonArguments.getScriptFriendly(); |
| | |
| | | * problem during the configuration processing. |
| | | */ |
| | | private int run(String[] args) { |
| | | |
| | | // Register global arguments and sub-commands. |
| | | try { |
| | | initializeGlobalArguments(); |
| | |
| | | |
| | | /** Run the top-level interactive console. */ |
| | | private int runInteractiveMode() { |
| | | |
| | | ConsoleApplication app = this; |
| | | |
| | | // Build menu structure. |
| | |
| | | // "\ " support |
| | | command = command.replace("\\ ", "##"); |
| | | |
| | | |
| | | String displayCommand = command.replace("\\ ", " "); |
| | | errPrintln(LocalizableMessage.raw(displayCommand)); |
| | | |