[
https://issues.apache.org/jira/browse/DIRAPI-163?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13852985#comment-13852985
]
lucas theisen commented on DIRAPI-163:
--------------------------------------
For search, you would use callbacks to map to model objects:
{code:java}
public <T> List<T> search( SearchRequest searchRequest,
EntryMapper<T> entryMapper ) {
List<T> entries = new ArrayList<T>();
LdapConnection connection = null;
try {
connection = ldapConnections.borrowObject();
for ( Entry entry : new EntryCursorImpl( connection.search(
searchRequest ) ) ) {
entries.add( entryMapper.map( entry ) );
}
}
catch ( LdapException e ) {
throw new LdapRuntimeException( e );
}
finally {
returnLdapConnection( connection );
}
return entries;
}
...
public static interface EntryMapper<T> {
public T map( Entry entry ) throws LdapException;
}
{code}
And you consume it thusly:
{code:java}
List<Dn> dns = ldapConnectionTemplate.search( searchRequest,
new EntryMapper<Dn>() {
@Override
public Dn map( Entry entry ) {
return entry.getDn();
}
} );
{code}
> Add an LdapConnectionTemplate (template design pattern)
> -------------------------------------------------------
>
> Key: DIRAPI-163
> URL: https://issues.apache.org/jira/browse/DIRAPI-163
> Project: Directory Client API
> Issue Type: New Feature
> Affects Versions: 1.0.0-M21
> Reporter: lucas theisen
>
> Create an LdapConnectionTemplate that can abstract the cookie cutter using
> callbacks.
--
This message was sent by Atlassian JIRA
(v6.1.4#6159)