DSConfig.java revision cddd676de138668ef547099bba407d8b302a1507
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (the "License"). You may not use this file except in compliance
* with the License.
*
* You can obtain a copy of the license at
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at
* trunk/opends/resource/legal-notices/OpenDS.LICENSE. If applicable,
* add the following below this CDDL HEADER, with the fields enclosed
* by brackets "[]" replaced with your own identifying information:
* Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*
*
* Portions Copyright 2007 Sun Microsystems, Inc.
*/
/**
* This class provides a command-line tool which enables
* administrators to configure the Directory Server.
*/
public final class DSConfig extends ConsoleApplication {
/**
* A menu call-back which runs a sub-command interactively.
*/
// The sub-command handler.
private final SubCommandHandler handler;
/**
* Creates a new sub-command handler call-back.
*
* @param handler
* The sub-command handler.
*/
}
/**
* {@inheritDoc}
*/
throws CLIException {
try {
return result;
} else {
// Success or cancel.
return MenuResult.again();
}
} catch (ArgumentException e) {
} catch (ClientException e) {
}
}
}
/**
* The interactive mode sub-menu implementation.
*/
// The menu.
/**
* Creates a new sub-menu implementation.
*
* @param app
* The console application.
* @param rd
* The relation definition.
* @param ch
* The optional create sub-command.
* @param dh
* The optional delete sub-command.
* @param lh
* The optional list sub-command.
* @param sh
* The option set-prop sub-command.
*/
if (rd instanceof InstantiableRelationDefinition) {
InstantiableRelationDefinition<?, ?> ir =
(InstantiableRelationDefinition<?, ?>) rd;
}
} else {
}
}
}
} else {
callback);
}
}
}
builder.addBackOption(true);
}
/**
* {@inheritDoc}
*/
throws CLIException {
try {
return MenuResult.again();
}
return result;
} catch (CLIException e) {
}
}
}
/**
* The value for the long option advanced.
*/
/**
* The value for the short option advanced.
*/
/**
* The tracer object for the debug logger.
*/
/**
* Provides the command-line arguments to the main application for
* processing.
*
* @param args
* The set of command-line arguments provided to this
* program.
*/
if (exitCode != 0) {
}
}
/**
* Provides the command-line arguments to the main application for
* processing and returns the exit code as an integer.
*
* @param args
* The set of command-line arguments provided to this
* program.
* @param initializeServer
* Indicates whether to perform basic initialization (which
* should not be done if the tool is running in the same
* JVM as the server).
* @param outStream
* The output stream for standard output.
* @param errStream
* The output stream for standard error.
* @return Zero to indicate that the program completed successfully,
* or non-zero to indicate that an error occurred.
*/
new LDAPManagementContextFactory());
// Only initialize the client environment when run as a standalone
// application.
if (initializeServer) {
try {
} catch (InitializationException e) {
// TODO: is this ok as an error message?
return 1;
}
}
// Run the application.
}
// The argument which should be used to request advanced mode.
private BooleanArgument advancedModeArgument;
// Flag indicating whether or not the application environment has
// already been initialized.
private boolean environmentInitialized = false;
// The factory which the application should use to retrieve its
// management context.
private final ManagementContextFactory factory;
// Flag indicating whether or not the global arguments have
// already been initialized.
private boolean globalArgumentsInitialized = false;
// The sub-command handler factory.
// Mapping of sub-commands to their implementations;
// Indicates whether or not a sub-command was provided.
private boolean hasSubCommand = true;
// The argument which should be used to request non interactive
// behavior.
private BooleanArgument noPromptArgument;
// 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.
private BooleanArgument noPropertiesFileArgument;
/**
* Creates a new dsconfig application instance.
*
* @param in
* The application input stream.
* @param out
* The application output stream.
* @param err
* The application error stream.
* @param factory
* The factory which this application instance should use
* for obtaining management contexts.
*/
INFO_CONFIGDS_TOOL_DESCRIPTION.get(), false);
}
/**
* Initializes core APIs for use when dsconfig will be run as a
* standalone application.
*
* @throws InitializationException
* If the core APIs could not be initialized.
*/
private void initializeClientEnvironment() throws InitializationException {
if (environmentInitialized == false) {
// Bootstrap definition classes.
// Switch off class name validation in client.
// Switch off attribute type name validation in client.
environmentInitialized = true;
}
}
/**
* {@inheritDoc}
*/
public boolean isAdvancedMode() {
return advancedModeArgument.isPresent();
}
/**
* {@inheritDoc}
*/
public boolean isInteractive() {
return !noPromptArgument.isPresent();
}
/**
* {@inheritDoc}
*/
public boolean isMenuDrivenMode() {
return !hasSubCommand;
}
/**
* {@inheritDoc}
*/
public boolean isQuiet() {
return quietArgument.isPresent();
}
/**
* {@inheritDoc}
*/
public boolean isScriptFriendly() {
return scriptFriendlyArgument.isPresent();
}
/**
* {@inheritDoc}
*/
public boolean isVerbose() {
return verboseArgument.isPresent();
}
// Displays the provided message followed by a help usage reference.
println();
}
/**
* Registers the global arguments with the argument parser.
*
* @throws ArgumentException
* If a global argument could not be registered.
*/
private void initializeGlobalArguments() throws ArgumentException {
if (globalArgumentsInitialized == false) {
quietArgument = new BooleanArgument(
noPromptArgument = new BooleanArgument(
.get());
// Register the global arguments.
// Register any global arguments required by the management
// context factory.
globalArgumentsInitialized = true;
}
}
/**
* Registers the sub-commands with the argument parser. This method
* uses the administration framework introspection APIs to determine
* the overall structure of the command-line.
*
* @throws ArgumentException
* If a sub-command could not be created.
*/
private void initializeSubCommands() throws ArgumentException {
if (handlerFactory == null) {
}
};
.getAllSubCommandHandlers()) {
// Add the sub-command to its groups.
}
}
}
// Register the usage arguments.
}
// Register the --help-all argument.
}
}
/**
* Parses the provided command-line arguments and makes the
* appropriate changes to the Directory Server configuration.
*
* @param args
* The command-line arguments provided to this program.
* @return The exit code from the configuration processing. A
* nonzero value indicates that there was some kind of
* problem during the configuration processing.
*/
// Register global arguments and sub-commands.
try {
} catch (ArgumentException e) {
return 1;
}
// Parse the command-line arguments provided to this program.
try {
} catch (ArgumentException ae) {
return 1;
}
// to do anything else.
if (parser.usageOrVersionDisplayed()) {
return 0;
}
// Check for conflicting arguments.
return 1;
}
.getLongIdentifier());
return 1;
}
return 1;
}
{
return 1;
}
// Make sure that management context's arguments are valid.
try {
} catch (ArgumentException e) {
println(e.getMessageObject());
return 1;
}
hasSubCommand = false;
if (isInteractive()) {
// Top-level interactive mode.
return runInteractiveMode();
} else {
return 1;
}
} else {
hasSubCommand = true;
// Retrieve the sub-command implementation and run it.
return runSubCommand(handler);
}
}
// Run the top-level interactive console.
private int runInteractiveMode() {
// In interactive mode, redirect all output to stdout.
// Build menu structure.
Comparator<RelationDefinition<?, ?>> c =
new Comparator<RelationDefinition<?, ?>>() {
RelationDefinition<?, ?> rd2) {
}
};
}
}
for (ListSubCommandHandler lh :
}
}
}
// Main menu.
}
try {
// Force retrieval of management context.
} catch (ArgumentException e) {
return 1;
} catch (ClientException e) {
return 1;
}
try {
return 0;
} else {
}
} catch (CLIException e) {
return 1;
}
}
// Run the provided sub-command handler.
try {
} else {
// User must have quit.
return 1;
}
} catch (ArgumentException e) {
println(e.getMessageObject());
return 1;
} catch (CLIException e) {
println(e.getMessageObject());
return 1;
} catch (ClientException e) {
if (cause instanceof ManagedObjectDecodingException) {
println();
println();
} else if (cause instanceof MissingMandatoryPropertiesException) {
println();
println();
} else if (cause instanceof OperationRejectedException) {
println();
displayOperationRejectedException(this, ore);
println();
} else {
// Just display the default message.
println(e.getMessageObject());
}
return 1;
} catch (Exception e) {
if (debugEnabled()) {
}
return 1;
}
}
}