Interface ValueConverter
- All Known Implementing Classes:
PathConverter
,VariableConverter
Instances of this class are registered with an XML loader
with the XmlLoader.addValueConverter(ValueConverter)
method.
Before a factory setter method is called, all registered
converters will get the chance to convert(String, Method)
the parameter value from the XML file. The converters are
called in the order they are registered.
A typical implementation of a converter is to check if the setter method has been annotated with some specific annotation. If, so the value is converted, otherwise it is returned without modification.
// Add a prefix to all strings. @Override public String convert(String in, Method method) { if (!method.isAnnotationPresent(AddPrefix.class)) return in; return in == null ? PREFIX : PREFIX + in; }
Note! Since each registered converter is invoked everytime a
factory setter method is about to be called, we recommend that
the convert(String, Method)
method is kept as quick
as possible.
- Version:
- 2.7
- Author:
- nicklas
- Last modified
- $Date:2008-03-20 12:15:25 +0100 (Thu, 20 Mar 2008) $
-
Method Summary
-
Method Details
-
convert
Convert a value.- Parameters:
in
- The value to convertmethod
- The factory setter method- Returns:
- The converted or original value
-