org.schmant.arg
Interface ArgumentInterpretationStrategy<T>

All Known Implementing Classes:
AbstractArgumentInterpretationStrategy, AbstractOneToOneArgumentInterpretationStrategy, AbstractReadableFileArgumentInterpretationStrategy, InterpretAsDirectoryStrategy, InterpretAsEFileStrategy, InterpretAsEntityHolderStrategy, InterpretAsEntityStrategy, InterpretAsFileDirectoryStrategy, InterpretAsFileStrategy, InterpretAsFutureEntityStrategy, InterpretAsNamedReadableFileStrategy, InterpretAsNewWritableFileStrategy, InterpretAsRandomlyAccessibleFileStrategy, InterpretAsReadableFileStrategy, InterpretAsReadOnlyDirectoryStrategy, InterpretAsReadOnlyEntityStrategy, InterpretAsUrlStrategy, InterpretAsWritableFileStrategy, InterpretAsXmlSourceStrategy

public interface ArgumentInterpretationStrategy<T>

This interface defines a strategy object used for interpreting and converting objects into a target type, such as EFile. It is used by the ArgumentInterpreter.interpret(Object, ArgumentInterpretationStrategy) method.

Every strategy object is created with a configuration that says which interpretation results that are valid. After calling interpretList(List), ArgumentInterpreter calls validateResult(ArgumentInterpretationResult) to check that the result is valid.

Implementations must be immutable.

Since:
1.0
Author:
Karl Gustafsson

Field Summary
static int ALLOW_NOT_INTERPRETED
          If an object cannot be interpreted, don't treat that as an error.
static int ALLOW_ONE_AND_ONLY_ONE_RESULT_OBJECT
          If the argument interpretation results in zero or two or more result objects, treat that as an error.
 
Method Summary
 ArgumentInterpretationResult<T> interpretList(List<Object> l)
          Interpret the list of supplied objects to the target type.
 void validateResult(ArgumentInterpretationResult<T> result)
          This is called by ArgumentInterpreter to validate that a result object returned by ArgumentInterpreter.interpret(Object, ArgumentInterpretationStrategy) is valid.
 

Field Detail

ALLOW_NOT_INTERPRETED

static final int ALLOW_NOT_INTERPRETED
If an object cannot be interpreted, don't treat that as an error. If an argument interpretation strategy is configured with this value, the result when interpreting objects may contain one or more objects that the strategy object could not interpret.

This constant is used when configuring an argument interpretation strategy object.

See Also:
Constant Field Values

ALLOW_ONE_AND_ONLY_ONE_RESULT_OBJECT

static final int ALLOW_ONE_AND_ONLY_ONE_RESULT_OBJECT
If the argument interpretation results in zero or two or more result objects, treat that as an error.

If this setting is combined with ALLOW_NOT_INTERPRETED, the result object may be either interpreted or not interpreted.

This constant is used when configuring an argument interpretation strategy object.

See Also:
Constant Field Values
Method Detail

interpretList

ArgumentInterpretationResult<T> interpretList(List<Object> l)
                                              throws ArgumentInterpretationException
Interpret the list of supplied objects to the target type.

If an object in the supplied list cannot be interpreted, the configuration of the strategy object decides what happens. For instance, the strategy object may be configured to just ignore objects that it cannot interpret, or it may be configured to throw an ArgumentInterpretationException if it encounters an object it cannot interpret.

Parameters:
l - The list of objects to interpret. Before ArgumentInterpreter passes this list to this strategy object, it flattens the list (see FlatteningList) and gets the produced objects from any Producer:s in the list.
Returns:
A result object. This object is always checked by ArgumentInterpreter by calling the validateResult(ArgumentInterpretationResult) method with the returned object. This means that implementations of this method may choose to not check for the error conditions that validateResult(ArgumentInterpretationResult) detects.
Throws:
ArgumentInterpretationException - Upon interpretation errors. The configuration of the strategy object decides exactly which situations that get treated as errors.

validateResult

void validateResult(ArgumentInterpretationResult<T> result)
                    throws ArgumentInterpretationException
This is called by ArgumentInterpreter to validate that a result object returned by ArgumentInterpreter.interpret(Object, ArgumentInterpretationStrategy) is valid.

The configuration of the strategy object determines which results that are considered valid.

Parameters:
result - The result object.
Throws:
ArgumentInterpretationException - If the result is somehow invalid.