SubCommandHandler.java revision 6870993d12bf8a2b9d5cd103dc5ccabc42f9bf5d
* You can obtain a copy of the license at legal-notices/CDDLv1_0.txt
* file and include the License file at legal-notices/CDDLv1_0.txt.
* A path serializer which is used to retrieve a managed object based on a path and a list of path arguments.
private int argIndex;
public <C extends ConfigurationClient, S extends Configuration> void appendManagedObjectPathElement(
} catch (ClientException e) {
clie = e;
} catch (DefinitionDecodingException e) {
dde = e;
} catch (ManagedObjectDecodingException e) {
mode = e;
} catch (AuthorizationException e) {
authze = e;
} catch (ManagedObjectNotFoundException e) {
monfe = e;
} catch (ConcurrentModificationException e) {
cme = e;
} catch (LdapException e) {
ere = e;
public <C extends ConfigurationClient, S extends Configuration> void appendManagedObjectPathElement(
} catch (DefinitionDecodingException e) {
dde = e;
} catch (ManagedObjectDecodingException e) {
mode = e;
} catch (AuthorizationException e) {
authze = e;
} catch (ManagedObjectNotFoundException e) {
monfe = e;
} catch (ConcurrentModificationException e) {
cme = e;
} catch (LdapException e) {
ere = e;
public <C extends ConfigurationClient, S extends Configuration> void appendManagedObjectPathElement(
} catch (ClientException e) {
clie = e;
} catch (DefinitionDecodingException e) {
dde = e;
} catch (ManagedObjectDecodingException e) {
mode = e;
} catch (AuthorizationException e) {
authze = e;
} catch (ManagedObjectNotFoundException e) {
monfe = e;
} catch (ConcurrentModificationException e) {
cme = e;
} catch (LdapException e) {
ere = e;
public <C extends ConfigurationClient, S extends Configuration> void appendManagedObjectPathElement(
} catch (DefinitionDecodingException e) {
dde = e;
} catch (ManagedObjectDecodingException e) {
mode = e;
} catch (AuthorizationException e) {
authze = e;
} catch (ManagedObjectNotFoundException e) {
monfe = e;
} catch (ConcurrentModificationException e) {
cme = e;
} catch (LdapException e) {
ere = e;
* @return Returns a {@link MenuResult#success()} containing the managed object referenced by the provided
* managed object path, or {@link MenuResult#quit()}, or {@link MenuResult#cancel()}, if the sub-command
return result;
throw clie;
throw authze;
throw cme;
throw dde;
throw mode;
throw monfe;
throw ere;
return result;
throw builder.e;
* Indicates whether the sub-command is a create-xxx sub-command, in which case the final path element will have
private final boolean isCreate;
private int sz;
public <C extends ConfigurationClient, S extends Configuration> void appendManagedObjectPathElement(
sz--;
} catch (ArgumentException e) {
public <C extends ConfigurationClient, S extends Configuration> void appendManagedObjectPathElement(
sz--;
public <C extends ConfigurationClient, S extends Configuration> void appendManagedObjectPathElement(
sz--;
} catch (ArgumentException e) {
public <C extends ConfigurationClient, S extends Configuration> void appendManagedObjectPathElement(
sz--;
* The boolean that says whether is useful to display the command builder's contents after calling the run method or
private boolean isCommandBuilderUseful = true;
protected SubCommandHandler() {
if (this == obj) {
commandBuilder = new CommandBuilder(System.getProperty(PROPERTY_SCRIPT_NAME), getSubCommand().getName());
return commandBuilder;
* This method tells whether displaying the command builder contents makes sense or not. For instance in the case of
* @return <CODE>true</CODE> if displaying the command builder is useful and <CODE>false</CODE> otherwise.
public final boolean isCommandBuilderUseful() {
return isCommandBuilderUseful;
return tags;
public final int hashCode() {
* @return Returns a {@link MenuResult#success()} containing zero if the sub-command completed successfully or
* non-zero if it did not, or {@link MenuResult#quit()}, or {@link MenuResult#cancel()}, if the sub-command
public abstract MenuResult<Integer> run(ConsoleApplication app, LDAPManagementContextFactory factory)
* Indicates whether the sub-command is a create-xxx sub-command, in which case the final path element
protected final List<StringArgument> createNamingArgs(SubCommand subCommand, ManagedObjectPath<?, ?> p,
* Creates a script-friendly table printer. This factory method should be used by sub-command handler
* implementations rather than constructing a table printer directly so that we can easily switch table
* @return Returns a {@link MenuResult#success()} containing the managed object referenced by the provided managed
* object path, or {@link MenuResult#quit()}, or {@link MenuResult#cancel()}, if the sub-command was run
protected final MenuResult<ManagedObject<?>> getManagedObject(ConsoleApplication app, ManagementContext context,
protected final List<String> getNamingArgValues(ConsoleApplication app, List<StringArgument> namingArgs)
throws ArgumentException {
return values;
* @return Returns the size unit that the user requested, or <code>null</code> if no size unit was specified.
} catch (IllegalArgumentException e) {
return null;
* @return Returns the time unit that the user requested, or <code>null</code> if no time unit was specified.
} catch (IllegalArgumentException e) {
return null;
protected final boolean isRecordMode() {
* This method will adapt according to the available choice. For example, if there is only one choice, then a
* question will be asked. If there are no children then an <code>ArgumentException</code> will be thrown.
* @return Returns a {@link MenuResult#success()} containing the name of the managed object that the user selected,
* or {@link MenuResult#quit()}, or {@link MenuResult#cancel()}, if the sub-command was run interactive and
protected final <C extends ConfigurationClient, S extends Configuration> MenuResult<String> readChildName(
if (d == null) {
d = r.getChildDefinition();
if (r instanceof InstantiableRelationDefinition) {
} catch (LdapException e) {
if (r instanceof InstantiableRelationDefinition) {
if (r instanceof InstantiableRelationDefinition) {
} catch (DefinitionDecodingException e) {
} catch (ManagedObjectDecodingException e) {
} catch (ManagedObjectNotFoundException e) {
} catch (LdapException e) {
LocalizableMessage msg = INFO_DSCFG_FINDER_PROMPT_SINGLE.get(d.getUserFriendlyName(), children.firstKey());
if (r instanceof InstantiableRelationDefinition) {
} catch (IllegalArgumentException e) {
} catch (IllegalArgumentException e) {
} catch (Throwable t) {
if (r instanceof InstantiableRelationDefinition) {
} catch (IllegalArgumentException e) {
} catch (Throwable t) {
return result;
this.unitSizeArgument = new StringArgument(OPTION_DSCFG_LONG_UNIT_SIZE, OPTION_DSCFG_SHORT_UNIT_SIZE,
this.unitTimeArgument = new StringArgument(OPTION_DSCFG_LONG_UNIT_TIME, OPTION_DSCFG_SHORT_UNIT_TIME,
* Updates the command builder with the arguments defined in the sub command. This implies basically putting the
protected final void updateCommandBuilderWithSubCommand() {
* Returns the string value for a given object as it will be displayed in the equivalent command-line. The code will
* Returns the string value for a given object as it will be displayed in the equivalent command-line.
* Returns a mapping of subordinate managed object type argument values to their corresponding managed object
* @return A mapping of managed object type argument values to their corresponding managed object definitions.
AbstractManagedObjectDefinition<C, S> d) {
= (ManagedObjectDefinition<? extends C, ? extends S>) d;
if (c instanceof ManagedObjectDefinition) {
= (ManagedObjectDefinition<? extends C, ? extends S>) c;
return map;
return name;
* Returns a usage string representing the list of possible types for the provided managed object definition.
* @return A usage string representing the list of possible types for the provided managed object definition.
boolean isFirst = true;
if (!isFirst) {
isFirst = false;