<?xml version="1.0" encoding="UTF-8"?>

<!--  An example Spring configuration for Spring LDAP ODM -->

<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:util="http://www.springframework.org/schema/util"
    xsi:schemaLocation="http://www.springframework.org/schema/beans
           http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
           http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-2.5.xsd">

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

    <bean id="contextSourceTarget" class="org.springframework.ldap.core.support.LdapContextSource">
        <property name="url" value="ldap://127.0.0.1:10389" />
        <property name="userDn" value="uid=admin,ou=system" />
        <property name="password" value="secret" />
        <property name="pooled" value="false" />
    </bean>

    <bean id="dirContextValidator" class="org.springframework.ldap.pool.validation.DefaultDirContextValidator">
        <property name="base" value="" />
        <property name="filter" value="objectclass=*" />
        <property name="searchControls.searchScope">
            <util:constant static-field="javax.naming.directory.SearchControls.OBJECT_SCOPE" />
        </property>
    </bean>

    <bean id="contextSource" class="org.springframework.ldap.pool.factory.PoolingContextSource">
        <property name="contextSource" ref="contextSourceTarget" />
        <property name="dirContextValidator" ref="dirContextValidator" />
        <property name="maxActive" value="10" />
        <property name="maxTotal" value="10" />
        <property name="maxIdle" value="5" />
        <property name="minIdle" value="1" />
        <property name="timeBetweenEvictionRunsMillis" value="60000" />
        <property name="testOnBorrow" value="true" />
        <property name="testWhileIdle" value="true" />
    </bean>

    <bean id="odmManager" class="org.springframework.ldap.odm.core.impl.OdmManagerImplFactoryBean">
        <property name="converterManager" ref="converterManager" />
        <property name="contextSource" ref="contextSource" />
        <property name="managedClasses">
            <set>
                <value>org.springframework.ldap.odm.sample.SimplePerson</value>
            </set>
        </property>
    </bean>

</beans>
