Class DefaultIncrementalAttributesMapper
- java.lang.Object
-
- org.springframework.ldap.core.support.DefaultIncrementalAttributesMapper
-
- All Implemented Interfaces:
AttributesMapper<DefaultIncrementalAttributesMapper>,IncrementalAttributesMapper<DefaultIncrementalAttributesMapper>
public class DefaultIncrementalAttributesMapper extends java.lang.Object implements IncrementalAttributesMapper<DefaultIncrementalAttributesMapper>
Utility class that helps with reading all attribute values from Active Directory using Incremental Retrieval of Multi-valued Properties.Example usage of this attribute mapper:
List values = DefaultIncrementalAttributeMapper.lookupAttributeValues(ldapTemplate, theDn, "oneAttribute"); Attributes attrs = DefaultIncrementalAttributeMapper.lookupAttributeValues(ldapTemplate, theDn, new Object[]{"oneAttribute", "anotherAttribute"});For greater control, e.g. explicitly specifying the requested page size, create and use an instance yourself:IncrementalAttributesMapper incrementalAttributeMapper = new DefaultIncrementalAttributeMapper(10, "someAttribute"); while (incrementalAttributeMapper.hasMore()) { ldap.lookup(entrDn, incrementalAttributeMapper.getAttributesForLookup(), incrementalAttributeMapper); } List values = incrementalAttributeMapper.getValues("someAttribute");NOTE: Instances of this class are highly stateful and must not be reused or shared between threads in any way.
NOTE: Instances of this class can only be used with lookups. No support is given for searches.
-
-
Constructor Summary
Constructors Constructor Description DefaultIncrementalAttributesMapper(int pageSize, java.lang.String attributeName)Create an instance for the requested attribute with a specific page size.DefaultIncrementalAttributesMapper(int pageSize, java.lang.String[] attributeNames)Create an instance for the requested attributes with a specific page size.DefaultIncrementalAttributesMapper(java.lang.String attributeName)Create an instance for the requested attribute.DefaultIncrementalAttributesMapper(java.lang.String[] attributeNames)Create an instance for the requested attributes.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.String[]getAttributesForLookup()Get properly formatted attributes for use in the next query.javax.naming.directory.AttributesgetCollectedAttributes()Get all collected values for all managed attributes as an Attributes instance.java.util.List<java.lang.Object>getValues(java.lang.String attributeName)Get all of the collected values for the specified attribute.booleanhasMore()Check whether another query iteration is required to get all values for all attributes.static javax.naming.directory.AttributeslookupAttributes(LdapOperations ldapOperations, java.lang.String dn, java.lang.String attribute)Lookup all values for the specified attribute, looping through the results incrementally if necessary.static javax.naming.directory.AttributeslookupAttributes(LdapOperations ldapOperations, java.lang.String dn, java.lang.String[] attributes)Lookup all values for the specified attributes, looping through the results incrementally if necessary.static javax.naming.directory.AttributeslookupAttributes(LdapOperations ldapOperations, javax.naming.Name dn, java.lang.String attribute)Lookup all values for the specified attribute, looping through the results incrementally if necessary.static javax.naming.directory.AttributeslookupAttributes(LdapOperations ldapOperations, javax.naming.Name dn, java.lang.String[] attributes)Lookup all values for the specified attributes, looping through the results incrementally if necessary.static java.util.List<java.lang.Object>lookupAttributeValues(LdapOperations ldapOperations, java.lang.String dn, java.lang.String attribute)Lookup all values for the specified attribute, looping through the results incrementally if necessary.static java.util.List<java.lang.Object>lookupAttributeValues(LdapOperations ldapOperations, javax.naming.Name dn, java.lang.String attribute)Lookup all values for the specified attribute, looping through the results incrementally if necessary.DefaultIncrementalAttributesMappermapFromAttributes(javax.naming.directory.Attributes attributes)Goes through all of the attributes to record their values and figure out whether a new query iteration is needed to get more values.
-
-
-
Constructor Detail
-
DefaultIncrementalAttributesMapper
public DefaultIncrementalAttributesMapper(java.lang.String attributeName)
Create an instance for the requested attribute.- Parameters:
attributeName- the name of the attribute that this instance handles. This is the attribute name that will be requested, and whose values are managed.
-
DefaultIncrementalAttributesMapper
public DefaultIncrementalAttributesMapper(java.lang.String[] attributeNames)
Create an instance for the requested attributes.- Parameters:
attributeNames- the name of the attributes that this instance handles. These are the attribute names that will be requested, and whose values are managed.
-
DefaultIncrementalAttributesMapper
public DefaultIncrementalAttributesMapper(int pageSize, java.lang.String attributeName)Create an instance for the requested attribute with a specific page size.- Parameters:
pageSize- the requested page size that will be included in range query attribute names.attributeName- the name of the attribute that this instance handles. This is the attribute name that will be requested, and whose values are managed.
-
DefaultIncrementalAttributesMapper
public DefaultIncrementalAttributesMapper(int pageSize, java.lang.String[] attributeNames)Create an instance for the requested attributes with a specific page size.- Parameters:
pageSize- the requested page size that will be included in range query attribute names.attributeNames- the name of the attributes that this instance handles. These are the attribute names that will be requested, and whose values are managed.
-
-
Method Detail
-
mapFromAttributes
public final DefaultIncrementalAttributesMapper mapFromAttributes(javax.naming.directory.Attributes attributes) throws javax.naming.NamingException
Description copied from interface:IncrementalAttributesMapperGoes through all of the attributes to record their values and figure out whether a new query iteration is needed to get more values.- Specified by:
mapFromAttributesin interfaceAttributesMapper<DefaultIncrementalAttributesMapper>- Specified by:
mapFromAttributesin interfaceIncrementalAttributesMapper<DefaultIncrementalAttributesMapper>- Parameters:
attributes- attributes from a SearchResult.- Returns:
- this instance.
- Throws:
javax.naming.NamingException- if any error occurs mapping the attributes
-
getValues
public final java.util.List<java.lang.Object> getValues(java.lang.String attributeName)
Description copied from interface:IncrementalAttributesMapperGet all of the collected values for the specified attribute.- Specified by:
getValuesin interfaceIncrementalAttributesMapper<DefaultIncrementalAttributesMapper>- Parameters:
attributeName- the attribute to get values for.- Returns:
- the collected values for the specified attribute. Will be
nullif the requested attribute has not been returned by the server (attribute did not exist).
-
getCollectedAttributes
public final javax.naming.directory.Attributes getCollectedAttributes()
Description copied from interface:IncrementalAttributesMapperGet all collected values for all managed attributes as an Attributes instance.- Specified by:
getCollectedAttributesin interfaceIncrementalAttributesMapper<DefaultIncrementalAttributesMapper>- Returns:
- an Attributes instance populated with all collected values.
-
hasMore
public final boolean hasMore()
Description copied from interface:IncrementalAttributesMapperCheck whether another query iteration is required to get all values for all attributes.- Specified by:
hasMorein interfaceIncrementalAttributesMapper<DefaultIncrementalAttributesMapper>- Returns:
trueif there are more values for at least one of the managed attributes,falseotherwise.
-
getAttributesForLookup
public final java.lang.String[] getAttributesForLookup()
Description copied from interface:IncrementalAttributesMapperGet properly formatted attributes for use in the next query. The attribute names included will include Range specifiers as needed and only the attributes that have not been retrieved in full will be included.- Specified by:
getAttributesForLookupin interfaceIncrementalAttributesMapper<DefaultIncrementalAttributesMapper>- Returns:
- an array of Strings to be used as input to e.g.
LdapTemplate.lookup(javax.naming.Name, String[], org.springframework.ldap.core.AttributesMapper)in the next iteration.
-
lookupAttributes
public static javax.naming.directory.Attributes lookupAttributes(LdapOperations ldapOperations, java.lang.String dn, java.lang.String attribute)
Lookup all values for the specified attribute, looping through the results incrementally if necessary.- Parameters:
ldapOperations- The instance to use for performing the actual lookup.dn- The distinguished name of the object to find.attribute- name of the attribute to request.- Returns:
- an Attributes instance, populated with all found values for the requested attribute.
Never
null, though the actual attribute may not be set if it was not set on the requested object.
-
lookupAttributes
public static javax.naming.directory.Attributes lookupAttributes(LdapOperations ldapOperations, java.lang.String dn, java.lang.String[] attributes)
Lookup all values for the specified attributes, looping through the results incrementally if necessary.- Parameters:
ldapOperations- The instance to use for performing the actual lookup.dn- The distinguished name of the object to find.attributes- names of the attributes to request.- Returns:
- an Attributes instance, populated with all found values for the requested attributes.
Never
null, though the actual attributes may not be set if they was not set on the requested object.
-
lookupAttributes
public static javax.naming.directory.Attributes lookupAttributes(LdapOperations ldapOperations, javax.naming.Name dn, java.lang.String attribute)
Lookup all values for the specified attribute, looping through the results incrementally if necessary.- Parameters:
ldapOperations- The instance to use for performing the actual lookup.dn- The distinguished name of the object to find.attribute- name of the attribute to request.- Returns:
- an Attributes instance, populated with all found values for the requested attribute.
Never
null, though the actual attribute may not be set if it was not set on the requested object.
-
lookupAttributes
public static javax.naming.directory.Attributes lookupAttributes(LdapOperations ldapOperations, javax.naming.Name dn, java.lang.String[] attributes)
Lookup all values for the specified attributes, looping through the results incrementally if necessary.- Parameters:
ldapOperations- The instance to use for performing the actual lookup.dn- The distinguished name of the object to find.attributes- names of the attributes to request.- Returns:
- an Attributes instance, populated with all found values for the requested attributes.
Never
null, though the actual attributes may not be set if they was not set on the requested object.
-
lookupAttributeValues
public static java.util.List<java.lang.Object> lookupAttributeValues(LdapOperations ldapOperations, java.lang.String dn, java.lang.String attribute)
Lookup all values for the specified attribute, looping through the results incrementally if necessary.- Parameters:
ldapOperations- The instance to use for performing the actual lookup.dn- The distinguished name of the object to find.attribute- name of the attribute to request.- Returns:
- a list with all attribute values found for the requested attribute.
Never
null, an empty list indicates that the attribute was not set or empty.
-
lookupAttributeValues
public static java.util.List<java.lang.Object> lookupAttributeValues(LdapOperations ldapOperations, javax.naming.Name dn, java.lang.String attribute)
Lookup all values for the specified attribute, looping through the results incrementally if necessary.- Parameters:
ldapOperations- The instance to use for performing the actual lookup.dn- The distinguished name of the object to find.attribute- name of the attribute to request.- Returns:
- a list with all attribute values found for the requested attribute.
Never
null, an empty list indicates that the attribute was not set or empty.
-
-