public interface DataTranslator
DataTranslator defines a mechanism by which an arbitrary object
is translated into an instance of a given class. Classes implementing
this interface are discovered using standard ServiceLoader.| Modifier and Type | Field and Description |
|---|---|
static Object |
NULL_OBJECT
This constant allows the translator to indicate that the result value
is
null, which normally means unsuccessful translation, causing
further attempts of translation. |
static int |
PRIORITY_NORMAL_SUPPORT
The default priority means that a class is supported by this translator.
|
static int |
PRIORITY_NOT_SUPPORTED
Priority 0 denotes that a class is not supported by this translator.
|
| Modifier and Type | Method and Description |
|---|---|
String |
getId()
Gets an identifier of this translator.
|
int |
getTargetClassSupportPriority(Class<?> targetClass,
DataTranslatorContext context)
Determines whether the argument represents a class supported by this
translator.
|
Object |
translateToClass(Object source,
Class<?> targetClass,
DataTranslatorContext context)
Attempts to translate an arbitrary object into an instance of
targetClass. |
static final int PRIORITY_NOT_SUPPORTED
static final int PRIORITY_NORMAL_SUPPORT
static final Object NULL_OBJECT
null, which normally means unsuccessful translation, causing
further attempts of translation.String getId()
int getTargetClassSupportPriority(Class<?> targetClass, DataTranslatorContext context)
PRIORITY_NOT_SUPPORTED constant.
The translator that reports the highest priority will be used for the actual translation. If there are multiple translators with the same maximum priority, the choice will be arbitrary.
targetClass - class of the expected result of translationcontext - context of the translationtargetClass; zero or negative value if the class is not
supportedObject translateToClass(Object source, Class<?> targetClass, DataTranslatorContext context)
targetClass.
If the translation couldn't be performed, null is returned.
As the translation happens while preparing configuration data, the translator receives information about the context of translation.
source - non-null object that is to be translatedtargetClass - requested target classcontext - context of the translationtargetClass; null if the translation cannot
be performed; NULL_OBJECT if the result should be true null valueCopyright © 2015 Boleslav Bobcik - Auderis. All rights reserved.