Package org.ldaptive.handler
Class RecursiveResultHandler
- java.lang.Object
-
- org.ldaptive.transport.MessageFunctional<Q,S>
-
- org.ldaptive.transport.MessageFunctional.Function<SearchRequest,SearchResponse,T,T>
-
- org.ldaptive.handler.AbstractEntryHandler<SearchResponse>
-
- org.ldaptive.handler.RecursiveResultHandler
-
- All Implemented Interfaces:
Function<SearchResponse,SearchResponse>
,SearchResultHandler
public class RecursiveResultHandler extends AbstractEntryHandler<SearchResponse> implements SearchResultHandler
This recursively searches based on a supplied attribute and merges those results into the original entry. For the following LDIF:dn: uugid=group1,ou=groups,dc=ldaptive,dc=org uugid: group1 member: uugid=group2,ou=groups,dc=ldaptive,dc=org dn: uugid=group2,ou=groups,dc=ldaptive,dc=org uugid: group2
With the following code:
RecursiveResultHandler reh = new RecursiveResultHandler("member", "uugid");
Will produce this result for the query (uugid=group1):
dn: uugid=group1,ou=groups,dc=ldaptive,dc=org uugid: group1 uugid: group2 member: uugid=group2,ou=groups,dc=ldaptive,dc=org
This handler should only be used with theSearchOperation.execute()
method since it leverages the connection to make further searches.
-
-
Field Summary
Fields Modifier and Type Field Description private static int
HASH_CODE_SEED
hash code seed.private String[]
mergeAttributes
Attribute(s) to merge.private String[]
retAttrs
Attributes to return when searching, mergeAttributes + searchAttribute.private String
searchAttribute
Attribute to recursively search on.-
Fields inherited from class org.ldaptive.handler.AbstractEntryHandler
logger
-
-
Constructor Summary
Constructors Constructor Description RecursiveResultHandler()
Default constructor.RecursiveResultHandler(String searchAttr, String... mergeAttrs)
Creates a new recursive entry handler.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description SearchResponse
apply(SearchResponse response)
boolean
equals(Object o)
String[]
getMergeAttributes()
Returns the attribute names that will be merged by the recursive search.String
getSearchAttribute()
Returns the attribute name that will be recursively searched on.void
handleEntry(LdapEntry entry)
Handle the entry.int
hashCode()
protected void
initializeReturnAttributes()
Initializes the return attributes array.private void
readSearchAttribute(LdapEntry entry, List<String> searchedDns)
Reads the values ofsearchAttribute
from the supplied attributes and callsrecursiveSearch(java.lang.String, org.ldaptive.LdapEntry, java.util.List<java.lang.String>)
for each.private void
recursiveSearch(String dn, LdapEntry entry, List<String> searchedDns)
Recursively gets the attribute(s)mergeAttributes
for the supplied dn and adds the values to the supplied attributes.void
setMergeAttributes(String... mergeAttrs)
Sets the attribute name that will be merged by the recursive search.void
setSearchAttribute(String name)
Sets the attribute name that will be recursively searched on.String
toString()
-
Methods inherited from class org.ldaptive.handler.AbstractEntryHandler
handleAttribute, handleAttributeName, handleAttributes, handleAttributeValue, handleAttributeValue, handleDn
-
Methods inherited from class org.ldaptive.transport.MessageFunctional
getConnection, getHandle, getRequest, setConnection, setHandle, setRequest
-
-
-
-
Field Detail
-
HASH_CODE_SEED
private static final int HASH_CODE_SEED
hash code seed.- See Also:
- Constant Field Values
-
searchAttribute
private String searchAttribute
Attribute to recursively search on.
-
mergeAttributes
private String[] mergeAttributes
Attribute(s) to merge.
-
retAttrs
private String[] retAttrs
Attributes to return when searching, mergeAttributes + searchAttribute.
-
-
Method Detail
-
getSearchAttribute
public String getSearchAttribute()
Returns the attribute name that will be recursively searched on.- Returns:
- attribute name
-
setSearchAttribute
public void setSearchAttribute(String name)
Sets the attribute name that will be recursively searched on.- Parameters:
name
- of the search attribute
-
getMergeAttributes
public String[] getMergeAttributes()
Returns the attribute names that will be merged by the recursive search.- Returns:
- attribute names
-
setMergeAttributes
public void setMergeAttributes(String... mergeAttrs)
Sets the attribute name that will be merged by the recursive search.- Parameters:
mergeAttrs
- attribute names to merge
-
initializeReturnAttributes
protected void initializeReturnAttributes()
Initializes the return attributes array. Must be called after both searchAttribute and mergeAttributes have been set.
-
apply
public SearchResponse apply(SearchResponse response)
- Specified by:
apply
in interfaceFunction<SearchResponse,SearchResponse>
-
handleEntry
public void handleEntry(LdapEntry entry)
Description copied from class:AbstractEntryHandler
Handle the entry.- Overrides:
handleEntry
in classAbstractEntryHandler<SearchResponse>
- Parameters:
entry
- to handle
-
readSearchAttribute
private void readSearchAttribute(LdapEntry entry, List<String> searchedDns)
Reads the values ofsearchAttribute
from the supplied attributes and callsrecursiveSearch(java.lang.String, org.ldaptive.LdapEntry, java.util.List<java.lang.String>)
for each.- Parameters:
entry
- to readsearchedDns
- list of DNs whose attributes have been read
-
recursiveSearch
private void recursiveSearch(String dn, LdapEntry entry, List<String> searchedDns)
Recursively gets the attribute(s)mergeAttributes
for the supplied dn and adds the values to the supplied attributes.- Parameters:
dn
- to get attribute(s) forentry
- to merge withsearchedDns
- list of DNs that have been searched for
-
equals
public boolean equals(Object o)
- Overrides:
equals
in classAbstractEntryHandler<SearchResponse>
-
hashCode
public int hashCode()
- Specified by:
hashCode
in classAbstractEntryHandler<SearchResponse>
-
-