diff --git a/spring-ldap/docs/reference/src/dirobjectfactory.xml b/spring-ldap/docs/reference/src/dirobjectfactory.xml index adef7454..0e352694 100644 --- a/spring-ldap/docs/reference/src/dirobjectfactory.xml +++ b/spring-ldap/docs/reference/src/dirobjectfactory.xml @@ -60,10 +60,30 @@ public class PersonDaoImpl implements PersonDao { directly by name, without having to go through the Attributes and BasicAttribute classes. + Spring LDAP provides an abstract base implementation of ContextMapper, + AbstractContextMapper. This automatically takes care of the casting of the supplied + Object parameter to DirContexOperations. + The PersonContextMapper above can thus be re-written as follows: + + + Using an AbstractContextMapper + + + private static class PersonContextMapper extends AbstractContextMapper { + public Object doMapFromContext(DirContextOperations ctx) { + Person p = new Person(); + p.setFullName(context.getStringAttribute("cn")); + p.setLastName(context.getStringAttribute("sn")); + p.setDescription(context.getStringAttribute("description")); + return p; + } + } + + - Binding and Modifying Using ContextMapper + Binding and Modifying Using DirContextAdapter The DirContextAdapter can also be used to hide the Attributes when binding and modifying data. diff --git a/spring-ldap/src/itest/java/org/springframework/ldap/PersonContextMapper.java b/spring-ldap/src/itest/java/org/springframework/ldap/PersonContextMapper.java index 1539979d..da560d01 100644 --- a/spring-ldap/src/itest/java/org/springframework/ldap/PersonContextMapper.java +++ b/spring-ldap/src/itest/java/org/springframework/ldap/PersonContextMapper.java @@ -27,12 +27,12 @@ import org.springframework.ldap.core.support.AbstractContextMapper; */ public class PersonContextMapper extends AbstractContextMapper { - protected Object doMapFromContext(DirContextOperations operations) { + protected Object doMapFromContext(DirContextOperations ctx) { Person person = new Person(); - person.setFullname(operations.getStringAttribute("cn")); - person.setLastname(operations.getStringAttribute("sn")); - person.setPhone(operations.getStringAttribute("telephoneNumber")); - person.setDescription(operations.getStringAttribute("description")); + person.setFullname(ctx.getStringAttribute("cn")); + person.setLastname(ctx.getStringAttribute("sn")); + person.setPhone(ctx.getStringAttribute("telephoneNumber")); + person.setDescription(ctx.getStringAttribute("description")); return person; } diff --git a/spring-ldap/src/main/java/org/springframework/ldap/core/support/AbstractContextMapper.java b/spring-ldap/src/main/java/org/springframework/ldap/core/support/AbstractContextMapper.java index 342c0b22..fc25f06e 100644 --- a/spring-ldap/src/main/java/org/springframework/ldap/core/support/AbstractContextMapper.java +++ b/spring-ldap/src/main/java/org/springframework/ldap/core/support/AbstractContextMapper.java @@ -50,6 +50,6 @@ public abstract class AbstractContextMapper implements ContextMapper { * the context to map to an object. * @return an object built from the data in the context. */ - protected abstract Object doMapFromContext(DirContextOperations operations); + protected abstract Object doMapFromContext(DirContextOperations ctx); }