The OdmManager relies on the
org.springframework.ldap.odm.typeconversion package to
convert LDAP attributes to Java fields. The main interface in this class
is the
org.springframework.ldap.odm.typeconversion.ConverterManager.
The default ConverterManager implementation uses the
following algorithm when parsing objects to convert fields:
Try to find and use a Converter registered for
the fromClass, syntax and
toClass and use it.
If this fails, then if the toClass
isAssignableFrom the
fromClass then just assign it.
If this fails try to find and use a
Converter registered for the
fromClass and the toClass ignoring the
syntax.
If this fails then throw a
ConverterException.
Implementations of the ConverterManager interface can
be obtained from the
o.s.l.odm.typeconversion.impl.ConvertManagerFactoryBean.
The factory bean requires converter configurations to be declared in the
bean configuration.
The converterConfig property accepts a set of
ConverterConfig classes, each one defining some conversion
logic. A converter config is an instance of
o.s.l.odm.typeconversion.impl.ConverterManagerFactoryBean.ConverterConfig.
The config defines a set of source classes, the set of target classes, and
an implementation of the
org.springframework.ldap.odm.typeconversion.impl.Converter
interface which provides the logic to convert from the
fromClass to the toClass. A sample configuration
is provided in the following example:
Example 12.2. Configuring the Converter Manager Factory
<bean id="fromStringConverter"
class="org.springframework.ldap.odm.typeconversion.impl.converters.FromStringConverter" />
<bean id="toStringConverter"
class="org.springframework.ldap.odm.typeconversion.impl.converters.ToStringConverter" />
<bean id="converterManager"
class="org.springframework.ldap.odm.typeconversion.impl.ConverterManagerFactoryBean">
<property name="converterConfig">
<set>
<bean class="org.springframework.ldap.odm.\
typeconversion.impl.ConverterManagerFactoryBean$ConverterConfig">
<property name="fromClasses">
<set>
<value>java.lang.String</value>
</set>
</property>
<property name="toClasses">
<set>
<value>java.lang.Byte</value>
<value>java.lang.Short</value>
<value>java.lang.Integer</value>
<value>java.lang.Long</value>
<value>java.lang.Float</value>
<value>java.lang.Double</value>
<value>java.lang.Boolean</value>
</set>
</property>
<property name="converter" ref="fromStringConverter" />
</bean>
<bean class="org.springframework.ldap.odm.\
typeconversion.impl.ConverterManagerFactoryBean$ConverterConfig">
<property name="fromClasses">
<set>
<value>java.lang.Byte</value>
<value>java.lang.Short</value>
<value>java.lang.Integer</value>
<value>java.lang.Long</value>
<value>java.lang.Float</value>
<value>java.lang.Double</value>
<value>java.lang.Boolean</value>
</set>
</property>
<property name="toClasses">
<set>
<value>java.lang.String</value>
</set>
</property>
<property name="converter" ref="toStringConverter" />
</bean>
</set>
</property>
</bean>