Package org.ldaptive.handler
Class RecursiveResultHandler
- java.lang.Object
-
- org.ldaptive.AbstractFreezable
-
- org.ldaptive.transport.MessageFunctional<Q,S>
-
- org.ldaptive.transport.MessageFunctional.Function<SearchRequest,SearchResponse,T,T>
-
- org.ldaptive.transport.AbstractMessageFunctionalEntryHandler<SearchResponse>
-
- org.ldaptive.handler.RecursiveResultHandler
-
- All Implemented Interfaces:
Function<SearchResponse,SearchResponse>,Freezable,SearchResultHandler
public class RecursiveResultHandler extends AbstractMessageFunctionalEntryHandler<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 intHASH_CODE_SEEDhash code seed.private String[]mergeAttributesAttribute(s) to merge.private String[]retAttrsAttributes to return when searching, mergeAttributes + searchAttribute.private StringsearchAttributeAttribute to recursively search on.-
Fields inherited from class org.ldaptive.transport.AbstractMessageFunctionalEntryHandler
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 SearchResponseapply(SearchResponse response)booleanequals(Object o)String[]getMergeAttributes()Returns the attribute names that will be merged by the recursive search.StringgetSearchAttribute()Returns the attribute name that will be recursively searched on.voidhandleEntry(LdapEntry entry)Handle the entry.inthashCode()protected voidinitializeReturnAttributes()Initializes the return attributes array.RecursiveResultHandlernewInstance()Create a new instance of this message functional.protected SearchResponseperformSearch(String baseDn, String[] attrs)Perform an object scope search on the supplied baseDN and retrieve the supplied return attributes.private voidreadSearchAttribute(LdapEntry entry, List<String> searchedDns)Reads the values ofsearchAttributefrom the supplied attributes and callsrecursiveSearch(java.lang.String, org.ldaptive.LdapEntry, java.util.List<java.lang.String>)for each.private voidrecursiveSearch(String dn, LdapEntry entry, List<String> searchedDns)Recursively gets the attribute(s)mergeAttributesfor the supplied dn and adds the values to the supplied attributes.voidsetMergeAttributes(String... mergeAttrs)Sets the attribute name that will be merged by the recursive search.voidsetSearchAttribute(String name)Sets the attribute name that will be recursively searched on.StringtoString()-
Methods inherited from class org.ldaptive.transport.AbstractMessageFunctionalEntryHandler
handleAttribute, handleAttributeName, handleAttributes, handleAttributeValue, handleAttributeValue, handleDn
-
Methods inherited from class org.ldaptive.transport.MessageFunctional
getConnection, getHandle, getRequest, setConnection, setHandle, setRequest
-
Methods inherited from class org.ldaptive.AbstractFreezable
assertMutable, freeze, freeze, freeze, isFrozen
-
-
-
-
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:
applyin interfaceFunction<SearchResponse,SearchResponse>
-
handleEntry
public void handleEntry(LdapEntry entry)
Description copied from class:AbstractMessageFunctionalEntryHandlerHandle the entry.- Overrides:
handleEntryin classAbstractMessageFunctionalEntryHandler<SearchResponse>- Parameters:
entry- to handle
-
readSearchAttribute
private void readSearchAttribute(LdapEntry entry, List<String> searchedDns) throws LdapException
Reads the values ofsearchAttributefrom 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- Throws:
LdapException- if an error occurs performing a search
-
recursiveSearch
private void recursiveSearch(String dn, LdapEntry entry, List<String> searchedDns) throws LdapException
Recursively gets the attribute(s)mergeAttributesfor 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- Throws:
LdapException- if an error occurs performing a search
-
performSearch
protected SearchResponse performSearch(String baseDn, String[] attrs) throws LdapException
Perform an object scope search on the supplied baseDN and retrieve the supplied return attributes.- Parameters:
baseDn- to search onattrs- attributes to return- Returns:
- search response
- Throws:
LdapException- if the search operation fails
-
newInstance
public RecursiveResultHandler newInstance()
Description copied from class:MessageFunctionalCreate a new instance of this message functional.- Specified by:
newInstancein classMessageFunctional<SearchRequest,SearchResponse>- Returns:
- new instance of this message functional
-
equals
public boolean equals(Object o)
- Overrides:
equalsin classAbstractMessageFunctionalEntryHandler<SearchResponse>
-
hashCode
public int hashCode()
- Specified by:
hashCodein classAbstractMessageFunctionalEntryHandler<SearchResponse>
-
-