Fix for LDAP-79: Document AbstractContextMapper.

This commit is contained in:
Mattias Arthursson
2007-09-07 13:35:57 +00:00
parent 327a20bbf3
commit 5b8f99e86c
3 changed files with 27 additions and 7 deletions

View File

@@ -60,10 +60,30 @@ public class PersonDaoImpl implements PersonDao {
directly by name, without having to go through the directly by name, without having to go through the
<literal>Attributes</literal> and <literal>BasicAttribute</literal> <literal>Attributes</literal> and <literal>BasicAttribute</literal>
classes.</para> classes.</para>
<para>Spring LDAP provides an abstract base implementation of <literal>ContextMapper</literal>,
<literal>AbstractContextMapper</literal>. This automatically takes care of the casting of the supplied
<literal>Object</literal> parameter to <literal>DirContexOperations</literal>.
The <literal>PersonContextMapper</literal> above can thus be re-written as follows:
</para>
<example>
<title>Using an AbstractContextMapper</title>
<programlisting>
private static class PersonContextMapper <emphasis role="bold">extends AbstractContextMapper</emphasis> {
public Object <emphasis role="bold">doMapFromContext</emphasis>(DirContextOperations ctx) {
Person p = new Person();
p.setFullName(context.getStringAttribute("cn"));
p.setLastName(context.getStringAttribute("sn"));
p.setDescription(context.getStringAttribute("description"));
return p;
}
}
</programlisting>
</example>
</sect1> </sect1>
<sect1> <sect1>
<title>Binding and Modifying Using ContextMapper</title> <title>Binding and Modifying Using DirContextAdapter</title>
<para>The DirContextAdapter can also be used to hide the Attributes when <para>The DirContextAdapter can also be used to hide the Attributes when
binding and modifying data.</para> binding and modifying data.</para>

View File

@@ -27,12 +27,12 @@ import org.springframework.ldap.core.support.AbstractContextMapper;
*/ */
public class PersonContextMapper extends AbstractContextMapper { public class PersonContextMapper extends AbstractContextMapper {
protected Object doMapFromContext(DirContextOperations operations) { protected Object doMapFromContext(DirContextOperations ctx) {
Person person = new Person(); Person person = new Person();
person.setFullname(operations.getStringAttribute("cn")); person.setFullname(ctx.getStringAttribute("cn"));
person.setLastname(operations.getStringAttribute("sn")); person.setLastname(ctx.getStringAttribute("sn"));
person.setPhone(operations.getStringAttribute("telephoneNumber")); person.setPhone(ctx.getStringAttribute("telephoneNumber"));
person.setDescription(operations.getStringAttribute("description")); person.setDescription(ctx.getStringAttribute("description"));
return person; return person;
} }

View File

@@ -50,6 +50,6 @@ public abstract class AbstractContextMapper implements ContextMapper {
* the context to map to an object. * the context to map to an object.
* @return an object built from the data in the context. * @return an object built from the data in the context.
*/ */
protected abstract Object doMapFromContext(DirContextOperations operations); protected abstract Object doMapFromContext(DirContextOperations ctx);
} }