Class DnNode<N>

  • Type Parameters:
    N - The type of node we store

    public class DnNode<N>
    extends Object
    A class storing nodes in a tree designed to map DNs.
    Branch nodes in this tree refers to child nodes. Leaf nodes in the tree don't have any children.
    A node may contain a reference to an object whose suffix is the path through the nodes of the tree from the root.
    A node may also have no attached element.
    Each child node is referenced by a Rdn, and holds the full Dn corresponding to its position
    Author:
    Apache Directory Project
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private Map<String,​DnNode<N>> children
      Stores the list of all the descendant
      private int depth
      The node's depth in the tree
      private static org.slf4j.Logger LOG
      The logger for this class
      private org.apache.directory.api.ldap.model.name.Dn nodeDn
      The node's Dn
      private N nodeElement
      The stored element
      private org.apache.directory.api.ldap.model.name.Rdn nodeRdn
      The node's key
      private DnNode<N> parent
      The parent, if any
    • Constructor Summary

      Constructors 
      Constructor Description
      DnNode()
      Creates a new instance of DnNode.
      DnNode​(N element)
      Creates a new instance of DnNode.
      DnNode​(org.apache.directory.api.ldap.model.name.Dn dn, N element)
      Creates a new instance of DnNode.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      DnNode<N> add​(org.apache.directory.api.ldap.model.name.Dn dn)
      Add a new node in the tree.
      DnNode<N> add​(org.apache.directory.api.ldap.model.name.Dn dn, N element)
      Add a new node in the tree.
      private void checkDn​(org.apache.directory.api.ldap.model.name.Dn dn)
      Check that the Dn is not null
      boolean contains​(org.apache.directory.api.ldap.model.name.Rdn rdn)
      Tells if the current DnBranchNode contains another node associated with an rdn.
      private DnNode<N> createNode​(org.apache.directory.api.ldap.model.name.Dn dn, N element, int nbRdns)
      Create a new DnNode, recursively creating all the intermediate nodes.
      DnNode<N> getChild​(org.apache.directory.api.ldap.model.name.Rdn rdn)
      Get's a child using an rdn string.
      Map<String,​DnNode<N>> getChildren()  
      List<N> getDescendantElements​(org.apache.directory.api.ldap.model.name.Dn dn)  
      private void getDescendantElements​(DnNode<N> node, List<N> descendants)
      Recursively get all the elements from nodes having an element
      org.apache.directory.api.ldap.model.name.Dn getDn()  
      N getElement()  
      N getElement​(org.apache.directory.api.ldap.model.name.Dn dn)  
      DnNode<N> getNode​(org.apache.directory.api.ldap.model.name.Dn dn)
      Get the Node for a given Dn, if present in the tree.
      For instance, if we have stored dc=acme, dc=org into the tree, the Dn: ou=example, dc=acme, dc=org will have a parent, and dc=acme, dc=org will be returned.
      DnNode<N> getParent()  
      DnNode<N> getParentWithElement()
      Get the closest Node for a given Dn which has an element, if present in the tree.
      For instance, if we have stored dc=acme, dc=org into the tree, the Dn: ou=example, dc=acme, dc=org will have a parent, and dc=acme, dc=org will be returned if it has an associated element.
      DnNode<N> getParentWithElement​(org.apache.directory.api.ldap.model.name.Dn dn)
      Get the closest Node for a given Dn which has an element, if present in the tree.
      For instance, if we have stored dc=acme, dc=org into the tree, the Dn: ou=example, dc=acme, dc=org will have a parent, and dc=acme, dc=org will be returned if it has an associated element.
      org.apache.directory.api.ldap.model.name.Rdn getRdn()  
      boolean hasChildren()
      Tells if the current DnNode has some children or not
      boolean hasChildren​(org.apache.directory.api.ldap.model.name.Dn dn)
      Tells if a node has some children or not.
      boolean hasDescendantElement​(org.apache.directory.api.ldap.model.name.Dn dn)  
      private boolean hasDescendantElement​(DnNode<N> node)
      Recursively check if the node has a descendant having an element
      boolean hasElement()  
      boolean hasElement​(org.apache.directory.api.ldap.model.name.Dn dn)  
      boolean hasParent()  
      boolean hasParent​(org.apache.directory.api.ldap.model.name.Dn dn)
      Tells if there is a parent for a given Dn,.
      boolean hasParentElement​(org.apache.directory.api.ldap.model.name.Dn dn)
      Get the closest Node for a given Dn which has an element, if present in the tree.
      For instance, if we have stored dc=acme, dc=org into the tree, the Dn: ou=example, dc=acme, dc=org will have a parent, and dc=acme, dc=org will be returned if it has an associated element.
      boolean isLeaf()
      Tells if the implementation is a leaf node.
      boolean isLeaf​(org.apache.directory.api.ldap.model.name.Dn dn)
      Tells if the implementation is a leaf node.
      void move​(org.apache.directory.api.ldap.model.name.Dn newParent)
      move the DnNode's Dn
      void remove​(org.apache.directory.api.ldap.model.name.Dn dn)
      Removes a node from the tree.
      void rename​(org.apache.directory.api.ldap.model.name.Rdn newRdn)
      rename the DnNode's Dn
      void setElement​(N element)
      Store the given element into the node
      int size()
      Returns the number of entries under this node.
      String toString()
      private String toString​(String tabs)  
      private void updateAfterModDn​(org.apache.directory.api.ldap.model.name.Dn newParentDn)
      update the children's Dn based on the new parent Dn created after a rename or move operation
    • Field Detail

      • LOG

        private static final org.slf4j.Logger LOG
        The logger for this class
      • nodeElement

        private N nodeElement
        The stored element
      • nodeRdn

        private org.apache.directory.api.ldap.model.name.Rdn nodeRdn
        The node's key
      • nodeDn

        private org.apache.directory.api.ldap.model.name.Dn nodeDn
        The node's Dn
      • depth

        private int depth
        The node's depth in the tree
      • parent

        private DnNode<N> parent
        The parent, if any
      • children

        private Map<String,​DnNode<N>> children
        Stores the list of all the descendant
    • Constructor Detail

      • DnNode

        public DnNode()
        Creates a new instance of DnNode.
      • DnNode

        public DnNode​(N element)
        Creates a new instance of DnNode.
        Parameters:
        element - the element to store
      • DnNode

        public DnNode​(org.apache.directory.api.ldap.model.name.Dn dn,
                      N element)
        Creates a new instance of DnNode.
        Parameters:
        dn - the node's Dn
        element - the element to store
    • Method Detail

      • checkDn

        private void checkDn​(org.apache.directory.api.ldap.model.name.Dn dn)
                      throws org.apache.directory.api.ldap.model.exception.LdapException
        Check that the Dn is not null
        Parameters:
        dn - The Dn to check
        Throws:
        org.apache.directory.api.ldap.model.exception.LdapException - If teh Dn is null or empty
      • createNode

        private DnNode<N> createNode​(org.apache.directory.api.ldap.model.name.Dn dn,
                                     N element,
                                     int nbRdns)
                              throws org.apache.directory.api.ldap.model.exception.LdapException
        Create a new DnNode, recursively creating all the intermediate nodes.
        Parameters:
        dn - The nod's Dn
        element - The element to set
        nbRdns - The number of RDNs in the Dn
        nbRdns - The number of level to create
        Returns:
        The created Node
        Throws:
        org.apache.directory.api.ldap.model.exception.LdapException - If the Dn is null or empty
      • setElement

        public void setElement​(N element)
        Store the given element into the node
        Parameters:
        element - The element to set
      • isLeaf

        public boolean isLeaf()
        Tells if the implementation is a leaf node. If it's a branch node then false is returned.
        Returns:
        true if the class is a leaf node, false otherwise.
      • isLeaf

        public boolean isLeaf​(org.apache.directory.api.ldap.model.name.Dn dn)
        Tells if the implementation is a leaf node. If it's a branch node then false is returned.
        Parameters:
        dn - The Dn we want to check
        Returns:
        true if this is a leaf node, false otherwise.
      • size

        public int size()
        Returns the number of entries under this node. It includes the node itself, plus the number of all it children and descendants.
        Returns:
        The number of descendents
      • getElement

        public N getElement()
        Returns:
        Return the stored element, if any
      • getElement

        public N getElement​(org.apache.directory.api.ldap.model.name.Dn dn)
        Parameters:
        dn - The Dn we want to get the element for
        Returns:
        Return the stored element, if any
      • hasElement

        public boolean hasElement()
        Returns:
        True if the Node stores an element. BranchNode may not hold any element.
      • hasElement

        public boolean hasElement​(org.apache.directory.api.ldap.model.name.Dn dn)
        Parameters:
        dn - The Dn we want to get the element for
        Returns:
        True if the Node stores an element. BranchNode may not hold any element.
      • hasDescendantElement

        private boolean hasDescendantElement​(DnNode<N> node)
        Recursively check if the node has a descendant having an element
        Parameters:
        node - The node to start from
        Returns:
        true if the node has some descendant
      • hasDescendantElement

        public boolean hasDescendantElement​(org.apache.directory.api.ldap.model.name.Dn dn)
        Parameters:
        dn - The Dn we want to get the element for
        Returns:
        True if one of the node below the current node has one element, False otherwise
      • getDescendantElements

        private void getDescendantElements​(DnNode<N> node,
                                           List<N> descendants)
        Recursively get all the elements from nodes having an element
        Parameters:
        node - The node to start with
        descendants - The list of descendant to fulfill
      • getDescendantElements

        public List<N> getDescendantElements​(org.apache.directory.api.ldap.model.name.Dn dn)
        Parameters:
        dn - The Dn we want to get the element for
        Returns:
        True if one of the node below the current node has one element, False otherwise
      • hasChildren

        public boolean hasChildren()
        Tells if the current DnNode has some children or not
        Returns:
        true if the node has some children
      • hasChildren

        public boolean hasChildren​(org.apache.directory.api.ldap.model.name.Dn dn)
                            throws org.apache.directory.api.ldap.model.exception.LdapException
        Tells if a node has some children or not.
        Parameters:
        dn - the node's Dn
        Returns:
        true if the node has some children
        Throws:
        org.apache.directory.api.ldap.model.exception.LdapException - if the Dn is null or empty
      • getChildren

        public Map<String,​DnNode<N>> getChildren()
        Returns:
        The list of DnNode
      • getParent

        public DnNode<N> getParent()
        Returns:
        The parent DnNode, if any
      • hasParent

        public boolean hasParent()
        Returns:
        True if the current DnNode has a parent
      • hasParent

        public boolean hasParent​(org.apache.directory.api.ldap.model.name.Dn dn)
        Tells if there is a parent for a given Dn,. This parent should be a subset of the given dn.
        For instance, if we have stored dc=acme, dc=org into the tree, the Dn: ou=example, dc=acme, dc=org will have a parent
        For the Dn ou=apache, dc=org, there is no parent, so false will be returned.
        Parameters:
        dn - the normalized distinguished name to resolve to a parent
        Returns:
        true if there is a parent associated with the normalized dn
      • add

        public DnNode<N> add​(org.apache.directory.api.ldap.model.name.Dn dn)
                      throws org.apache.directory.api.ldap.model.exception.LdapException
        Add a new node in the tree. The added node won't have any element.
        Parameters:
        dn - The node's Dn
        Returns:
        the corresponding node
        Throws:
        org.apache.directory.api.ldap.model.exception.LdapException - if the Dn is null or empty
      • add

        public DnNode<N> add​(org.apache.directory.api.ldap.model.name.Dn dn,
                             N element)
                      throws org.apache.directory.api.ldap.model.exception.LdapException
        Add a new node in the tree. We can't add a node if its Dn is empty. The added element is attached to the node, which is named by the Dn's Rdn.
        Parameters:
        dn - The node's Dn
        element - The element to associate with this Node. Can be null.
        Returns:
        the corresponding node
        Throws:
        org.apache.directory.api.ldap.model.exception.LdapException - if the Dn is null or empty
      • remove

        public void remove​(org.apache.directory.api.ldap.model.name.Dn dn)
                    throws org.apache.directory.api.ldap.model.exception.LdapException
        Removes a node from the tree.
        Parameters:
        dn - the node's Dn
        Throws:
        org.apache.directory.api.ldap.model.exception.LdapException - if the Dn is null or empty
      • contains

        public boolean contains​(org.apache.directory.api.ldap.model.name.Rdn rdn)
        Tells if the current DnBranchNode contains another node associated with an rdn.
        Parameters:
        rdn - The name we are looking for
        Returns:
        true if the tree instance contains this name
      • getChild

        public DnNode<N> getChild​(org.apache.directory.api.ldap.model.name.Rdn rdn)
        Get's a child using an rdn string.
        Parameters:
        rdn - the rdn to use as the node key
        Returns:
        the child node corresponding to the rdn.
      • getRdn

        public org.apache.directory.api.ldap.model.name.Rdn getRdn()
        Returns:
        The Node's Rdn
      • getNode

        public DnNode<N> getNode​(org.apache.directory.api.ldap.model.name.Dn dn)
        Get the Node for a given Dn, if present in the tree.
        For instance, if we have stored dc=acme, dc=org into the tree, the Dn: ou=example, dc=acme, dc=org will have a parent, and dc=acme, dc=org will be returned.
        For the Dn ou=apache, dc=org, there is no parent, so null will be returned.
        Parameters:
        dn - the normalized distinguished name to resolve to a parent
        Returns:
        the Node associated with the normalized dn
      • hasParentElement

        public boolean hasParentElement​(org.apache.directory.api.ldap.model.name.Dn dn)
        Get the closest Node for a given Dn which has an element, if present in the tree.
        For instance, if we have stored dc=acme, dc=org into the tree, the Dn: ou=example, dc=acme, dc=org will have a parent, and dc=acme, dc=org will be returned if it has an associated element.
        For the Dn ou=apache, dc=org, there is no parent, so null will be returned.
        Parameters:
        dn - the normalized distinguished name to resolve to a parent
        Returns:
        the Node associated with the normalized dn
      • getParentWithElement

        public DnNode<N> getParentWithElement​(org.apache.directory.api.ldap.model.name.Dn dn)
        Get the closest Node for a given Dn which has an element, if present in the tree.
        For instance, if we have stored dc=acme, dc=org into the tree, the Dn: ou=example, dc=acme, dc=org will have a parent, and dc=acme, dc=org will be returned if it has an associated element.
        For the Dn ou=apache, dc=org, there is no parent, so null will be returned.
        Parameters:
        dn - the normalized distinguished name to resolve to a parent
        Returns:
        the Node associated with the normalized dn
      • getParentWithElement

        public DnNode<N> getParentWithElement()
        Get the closest Node for a given Dn which has an element, if present in the tree.
        For instance, if we have stored dc=acme, dc=org into the tree, the Dn: ou=example, dc=acme, dc=org will have a parent, and dc=acme, dc=org will be returned if it has an associated element.
        For the Dn ou=apache, dc=org, there is no parent, so null will be returned.
        Returns:
        the Node associated with the normalized dn
      • rename

        public void rename​(org.apache.directory.api.ldap.model.name.Rdn newRdn)
                    throws org.apache.directory.api.ldap.model.exception.LdapException
        rename the DnNode's Dn
        Parameters:
        newRdn - the new Rdn of this node
        Throws:
        org.apache.directory.api.ldap.model.exception.LdapException - If the rename failed
      • move

        public void move​(org.apache.directory.api.ldap.model.name.Dn newParent)
                  throws org.apache.directory.api.ldap.model.exception.LdapException
        move the DnNode's Dn
        Parameters:
        newParent - the new parent Dn
        Throws:
        org.apache.directory.api.ldap.model.exception.LdapException - If the move failed
      • updateAfterModDn

        private void updateAfterModDn​(org.apache.directory.api.ldap.model.name.Dn newParentDn)
                               throws org.apache.directory.api.ldap.model.exception.LdapInvalidDnException
        update the children's Dn based on the new parent Dn created after a rename or move operation
        Parameters:
        newParentDn - The new parent's Dn
        Throws:
        org.apache.directory.api.ldap.model.exception.LdapInvalidDnException - The parent DN is invalid
      • getDn

        public org.apache.directory.api.ldap.model.name.Dn getDn()
        Returns:
        the dn