You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by el...@apache.org on 2008/09/22 12:29:52 UTC
svn commit: r697775 - in /directory:
apacheds/trunk/core/src/main/java/org/apache/directory/server/core/partition/DefaultPartitionNexus.java
shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/util/tree/DnBranchNode.java
Author: elecharny
Date: Mon Sep 22 03:29:51 2008
New Revision: 697775
URL: http://svn.apache.org/viewvc?rev=697775&view=rev
Log:
o Added a hasParent method
o Modified the getParentElement method which does not throw an exception anymore
Modified:
directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/partition/DefaultPartitionNexus.java
directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/util/tree/DnBranchNode.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?rev=697775&r1=697774&r2=697775&view=diff
==============================================================================
--- 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 Mon Sep 22 03:29:51 2008
@@ -1056,7 +1056,16 @@
*/
public Partition getPartition( LdapDN dn ) throws Exception
{
- return partitionLookupTree.getElement( dn );
+ Partition parent = partitionLookupTree.getParentElement( dn );
+
+ if ( parent == null )
+ {
+ throw new LdapNameNotFoundException( " Cannot find a partition for " + dn );
+ }
+ else
+ {
+ return parent;
+ }
}
Modified: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/util/tree/DnBranchNode.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/util/tree/DnBranchNode.java?rev=697775&r1=697774&r2=697775&view=diff
==============================================================================
--- directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/util/tree/DnBranchNode.java (original)
+++ directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/util/tree/DnBranchNode.java Mon Sep 22 03:29:51 2008
@@ -26,7 +26,6 @@
import javax.naming.NamingException;
-import org.apache.directory.shared.ldap.exception.LdapNameNotFoundException;
import org.apache.directory.shared.ldap.name.LdapDN;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -188,13 +187,18 @@
/**
- * Gets the partition associated with a normalized dn.
+ * Get the parent of a given DN, if present in the tree. This parent should be a
+ * subset of the given dn.<br>
+ * 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.
+ * <br>For the DN ou=apache, dc=org, there is no parent, so null will be returned.
+ *
*
- * @param dn the normalized distinguished name to resolve to a partition
- * @return the backend partition associated with the normalized dn
- * @throws Exception if the name cannot be resolved to a partition
+ * @param dn the normalized distinguished name to resolve to a parent
+ * @return the parent associated with the normalized dn
*/
- public N getElement( LdapDN dn ) throws Exception
+ public N getParentElement( LdapDN dn )
{
Enumeration<String> rdns = dn.getAll();
@@ -233,6 +237,58 @@
}
}
- throw new LdapNameNotFoundException( dn.getUpName() );
+ return null;
+ }
+
+
+ /**
+ * Tells if the DN contains a parent in the tree. This parent should be a
+ * subset of the given dn.<br>
+ * 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.
+ *
+ * @param dn the normalized distinguished name to resolve to a parent
+ * @return the parent associated with the normalized dn
+ */
+ public boolean hasParentElement( LdapDN dn )
+ {
+ Enumeration<String> rdns = dn.getAll();
+
+ // This is synchronized so that we can't read the
+ // partitionList when it is modified.
+ synchronized ( this )
+ {
+ DnNode<N> currentNode = this;
+
+ // Iterate through all the RDN until we find the associated partition
+ while ( rdns.hasMoreElements() )
+ {
+ String rdn = rdns.nextElement();
+
+ if ( currentNode == null )
+ {
+ return false;
+ }
+
+ if ( currentNode instanceof DnLeafNode )
+ {
+ return true;
+ }
+
+ DnBranchNode<N> currentBranch = ( DnBranchNode<N> ) currentNode;
+
+ if ( currentBranch.contains( rdn ) )
+ {
+ currentNode = currentBranch.getChild( rdn );
+
+ if ( currentNode instanceof DnLeafNode )
+ {
+ return true;
+ }
+ }
+ }
+ }
+
+ return false;
}
}