diff --git a/spring-ldap/docs/reference/src/index.xml b/spring-ldap/docs/reference/src/index.xml index 0cf2332f..07a2a9f5 100644 --- a/spring-ldap/docs/reference/src/index.xml +++ b/spring-ldap/docs/reference/src/index.xml @@ -9,6 +9,7 @@ + ]> @@ -49,6 +50,7 @@ &transactions; &executors; &contextprocessor; + &simple; &configuration; \ No newline at end of file diff --git a/spring-ldap/docs/reference/src/simple.xml b/spring-ldap/docs/reference/src/simple.xml new file mode 100644 index 00000000..5ce9b443 --- /dev/null +++ b/spring-ldap/docs/reference/src/simple.xml @@ -0,0 +1,54 @@ + + + + Spring LDAP Java 5 Support + + + SimpleLdapTemplate + + As of version 1.2 Spring LDAP includes the spring-ldap-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 + ParametrizedContextMapper, adding generics support to these methods. + The SimpleLdapTemplate also adds a couple of shortcuts that may be useful when + working with DirContextAdapter, particularly when it comes to updates. + + ParametrizedContextMapper is a typed version of ContextMapper, + which simplifies working with searches and lookups: + + public List<Person> getAllPersons(){ + return simpleLdapTemplate.search("", "(objectclass=person)", + new ParametrizedContextMapper<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; + } + }; +} + + + + Updates are slightly simplified using the convenience wrapper methods in SimpleLdapTemplate. + The lookup method automatically casts to a DirContextOperations, and the modifyAttributes + method automatically gets the necessary information to do the update from the supplied DirContextOperations + instance: + + public void update(Person person){ + DirContextOperations ctx = simpleLdapTemplate.lookup(person.getDn()); + + //Update the DirContextOperation instance with data from the domain object + ctx.setAttributeValue("description", person.getDescription()); + ctx.setAttributeValue("telephoneNumber", peraton.getPhone()); + //... update more attributes here + + simpleLdapOperations.modifyAttributes(ctx); +} + + + + + \ No newline at end of file