org.schmant.arg
Class AbstractOneToOneArgumentInterpretationStrategy<T>

java.lang.Object
  extended by org.schmant.arg.AbstractArgumentInterpretationStrategy<T>
      extended by org.schmant.arg.AbstractOneToOneArgumentInterpretationStrategy<T>
All Implemented Interfaces:
ArgumentInterpretationStrategy<T>
Direct Known Subclasses:
AbstractReadableFileArgumentInterpretationStrategy, InterpretAsDirectoryStrategy, InterpretAsEFileStrategy, InterpretAsEntityHolderStrategy, InterpretAsEntityStrategy, InterpretAsFileDirectoryStrategy, InterpretAsFileStrategy, InterpretAsFutureEntityStrategy, InterpretAsNewWritableFileStrategy, InterpretAsRandomlyAccessibleFileStrategy, InterpretAsReadOnlyDirectoryStrategy, InterpretAsReadOnlyEntityStrategy, InterpretAsUrlStrategy, InterpretAsWritableFileStrategy, InterpretAsXmlSourceStrategy

public abstract class AbstractOneToOneArgumentInterpretationStrategy<T>
extends AbstractArgumentInterpretationStrategy<T>

This class may be inherited by ArgumentInterpretationStrategy implementations that have a one-to-one relation between interpreted objects. (One object is always interpreted into one result object.)

Since:
1.0
Author:
Karl Gustafsson

Field Summary
 
Fields inherited from interface org.schmant.arg.ArgumentInterpretationStrategy
ALLOW_NOT_INTERPRETED, ALLOW_ONE_AND_ONLY_ONE_RESULT_OBJECT
 
Constructor Summary
protected AbstractOneToOneArgumentInterpretationStrategy(int... configuration)
           
 
Method Summary
 ArgumentInterpretationResult<T> interpretList(List<Object> l)
          Interpret the list of supplied objects to the target type.
protected abstract  T interpretObject(Object o, List<String> trace)
          Subclasses implement this to interpret the supplied object.
 
Methods inherited from class org.schmant.arg.AbstractArgumentInterpretationStrategy
checkConfiguration, convertBackslashesToSlashes, getExistingFileFromCharSequence, getParentFile, getTargetType, trace, validateResult
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AbstractOneToOneArgumentInterpretationStrategy

protected AbstractOneToOneArgumentInterpretationStrategy(int... configuration)
Method Detail

interpretObject

protected abstract T interpretObject(Object o,
                                     List<String> trace)
Subclasses implement this to interpret the supplied object.

Parameters:
o - The object to interpret.
trace - The interpretation trace list. The list should be populated by this method.
Returns:
The interpreted object or null if it could not be interpreted.

interpretList

public final ArgumentInterpretationResult<T> interpretList(List<Object> l)
                                                    throws ArgumentInterpretationException
Description copied from interface: ArgumentInterpretationStrategy
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 ArgumentInterpretationStrategy.validateResult(ArgumentInterpretationResult) method with the returned object. This means that implementations of this method may choose to not check for the error conditions that ArgumentInterpretationStrategy.validateResult(ArgumentInterpretationResult) detects.
Throws:
ArgumentInterpretationException - Upon interpretation errors. The configuration of the strategy object decides exactly which situations that get treated as errors.