org.hyphenType.optionprocessors
Interface ArgumentsProcessorEngine<U extends Annotation>
- Type Parameters:
T
-
- All Known Implementing Classes:
- BooleanValidatorEngine, CustomizableValidatorEngine
public interface ArgumentsProcessorEngine<U extends Annotation>
A processor for arguments parsed. A processor is an object that will check an
option object to search for inconsistencies. All processor are called before
option objects are made available for the main application, representing part
of a contract the arguments must met in order to be accepted into the main
application. As in design by contract, the main application does not need to
have defensive source code. In other words, the main application does not
need to protect itself from malformed option objects.
Argument processor classes should declare an inner annotation that is to be
added to the options interface. When such annotation is detected, the
extractor will search for the class in which the annotation was declared
using Class.getEnclosingClass()
. After the processor class was found,
a new instance of the processor class the extractor will create a new
instance of this class using the default constructor.
The method ArgumentsProcessorEngine#process(Class, Options, Enum)
,
should search for contract violations. When the first violation is found,
this method should call either Options#exit(Enum)
or
Options#exit(int)
to terminate the JVM.
Although a good example of implementation of ArgumentsProcessorEngine
is the class BooleanValidatorEngine
, maybe the following pseudo code
clarifies our explanation:
public class FooValidatorEngine<T extends Options<?>> implements ArgumentValidator<T, FooValidator> {
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE)
public @interface FooValidator {
String propertyA() default "ABC";
String propertyB();
}
@Override
public void run(Class<T> interfaceClass, T options, FooValidator config) {
if(options are NOT OK)
options.exit(returnCode);
}
}
Properties with default values (such as propertyA above) will come with the
default value filled even if the user did not specify any value for this
property explicitly.
When writing an argument processor engine keep in mind that users will
interface only with the inner annotation and the processor itself will be
invisible. Which means the annotation, not the processor, should have a
friendly name.
- Author:
- Aurelio Akira M. Matsui
Method Summary |
|
process(Class<T> interfaceClass,
T options,
U config)
Must call Options#exit(Enum) or Options#exit(int) if, and
only if, the options violate the contract represented by this argument
validator engine. |
process
<T extends Options<?>> void process(Class<T> interfaceClass,
T options,
U config)
- Must call
Options#exit(Enum)
or Options#exit(int)
if, and
only if, the options violate the contract represented by this argument
validator engine.
- Parameters:
interfaceClass
- The options interface classoptions
- The options objectconfig
- The configuration annotation
Copyright © 2013. All Rights Reserved.