2.17.2: 2011-06-17

net.sf.basedb.util.extensions.xml
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.
@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
 String convert(String in, Method method)
          Convert a value.
 

Method Detail

convert

String convert(String in,
               Method method)
Convert a value.

Parameters:
in - The value to convert
method - The factory setter method
Returns:
The converted or original value

2.17.2: 2011-06-17