Package org.ldaptive
Class LdapEntry
java.lang.Object
org.ldaptive.AbstractMessage
org.ldaptive.LdapEntry
LDAP search result entry defined as:
SearchResultEntry ::= [APPLICATION 4] SEQUENCE {
objectName LDAPDN,
attributes PartialAttributeList }
PartialAttributeList ::= SEQUENCE OF
partialAttribute PartialAttribute
PartialAttribute ::= SEQUENCE {
type AttributeDescription,
vals SET OF value AttributeValue }
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected static classParses a buffer containing an attribute name and its values.protected static classParse handler implementation for the attributes.static classprotected static classParse handler implementation for the LDAP DN.Nested classes/interfaces inherited from class org.ldaptive.AbstractMessage
AbstractMessage.AbstractBuilder<B,T extends AbstractMessage>, AbstractMessage.ControlParser, AbstractMessage.ControlsHandler, AbstractMessage.MessageIDHandler -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final Map<String,LdapAttribute> LDAP attributes on the entry.private static final DERPathDER path to attributes.private static final inthash code seed.private booleanWhether this object has been marked immutable.private static final DERPathDER path to LDAP DN.private StringLDAP DN of the entry.private StringNormalized LDAP DN.private DnParsed LDAP DN.static final intBER protocol number. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddAttributes(Collection<LdapAttribute> attrs) Adds attributes to the entry.voidaddAttributes(LdapAttribute... attrs) Adds attributes to the entry.final voidAsserts that this object is in a state to permit mutations.static LdapEntry.Builderbuilder()Creates a builder for this class.final voidclear()Removes all the attributes from this entry.static AttributeModification[]computeModifications(LdapEntry source, LdapEntry target) Returns the list of attribute modifications needed to change the supplied target entry into the supplied source entry.static AttributeModification[]computeModifications(LdapEntry source, LdapEntry target, boolean useReplace) Returns the list of attribute modifications needed to change the supplied target entry into the supplied source entry.static LdapEntryCreates a mutable copy of the supplied entry.booleanvoidfreeze()Freezes this object, making it immutable.Returns a single attribute of this entry.getAttribute(String name) Returns the attribute with the supplied name.byte[]Provides a null safe invocation ofLdapAttribute.getBinaryValue().Collection<byte[]>Provides a null safe invocation ofLdapAttribute.getBinaryValues().String[]Returns the attribute names in this entry.Returns the ldap attributes in this entry.Provides a null safe invocation ofLdapAttribute.getStringValue().Provides a null safe invocation ofLdapAttribute.getStringValues().<T> TgetAttributeValue(String name, Function<byte[], T> func) Provides a null safe invocation ofLdapAttribute.getValue(Function).<T> Collection<T>getAttributeValues(String name, Function<byte[], T> func) Provides a null safe invocation ofLdapAttribute.getValues(Function).final StringgetDn()Returns the ldap DN.final StringReturns the normalized ldap DN.final DnReturns the parsed ldap DN.booleanhasAttribute(String name) Returns whether this entry contains an attribute with the supplied name.booleanhasAttributeValue(String name, byte[] value) Provides a null safe invocation ofLdapAttribute.hasValue(byte[]).booleanhasAttributeValue(String name, String value) Provides a null safe invocation ofLdapAttribute.hasValue(String).inthashCode()Returns the hash code for this object.final booleanisFrozen()Determines whether this object is frozen, i.e. immutable.<T> TmapAttribute(String name, Function<LdapAttribute, T> func) Returns a mapped value from an attribute using the supplied function or null if the attribute doesn't exist.<T> TmapAttribute(String name, Function<LdapAttribute, T> func, T defaultValue) Returns a mapped value from an attribute using the supplied function or defaultValue if the attribute doesn't exist.voidmergeAttributes(Collection<LdapAttribute> attrs) Merges attributes into this entry.voidmergeAttributes(LdapAttribute... attrs) Merges attributes into this entry.booleanprocessAttribute(String name, Consumer<LdapAttribute> func) Processes an attribute using the supplied consumer.voidremoveAttribute(String name) Removes the attribute with the supplied name.voidremoveAttributes(Collection<LdapAttribute> attrs) Removes the attribute(s) from this ldap attributes.voidremoveAttributes(LdapAttribute... attrs) Removes an attribute from this ldap attributes.final voidSets the ldap DN.final intsize()Returns the number of attributes.static LdapEntryReturns a new entry whose attributes are sorted naturally by name without options.toString()Methods inherited from class org.ldaptive.AbstractMessage
addControls, copyValues, equalsMessage, getControls, getMessageID, setMessageIDMethods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface org.ldaptive.Message
getControl
-
Field Details
-
PROTOCOL_OP
public static final int PROTOCOL_OPBER protocol number.- See Also:
-
HASH_CODE_SEED
private static final int HASH_CODE_SEEDhash code seed.- See Also:
-
LDAP_DN_PATH
DER path to LDAP DN. -
ATTRIBUTES_PATH
DER path to attributes. -
attributes
LDAP attributes on the entry. -
ldapDn
LDAP DN of the entry. -
parsedDn
Parsed LDAP DN. -
normalizedDn
Normalized LDAP DN. -
immutable
private volatile boolean immutableWhether this object has been marked immutable.
-
-
Constructor Details
-
LdapEntry
public LdapEntry()Default constructor. -
LdapEntry
Creates a new search result entry.- Parameters:
buffer- to decode
-
-
Method Details
-
freeze
public void freeze()Description copied from interface:FreezableFreezes this object, making it immutable. -
isFrozen
public final boolean isFrozen()Description copied from interface:FreezableDetermines whether this object is frozen, i.e. immutable.- Specified by:
isFrozenin interfaceFreezable- Returns:
- True if
Freezable.freeze()has been invoked, false otherwise.
-
assertMutable
public final void assertMutable()Description copied from interface:FreezableAsserts that this object is in a state to permit mutations. Classes that implement this interface should invoke this method prior to performing any mutation of internal state as a means of implementing the "frozen" usage contract.- Specified by:
assertMutablein interfaceFreezable
-
getDn
Returns the ldap DN.- Returns:
- ldap DN
-
getParsedDn
Returns the parsed ldap DN. Parsing is performed usingDefaultDnParser.- Returns:
- parsed ldap DN or null if
ldapDnis null or could not be parsed
-
getNormalizedDn
Returns the normalized ldap DN. Normalization is performed usingDefaultRDnNormalizer.- Returns:
- normalized ldap DN or null if
ldapDnis null or could not be parsed
-
setDn
Sets the ldap DN.- Parameters:
dn- ldap DN
-
hasAttribute
Returns whether this entry contains an attribute with the supplied name.- Parameters:
name- of the attribute to match- Returns:
- whether this entry contains an attribute with the supplied name
-
hasAttributeValue
Provides a null safe invocation ofLdapAttribute.hasValue(byte[]).- Parameters:
name- of the attribute containing a valuevalue- to find- Returns:
- whether value exists in the attribute with the supplied name
-
hasAttributeValue
Provides a null safe invocation ofLdapAttribute.hasValue(String).- Parameters:
name- of the attribute containing a valuevalue- to find- Returns:
- whether value exists in the attribute with the supplied name
-
getAttributes
Returns the ldap attributes in this entry. Collection will be immutable ifimmutableis true.- Returns:
- ldap attributes
-
getAttribute
Returns a single attribute of this entry. If multiple attributes exist the first attribute returned by the underlying iterator is used. If no attributes exist null is returned.- Returns:
- single attribute
-
getAttribute
Returns the attribute with the supplied name.- Parameters:
name- of the attribute to return- Returns:
- ldap attribute or null if the attribute does not exist
-
getAttributeValue
Provides a null safe invocation ofLdapAttribute.getValue(Function).- Type Parameters:
T- type of decoded attribute- Parameters:
name- of the attribute whose values should be returnedfunc- to decode attribute value with- Returns:
- single attribute value or null if the attribute does not exist
-
getAttributeValues
Provides a null safe invocation ofLdapAttribute.getValues(Function).- Type Parameters:
T- type of decoded attribute- Parameters:
name- of the attribute whose values should be returnedfunc- to decode attribute value with- Returns:
- collection of attribute values or an empty collection if the attribute does not exist
-
getAttributeBinaryValue
Provides a null safe invocation ofLdapAttribute.getBinaryValue().- Parameters:
name- of the attribute whose values should be returned- Returns:
- single byte array attribute value or null if the attribute does not exist
-
getAttributeBinaryValues
Provides a null safe invocation ofLdapAttribute.getBinaryValues().- Parameters:
name- of the attribute whose values should be returned- Returns:
- collection of byte array attribute values or an empty collection if the attribute does not exist
-
getAttributeStringValue
Provides a null safe invocation ofLdapAttribute.getStringValue().- Parameters:
name- of the attribute whose values should be returned- Returns:
- single string attribute value or null if the attribute does not exist
-
getAttributeStringValues
Provides a null safe invocation ofLdapAttribute.getStringValues().- Parameters:
name- of the attribute whose values should be returned- Returns:
- collection of string attribute values or an empty collection if the attribute does not exist
-
processAttribute
Processes an attribute using the supplied consumer. The consumer is invoked only if the attribute exists.- Parameters:
name- of the attributefunc- to process the attribute if it exists- Returns:
- whether the consumer was invoked
-
mapAttribute
Returns a mapped value from an attribute using the supplied function or null if the attribute doesn't exist.- Type Parameters:
T- type of mapped value- Parameters:
name- of the attributefunc- to map the attribute with- Returns:
- mapped ldap attribute
-
mapAttribute
Returns a mapped value from an attribute using the supplied function or defaultValue if the attribute doesn't exist.- Type Parameters:
T- type of mapped value- Parameters:
name- of the attributefunc- to map the attribute withdefaultValue- to return if no attribute with name exists- Returns:
- mapped ldap attribute
-
getAttributeNames
Returns the attribute names in this entry.- Returns:
- string array of attribute names
-
addAttributes
Adds attributes to the entry. If an attribute with the same name already exists, it is replaced.- Parameters:
attrs- attributes to add
-
addAttributes
Adds attributes to the entry. If an attribute with the same name already exists, it is replaced.- Parameters:
attrs- attributes to add
-
mergeAttributes
Merges attributes into this entry. If an attribute with the same name already exists, the values of the supplied attribute are added to the existing attribute. If the supplied attribute doesn't exist, the attribute is added to this entry.- Parameters:
attrs- attributes to merge
-
mergeAttributes
Merges attributes into this entry. If an attribute with the same name already exists, the values of the supplied attribute are added to the existing attribute. If the supplied attribute doesn't exist, the attribute is added to this entry.- Parameters:
attrs- attributes to merge
-
removeAttribute
Removes the attribute with the supplied name.- Parameters:
name- of attribute to remove
-
removeAttributes
Removes an attribute from this ldap attributes.- Parameters:
attrs- attribute to remove
-
removeAttributes
Removes the attribute(s) from this ldap attributes.- Parameters:
attrs- collection of ldap attributes to remove
-
size
public final int size()Returns the number of attributes.- Returns:
- number of attributes
-
clear
public final void clear()Removes all the attributes from this entry. -
equals
- Overrides:
equalsin classAbstractMessage
-
hashCode
public int hashCode()Description copied from class:AbstractMessageReturns the hash code for this object.- Specified by:
hashCodein classAbstractMessage- Returns:
- hash code
-
toString
- Overrides:
toStringin classAbstractMessage
-
copy
Creates a mutable copy of the supplied entry.- Parameters:
entry- to copy- Returns:
- new ldap entry instance
-
sort
Returns a new entry whose attributes are sorted naturally by name without options.- Parameters:
le- entry to sort- Returns:
- sorted entry
-
computeModifications
Returns the list of attribute modifications needed to change the supplied target entry into the supplied source entry. SeecomputeModifications(LdapEntry, LdapEntry, boolean).- Parameters:
source- ldap entry containing new datatarget- ldap entry containing existing data- Returns:
- attribute modifications needed to change target into source or an empty array
-
computeModifications
public static AttributeModification[] computeModifications(LdapEntry source, LdapEntry target, boolean useReplace) Returns the list of attribute modifications needed to change the supplied target entry into the supplied source entry. This implementation performs a byte comparison on the attribute values to determine changes.- Parameters:
source- ldap entry containing new datatarget- ldap entry containing existing datauseReplace- whether to use a single REPLACE modification or individual ADD/DELETE for attribute values- Returns:
- attribute modifications needed to change target into source or an empty array
-
builder
Creates a builder for this class.- Returns:
- new builder
-