You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by ak...@apache.org on 2007/07/14 03:34:46 UTC
svn commit: r556200 - in
/directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/partition:
DefaultPartitionNexus.java tree/AbstractNode.java tree/BranchNode.java
tree/LeafNode.java tree/Node.java
Author: akarasulu
Date: Fri Jul 13 18:34:45 2007
New Revision: 556200
URL: http://svn.apache.org/viewvc?view=rev&rev=556200
Log:
more cleanup on partition lookup tree structure ...
o remove the AbstractNode since it's utility method is only needed by the
branch node and this left it bare
o removed unneeded methods from LeafNode
o removed and added some methods to BranchNode
o modified the getBackend() method to accomodate changes
Removed:
directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/partition/tree/AbstractNode.java
Modified:
directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/partition/DefaultPartitionNexus.java
directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/partition/tree/BranchNode.java
directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/partition/tree/LeafNode.java
directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/partition/tree/Node.java
Modified: directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/partition/DefaultPartitionNexus.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/partition/DefaultPartitionNexus.java?view=diff&rev=556200&r1=556199&r2=556200
==============================================================================
--- directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/partition/DefaultPartitionNexus.java (original)
+++ directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/partition/DefaultPartitionNexus.java Fri Jul 13 18:34:45 2007
@@ -54,6 +54,7 @@
import org.apache.directory.server.core.interceptor.context.SearchOperationContext;
import org.apache.directory.server.core.partition.impl.btree.MutableBTreePartitionConfiguration;
import org.apache.directory.server.core.partition.impl.btree.jdbm.JdbmPartition;
+import org.apache.directory.server.core.partition.tree.LeafNode;
import org.apache.directory.server.core.partition.tree.Node;
import org.apache.directory.server.core.partition.tree.BranchNode;
import org.apache.directory.server.ldap.constants.SupportedSASLMechanisms;
@@ -126,7 +127,7 @@
private Map<String, Partition> partitions = new HashMap<String, Partition>();
/** A structure to hold all the partitions */
- private Node partitionLookupTree = new BranchNode();
+ private BranchNode partitionLookupTree = new BranchNode();
/** the read only rootDSE attributes */
private final Attributes rootDSE;
@@ -402,7 +403,7 @@
{
partitions.put( key, system );
- partitionLookupTree.buildNode( partitionLookupTree, system.getSuffix(), 0, system );
+ partitionLookupTree.recursivelyAddPartition( partitionLookupTree, system.getSuffix(), 0, system );
Attribute namingContexts = rootDSE.get( NAMINGCTXS_ATTR );
namingContexts.add( system.getUpSuffix().getUpName() );
@@ -580,7 +581,7 @@
{
partitions.put( partition.getSuffix().toString(), partition );
- partitionLookupTree.buildNode( partitionLookupTree, partition.getSuffix(), 0, partition );
+ partitionLookupTree.recursivelyAddPartition( partitionLookupTree, partition.getSuffix(), 0, partition );
Attribute namingContexts = rootDSE.get( NAMINGCTXS_ATTR );
namingContexts.add( partition.getUpSuffix().getUpName() );
@@ -613,7 +614,7 @@
for ( Partition part:partitions.values() )
{
- partitionLookupTree.buildNode( partitionLookupTree, part.getSuffix(), 0, partition );
+ partitionLookupTree.recursivelyAddPartition( partitionLookupTree, part.getSuffix(), 0, partition );
}
partition.sync();
@@ -1046,19 +1047,26 @@
while ( rdns.hasMoreElements() )
{
String rdn = rdns.nextElement();
+
+ if ( currentNode == null )
+ {
+ break;
+ }
- if ( currentNode.contains( rdn ) )
+ if ( currentNode instanceof LeafNode )
{
- currentNode = currentNode.getChildOrThis( rdn );
-
- if ( currentNode.isLeaf() )
- {
- return currentNode.getPartition();
- }
+ return ( ( LeafNode ) currentNode ).getPartition();
}
- else
+
+ BranchNode currentBranch = ( BranchNode ) currentNode;
+ if ( currentBranch.contains( rdn ) )
{
- break;
+ currentNode = currentBranch.getChild( rdn );
+
+ if ( currentNode instanceof LeafNode )
+ {
+ return ( ( LeafNode ) currentNode ).getPartition();
+ }
}
}
}
Modified: directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/partition/tree/BranchNode.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/partition/tree/BranchNode.java?view=diff&rev=556200&r1=556199&r2=556200
==============================================================================
--- directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/partition/tree/BranchNode.java (original)
+++ directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/partition/tree/BranchNode.java Fri Jul 13 18:34:45 2007
@@ -19,10 +19,13 @@
*/
package org.apache.directory.server.core.partition.tree;
+
import java.util.HashMap;
import java.util.Map;
import org.apache.directory.server.core.partition.Partition;
+import org.apache.directory.shared.ldap.name.LdapDN;
+
/**
*
@@ -33,18 +36,18 @@
*
* @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
*/
-public class BranchNode extends AbstractNode
+public class BranchNode implements Node
{
/** Stores the list of all the descendant partitions and containers */
private Map<String, Node> children;
/**
- * Creates a new instance of PartitionContainer.
+ * Creates a new instance of a BranchNode.
*/
public BranchNode()
{
- children = new HashMap<String, Node>();
+ children = new HashMap<String, Node>(3);
}
@@ -58,48 +61,73 @@
/**
- * @see Node#addNode( String, Node )
+ * Recursively adds new nodes to the partition lookup tree data structure.
+ * When called it will add a partition to the tree in the appropriate leaf
+ * node position based on the DN passed in as an argument.
+ *
+ * @param current The current node having a partition added to it
+ * @param dn The DN associated with the partition
+ * @param index The index of the current RDN being processed
+ * @param partition The associated partition to add as a tree node
+ * @return The modified tree structure.
*/
- public Node addNode( String name, Node child )
+ public BranchNode recursivelyAddPartition( BranchNode current, LdapDN dn, int index, Partition partition )
{
- children.put( name, child );
- return this;
+ String rdnAtIndex = dn.getRdn( index ).toString();
+
+ if ( index == dn.size() - 1 )
+ {
+ return current.addNode( rdnAtIndex, new LeafNode( partition ) );
+ }
+ else
+ {
+ Node child = recursivelyAddPartition( new BranchNode(), dn, index + 1, partition );
+ return current.addNode( rdnAtIndex, child );
+ }
}
/**
- * @see Node#contains( String )
+ * Directly adds a new child Node to the current BranchNode.
+ *
+ * @param rdn The rdn of the child node to add
+ * @param child The child node to add
+ * @return The modified branch node after the insertion
*/
- public boolean contains( String name )
+ public BranchNode addNode( String rdn, Node child )
{
- return children.containsKey( name );
+ children.put( rdn, child );
+ return this;
}
/**
- * @see Node#getPartition()
- *
- * As this is a container, we just return null;
+ * Tells if the current BranchNode contains another node associated
+ * with an rdn.
+ *
+ * @param rdn The name we are looking for
+ * @return <code>true</code> if the PartitionStructure instance contains this name
*/
- public Partition getPartition()
+ public boolean contains( String rdn )
{
- return null;
+ return children.containsKey( rdn );
}
/**
- * @see Node#getChildOrThis( String )
+ * Get's a child using an rdn string.
+ *
+ * @param the rdn to use as the node key
+ * @return the child node corresponding to the rdn.
*/
- public Node getChildOrThis( String name )
+ public Node getChild( String rdn )
{
- if ( children.containsKey( name ) )
- {
- return children.get( name );
- }
- else
+ if ( children.containsKey( rdn ) )
{
- return null;
+ return children.get( rdn );
}
+
+ return null;
}
@@ -109,9 +137,7 @@
public String toString()
{
StringBuilder sb = new StringBuilder();
-
sb.append( " { " );
-
boolean isFirst = true;
for ( Node child:children.values() )
@@ -136,7 +162,6 @@
}
sb.append( " } " );
-
return sb.toString();
}
}
Modified: directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/partition/tree/LeafNode.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/partition/tree/LeafNode.java?view=diff&rev=556200&r1=556199&r2=556200
==============================================================================
--- directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/partition/tree/LeafNode.java (original)
+++ directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/partition/tree/LeafNode.java Fri Jul 13 18:34:45 2007
@@ -30,7 +30,7 @@
*
* @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
*/
-public class LeafNode extends AbstractNode
+public class LeafNode implements Node
{
/** The stored partition */
private Partition partition;
@@ -55,61 +55,13 @@
return true;
}
-
- /**
- * @see Node#contains( String )
- */
- public boolean contains( String name )
- {
- try
- {
- return partition.getSuffix().getNormName().equals( name );
- }
- catch ( NamingException ne )
- {
- return false;
- }
- }
-
/**
- * @see Node#addNode( String, Node )
- */
- public Node addNode( String name, Node partition )
- {
- return this;
- }
-
-
- /**
* @see Node#getPartition()
*/
public Partition getPartition()
{
return partition;
- }
-
-
- /**
- * @see Node#getChildOrThis( String )
- */
- public Node getChildOrThis( String name )
- {
- try
- {
- if ( partition.getSuffix().getNormName().equals( name ) )
- {
- return this;
- }
- else
- {
- return null;
- }
- }
- catch ( NamingException ne )
- {
- return null;
- }
}
Modified: directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/partition/tree/Node.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/partition/tree/Node.java?view=diff&rev=556200&r1=556199&r2=556200
==============================================================================
--- directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/partition/tree/Node.java (original)
+++ directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/partition/tree/Node.java Fri Jul 13 18:34:45 2007
@@ -20,10 +20,6 @@
package org.apache.directory.server.core.partition.tree;
-import org.apache.directory.server.core.partition.Partition;
-import org.apache.directory.shared.ldap.name.LdapDN;
-
-
/**
* An interface for nodes in a tree designed to quickly lookup partitions.
* Branch nodes in this tree contain other nodes. Leaf nodes in the tree
@@ -41,55 +37,4 @@
* @return <code>true</code> if the class is a leaf node, false otherwise.
*/
boolean isLeaf();
-
- /**
- * Add a new Partition to the current container.
- *
- * @param name The partition name
- * @param children The PartitionStructure object (it should be a PartitionHandler)
- * @return The current PartitionStructure to which a Partition has been added.
- */
- Node addNode( String name, Node children );
-
- /**
- * Tells if the current PartitionStructure contains the given partition.
- *
- * If the PartitionStructure is an instance of PartitionHandler, returns true
- * if the partition's name equals the given name.
- *
- * If the PartitionStructure is an instance of PartitionContainer, returns true
- * if the container's children contains the given name.
- *
- * @param name The name we are looking for
- * @return <code>true</code> if the PartitionStructure instance contains this name
- */
- boolean contains( String name );
-
- /**
- * Returns the Partition associated with this name, if any, or null if the name is not
- * found
- *
- * @param name The name we are looking for
- * @return The associated PartitionHandler or PartitionContainer
- */
- Node getChildOrThis( String name );
-
- /**
- * @return Get the partition if the object is an instance of PartitionHandler, null otherwise
- */
- Partition getPartition();
-
- /**
- * Construct the global partition structure, assuming the DN passed as an argument is a partition
- * name.
- *
- * This is a recursive method.
- *
- * @param current The current structure
- * @param dn The DN associated with the partition
- * @param index The current RDN being processed
- * @param partition The associated partition
- * @return The modified global structure.
- */
- Node buildNode( Node current, LdapDN dn, int index, Partition partition );
}