Package com.im.df.api.support
Interface DFDataConvertor
-
- All Known Subinterfaces:
DFDataAcceptor
,DFDataComparator
public interface DFDataConvertor
This class is supposed to handle conversion to a certain data type from multiple formats. The Convertor can be parametrized using the Options bean, which can be obtained from thecreateOptions()
. If createOptions returns null, no options are supported at all. In such case, theconvert(java.lang.Object, java.lang.Object)
method may ignore whatever options are passed. It is an error to pass an options instance to thecheckDataAcceptance(java.lang.Object, java.lang.Object)
orconvert(java.lang.Object, java.lang.Object)
, which was not created usingcreateOptions()
. The methods will throw anIllegalArgumentException
in such case. Theconvert(java.lang.Object, java.lang.Object)
method may return null for neutral values of the input data. Theconvert(java.lang.Object, java.lang.Object)
may throw an IllegalArgumentException to indicate the input data is not valid.- Author:
- svata
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description boolean
checkDataAcceptance(java.lang.Object value, java.lang.Object options)
Acknowledges that the Converter can work with the passed data.java.lang.Object
convert(java.lang.Object value, java.lang.Object options)
Converts the value.java.lang.Object
convert(java.lang.Object value, java.lang.Object options, java.util.List<java.lang.String> messages)
Converts the value.java.lang.Object
createOptions()
-
-
-
Method Detail
-
checkDataAcceptance
boolean checkDataAcceptance(java.lang.Object value, java.lang.Object options)
Acknowledges that the Converter can work with the passed data. The valuenull
can be always accepted, but is converted to null, but it depends on each convertor implementation - this is not guaranteed.- Parameters:
value
- The value to be convertedoptions
- Optional options object. Can be null for the default conversion- Returns:
- True if the value is correct, otherwise false. If true is returned then it's safe to use
convert(java.lang.Object, java.lang.Object)
method.
-
convert
java.lang.Object convert(java.lang.Object value, java.lang.Object options) throws java.lang.IllegalArgumentException
Converts the value. Same as the 3 argument form except that feedback cannot be give to the user- Parameters:
value
- The value to convert. Can be null (ifcheckDataAcceptance(java.lang.Object, java.lang.Object)
returned true, but then null is typically returned. It also depends on convertor implementation.options
- The conversion options, or null for the default behaviour- Returns:
- The converted value. Can return
null
. - Throws:
java.lang.IllegalArgumentException
- when value is not valid.
-
convert
java.lang.Object convert(java.lang.Object value, java.lang.Object options, java.util.List<java.lang.String> messages) throws java.lang.IllegalArgumentException
Converts the value. Conversion options can be specified (the bean can be obtained by thecreateOptions()
. The method will throw anIllegalArgumentException
, if the passed value is of unsupported type (first check usingcheckDataAcceptance(java.lang.Object, java.lang.Object)
, or the value is invalid.- Parameters:
value
- The value to convert. Can be null (ifcheckDataAcceptance(java.lang.Object, java.lang.Object)
returned true, but then null is typically returned. It also depends on convertor implementation.options
- The conversion options, or null for the default behaviourmessages
- Allows messages to be reported to user by being added to this list. Can be null.- Returns:
- The converted value. Can return
null
. - Throws:
java.lang.IllegalArgumentException
- when value is not valid.
-
createOptions
java.lang.Object createOptions()
- Returns:
- an option bean for the conversion. If the method returns
null
, the converter does not support any options at all.
-
-