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=orgThis handler should only be used with the
SearchOperation.execute() method since it leverages
the connection to make further searches.-
Nested Class Summary
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final inthash code seed.private String[]Attribute(s) to merge.private String[]Attributes to return when searching, mergeAttributes + searchAttribute.private StringAttribute to recursively search on.Fields inherited from class org.ldaptive.transport.AbstractMessageFunctionalEntryHandler
logger -
Constructor Summary
ConstructorsConstructorDescriptionDefault constructor.RecursiveResultHandler(String searchAttr, String... mergeAttrs) Creates a new recursive entry handler. -
Method Summary
Modifier and TypeMethodDescriptionapply(SearchResponse response) booleanString[]Returns the attribute names that will be merged by the recursive search.Returns the attribute name that will be recursively searched on.voidhandleEntry(LdapEntry entry) Handle the entry.inthashCode()protected voidInitializes the return attributes array.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.toString()Methods inherited from class org.ldaptive.transport.AbstractMessageFunctionalEntryHandler
handleAttribute, handleAttributeName, handleAttributes, handleAttributeValue, handleAttributeValue, handleDnMethods inherited from class org.ldaptive.transport.MessageFunctional
getConnection, getHandle, getRequest, setConnection, setHandle, setRequestMethods inherited from class org.ldaptive.AbstractFreezable
assertMutable, freeze, freeze, freeze, isFrozen
-
Field Details
-
HASH_CODE_SEED
private static final int HASH_CODE_SEEDhash code seed.- See Also:
-
searchAttribute
Attribute to recursively search on. -
mergeAttributes
Attribute(s) to merge. -
retAttrs
Attributes to return when searching, mergeAttributes + searchAttribute.
-
-
Constructor Details
-
RecursiveResultHandler
public RecursiveResultHandler()Default constructor. -
RecursiveResultHandler
Creates a new recursive entry handler.- Parameters:
searchAttr- attribute to search onmergeAttrs- attribute names to merge
-
-
Method Details
-
getSearchAttribute
Returns the attribute name that will be recursively searched on.- Returns:
- attribute name
-
setSearchAttribute
Sets the attribute name that will be recursively searched on.- Parameters:
name- of the search attribute
-
getMergeAttributes
Returns the attribute names that will be merged by the recursive search.- Returns:
- attribute names
-
setMergeAttributes
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
- Specified by:
applyin interfaceFunction<SearchResponse,SearchResponse>
-
handleEntry
Description copied from class:AbstractMessageFunctionalEntryHandlerHandle the entry.- Overrides:
handleEntryin classAbstractMessageFunctionalEntryHandler<SearchResponse>- Parameters:
entry- to handle
-
readSearchAttribute
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
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
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
- Overrides:
equalsin classAbstractMessageFunctionalEntryHandler<SearchResponse>
-
hashCode
public int hashCode()- Specified by:
hashCodein classAbstractMessageFunctionalEntryHandler<SearchResponse>
-
toString
-