Interface ValueConverter

All Known Implementing Classes:
PathConverter, VariableConverter

public interface ValueConverter
Interface for classes that wants to inspect/convert parameters from the XML file before they are passed to factory setter methods.

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.
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.

Last modified
$Date:2008-03-20 12:15:25 +0100 (Thu, 20 Mar 2008) $
  • Method Summary

    Modifier and Type Method Description
    String convert​(String in, Method method)
    Convert a value.
  • Method Details

    • convert

      String convert​(String in, Method method)
      Convert a value.
      in - The value to convert
      method - The factory setter method
      The converted or original value