Package org.ldaptive

Class LdapEntry

  • All Implemented Interfaces:
    Freezable, Message

    public class LdapEntry
    extends AbstractMessage
    implements Freezable
    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 }
     
    • Field Detail

      • HASH_CODE_SEED

        private static final int HASH_CODE_SEED
        hash code seed.
        See Also:
        Constant Field Values
      • LDAP_DN_PATH

        private static final DERPath LDAP_DN_PATH
        DER path to LDAP DN.
      • ATTRIBUTES_PATH

        private static final DERPath ATTRIBUTES_PATH
        DER path to attributes.
      • ldapDn

        private String ldapDn
        LDAP DN of the entry.
      • parsedDn

        private Dn parsedDn
        Parsed LDAP DN.
      • normalizedDn

        private String normalizedDn
        Normalized LDAP DN.
      • immutable

        private volatile boolean immutable
        Whether this object has been marked immutable.
    • Constructor Detail

      • LdapEntry

        public LdapEntry()
        Default constructor.
      • LdapEntry

        public LdapEntry​(DERBuffer buffer)
        Creates a new search result entry.
        Parameters:
        buffer - to decode
    • Method Detail

      • freeze

        public void freeze()
        Description copied from interface: Freezable
        Freezes this object, making it immutable.
        Specified by:
        freeze in interface Freezable
      • isFrozen

        public final boolean isFrozen()
        Description copied from interface: Freezable
        Determines whether this object is frozen, i.e. immutable.
        Specified by:
        isFrozen in interface Freezable
        Returns:
        True if Freezable.freeze() has been invoked, false otherwise.
      • assertMutable

        public final void assertMutable()
        Description copied from interface: Freezable
        Asserts 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:
        assertMutable in interface Freezable
      • getDn

        public final String getDn()
        Returns the ldap DN.
        Returns:
        ldap DN
      • getParsedDn

        public final Dn getParsedDn()
        Returns the parsed ldap DN. Parsing is performed using DefaultDnParser.
        Returns:
        parsed ldap DN or null if ldapDn is null or could not be parsed
      • getNormalizedDn

        public final String getNormalizedDn()
        Returns the normalized ldap DN. Normalization is performed using DefaultRDnNormalizer.
        Returns:
        normalized ldap DN or null if ldapDn is null or could not be parsed
      • setDn

        public final void setDn​(String dn)
        Sets the ldap DN.
        Parameters:
        dn - ldap DN
      • hasAttribute

        public boolean hasAttribute​(String name)
        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

        public boolean hasAttributeValue​(String name,
                                         byte[] value)
        Provides a null safe invocation of LdapAttribute.hasValue(byte[]).
        Parameters:
        name - of the attribute containing a value
        value - to find
        Returns:
        whether value exists in the attribute with the supplied name
      • hasAttributeValue

        public boolean hasAttributeValue​(String name,
                                         String value)
        Provides a null safe invocation of LdapAttribute.hasValue(String).
        Parameters:
        name - of the attribute containing a value
        value - to find
        Returns:
        whether value exists in the attribute with the supplied name
      • getAttributes

        public Collection<LdapAttribute> getAttributes()
        Returns the ldap attributes in this entry. Collection will be immutable if immutable is true.
        Returns:
        ldap attributes
      • getAttribute

        public LdapAttribute 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

        public LdapAttribute getAttribute​(String name)
        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
      • getAttributeBinaryValue

        public byte[] getAttributeBinaryValue​(String name)
        Provides a null safe invocation of LdapAttribute.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

        public Collection<byte[]> getAttributeBinaryValues​(String name)
        Provides a null safe invocation of LdapAttribute.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

        public String getAttributeStringValue​(String name)
        Provides a null safe invocation of LdapAttribute.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

        public Collection<String> getAttributeStringValues​(String name)
        Provides a null safe invocation of LdapAttribute.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

        public boolean processAttribute​(String name,
                                        Consumer<LdapAttribute> func)
        Processes an attribute using the supplied consumer. The consumer is invoked only if the attribute exists.
        Parameters:
        name - of the attribute
        func - to process the attribute if it exists
        Returns:
        whether the consumer was invoked
      • mapAttribute

        public <T> T mapAttribute​(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.
        Type Parameters:
        T - type of mapped value
        Parameters:
        name - of the attribute
        func - to map the attribute with
        Returns:
        mapped ldap attribute
      • mapAttribute

        public <T> T mapAttribute​(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.
        Type Parameters:
        T - type of mapped value
        Parameters:
        name - of the attribute
        func - to map the attribute with
        defaultValue - to return if no attribute with name exists
        Returns:
        mapped ldap attribute
      • getAttributeNames

        public String[] getAttributeNames()
        Returns the attribute names in this entry.
        Returns:
        string array of attribute names
      • addAttributes

        public void addAttributes​(LdapAttribute... attrs)
        Adds attributes to the entry. If an attribute with the same name already exists, it is replaced.
        Parameters:
        attrs - attributes to add
      • addAttributes

        public void addAttributes​(Collection<LdapAttribute> attrs)
        Adds attributes to the entry. If an attribute with the same name already exists, it is replaced.
        Parameters:
        attrs - attributes to add
      • mergeAttributes

        public void mergeAttributes​(LdapAttribute... attrs)
        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

        public void mergeAttributes​(Collection<LdapAttribute> attrs)
        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

        public void removeAttribute​(String name)
        Removes the attribute with the supplied name.
        Parameters:
        name - of attribute to remove
      • removeAttributes

        public void removeAttributes​(LdapAttribute... attrs)
        Removes an attribute from this ldap attributes.
        Parameters:
        attrs - attribute to remove
      • removeAttributes

        public void removeAttributes​(Collection<LdapAttribute> attrs)
        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.
      • hashCode

        public int hashCode()
        Description copied from class: AbstractMessage
        Returns the hash code for this object.
        Specified by:
        hashCode in class AbstractMessage
        Returns:
        hash code
      • copy

        public static LdapEntry copy​(LdapEntry entry)
        Creates a mutable copy of the supplied entry.
        Parameters:
        entry - to copy
        Returns:
        new ldap entry instance
      • sort

        public static LdapEntry sort​(LdapEntry le)
        Returns a new entry whose attributes are sorted naturally by name without options.
        Parameters:
        le - entry to sort
        Returns:
        sorted entry
      • computeModifications

        public 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. See computeModifications(LdapEntry, LdapEntry, boolean).
        Parameters:
        source - ldap entry containing new data
        target - 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 data
        target - ldap entry containing existing data
        useReplace - 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

        public static LdapEntry.Builder builder()
        Creates a builder for this class.
        Returns:
        new builder