Chapter 7. Java 5 Support

7.1. SimpleLdapTemplate

As of version 1.3 Spring LDAP includes the spring-ldap-core-tiger.jar distributable, which adds a thin layer of Java 5 functionality on top of Spring LDAP.

The SimpleLdapTemplate class adds search and lookup methods that take a ParameterizedContextMapper, adding generics support to these methods.

ParametrizedContextMapper is a typed version of ContextMapper, which simplifies working with searches and lookups:

Example 7.1. Using ParameterizedContextMapper

public List<Person> getAllPersons(){
    return"", "(objectclass=person)",
               new ParameterizedContextMapper<Person>() {
                   public Person mapFromContext(Object ctx) {
                       DirContextAdapter adapter = (DirContextAdapter) ctx;
                       Person person = new Person();
                       // Fill the domain object with data from the DirContextAdapter
                       return person;