public class AeshCommandPopulator extends java.lang.Object implements CommandPopulator<java.lang.Object,Command>
| Modifier and Type | Field and Description |
|---|---|
private java.lang.Object |
instance |
| Constructor and Description |
|---|
AeshCommandPopulator(java.lang.Object instance) |
| Modifier and Type | Method and Description |
|---|---|
private java.lang.reflect.Field |
getField(java.lang.Class clazz,
java.lang.String fieldName) |
java.lang.Object |
getObject() |
void |
populateObject(CommandLine<Command> line,
InvocationProviders invocationProviders,
AeshContext aeshContext,
boolean validate)
Populate a Command instance with the values parsed from a command line
If any parser errors are detected it will throw an exception
|
private void |
resetField(java.lang.Object instance,
java.lang.String fieldName,
boolean hasValue)
Will parse the input line and populate the fields in the instance object specified by
the given annotations.
|
public void populateObject(CommandLine<Command> line, InvocationProviders invocationProviders, AeshContext aeshContext, boolean validate) throws CommandLineParserException, OptionValidatorException
populateObject in interface CommandPopulator<java.lang.Object,Command>line - command linevalidate - do validation or notaeshContext - the contextCommandLineParserExceptionOptionValidatorExceptionprivate void resetField(java.lang.Object instance,
java.lang.String fieldName,
boolean hasValue)
instance - commandfieldName - field
public static void parseAndPopulate(Object instance, String line)
throws CommandLineParserException, OptionValidatorException {
CommandLineParser parser = ParserGenerator.generateCommandLineParser(instance.getClass());
AeshCommandPopulator populator = new AeshCommandPopulator(parser);
populator.populateObject(instance, parser.parse(line));
}private java.lang.reflect.Field getField(java.lang.Class clazz,
java.lang.String fieldName)
throws java.lang.NoSuchFieldException
java.lang.NoSuchFieldExceptionpublic java.lang.Object getObject()
getObject in interface CommandPopulator<java.lang.Object,Command>