Return-Path: Delivered-To: apmail-directory-commits-archive@www.apache.org Received: (qmail 80231 invoked from network); 18 Jul 2010 20:40:38 -0000 Received: from unknown (HELO mail.apache.org) (140.211.11.3) by 140.211.11.9 with SMTP; 18 Jul 2010 20:40:38 -0000 Received: (qmail 71180 invoked by uid 500); 18 Jul 2010 20:40:38 -0000 Delivered-To: apmail-directory-commits-archive@directory.apache.org Received: (qmail 71126 invoked by uid 500); 18 Jul 2010 20:40:38 -0000 Mailing-List: contact commits-help@directory.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@directory.apache.org Delivered-To: mailing list commits@directory.apache.org Received: (qmail 71119 invoked by uid 99); 18 Jul 2010 20:40:38 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 18 Jul 2010 20:40:38 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 18 Jul 2010 20:40:35 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 300672388A2C; Sun, 18 Jul 2010 20:39:42 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r965282 - /directory/apacheds/branches/apacheds-subtree/core/src/main/java/org/apache/directory/server/core/subtree/SubtreeEvaluator.java Date: Sun, 18 Jul 2010 20:39:42 -0000 To: commits@directory.apache.org From: elecharny@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20100718203942.300672388A2C@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: elecharny Date: Sun Jul 18 20:39:41 2010 New Revision: 965282 URL: http://svn.apache.org/viewvc?rev=965282&view=rev Log: Sligth optimization of the subtree evaluator. Modified: directory/apacheds/branches/apacheds-subtree/core/src/main/java/org/apache/directory/server/core/subtree/SubtreeEvaluator.java Modified: directory/apacheds/branches/apacheds-subtree/core/src/main/java/org/apache/directory/server/core/subtree/SubtreeEvaluator.java URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-subtree/core/src/main/java/org/apache/directory/server/core/subtree/SubtreeEvaluator.java?rev=965282&r1=965281&r2=965282&view=diff ============================================================================== --- directory/apacheds/branches/apacheds-subtree/core/src/main/java/org/apache/directory/server/core/subtree/SubtreeEvaluator.java (original) +++ directory/apacheds/branches/apacheds-subtree/core/src/main/java/org/apache/directory/server/core/subtree/SubtreeEvaluator.java Sun Jul 18 20:39:41 2010 @@ -20,8 +20,6 @@ package org.apache.directory.server.core.subtree; -import java.util.Iterator; - import org.apache.directory.server.core.event.Evaluator; import org.apache.directory.server.core.event.ExpressionEvaluator; import org.apache.directory.shared.ldap.entry.Entry; @@ -29,7 +27,6 @@ import org.apache.directory.shared.ldap. import org.apache.directory.shared.ldap.name.DN; import org.apache.directory.shared.ldap.schema.SchemaManager; import org.apache.directory.shared.ldap.subtree.SubtreeSpecification; -import org.apache.directory.shared.ldap.util.NamespaceTools; /** @@ -79,51 +76,16 @@ public class SubtreeEvaluator * specification. * ===================================================================== */ - - /* - * First we simply check if the candidate entry is a descendant of the - * administrative point. In the process we calculate the relative - * distinguished name relative to the administrative point. - */ - DN apRelativeRdn; + // First construct the subtree base, which is the concatenation of the + // AP DN and the subentry base + DN subentryBaseDn = (DN)apDn.clone(); + subentryBaseDn.addAll( subtree.getBase() ); - if ( !entryDn.isChildOf( apDn ) ) + if ( !entryDn.isChildOf( subentryBaseDn ) ) { + // The entry DN is not part of the subtree specification, get out return false; } - else if ( apDn.equals( entryDn ) ) - { - apRelativeRdn = new DN(); - } - else - { - apRelativeRdn = NamespaceTools.getRelativeName( apDn, entryDn ); - } - - /* - * We do the same thing with the base as we did with the administrative - * point: check if the entry is a descendant of the base and find the - * relative name of the entry with respect to the base rdn. With the - * baseRelativeRdn we can later make comparisons with specific exclusions. - */ - DN baseRelativeRdn; - - if ( subtree.getBase() != null && subtree.getBase().size() == 0 ) - { - baseRelativeRdn = apRelativeRdn; - } - else if ( apRelativeRdn.equals( subtree.getBase() ) ) - { - baseRelativeRdn = new DN(); - } - else if ( !apRelativeRdn.isChildOf( subtree.getBase() ) ) - { - return false; - } - else - { - baseRelativeRdn = NamespaceTools.getRelativeName( subtree.getBase(), apRelativeRdn ); - } /* * Evaluate based on minimum and maximum chop values. Here we simply @@ -133,13 +95,15 @@ public class SubtreeEvaluator * entries with a baseRelativeRdn size less than the minimum distance * are rejected. */ - if ( subtree.getMaxBaseDistance() != SubtreeSpecification.UNBOUNDED_MAX && - subtree.getMaxBaseDistance() < baseRelativeRdn.size() ) + int entryRelativeDnSize = entryDn.size() - subentryBaseDn.size(); + + if ( ( subtree.getMaxBaseDistance() != SubtreeSpecification.UNBOUNDED_MAX ) && + ( entryRelativeDnSize > subtree.getMaxBaseDistance() ) ) { return false; } - if ( subtree.getMinBaseDistance() > 0 && baseRelativeRdn.size() < subtree.getMinBaseDistance() ) + if ( ( subtree.getMinBaseDistance() > 0 ) && ( entryRelativeDnSize < subtree.getMinBaseDistance() ) ) { return false; } @@ -151,27 +115,27 @@ public class SubtreeEvaluator * are equal so for chopAfter exclusions we must check for equality * as well and reject if the relative names are equal. */ - Iterator list = subtree.getChopBeforeExclusions().iterator(); + // Now, get the entry's relative part - while ( list.hasNext() ) + if ( ( subtree.getChopBeforeExclusions().size() != 0 ) || + ( subtree.getChopAfterExclusions().size() != 0 ) ) { - DN chopBefore = list.next(); + DN entryRelativeDn = entryDn.getSuffix( apDn.size() + subtree.getBase().size() ); - if ( baseRelativeRdn.isChildOf( chopBefore ) ) + for ( DN chopBeforeDn : subtree.getChopBeforeExclusions() ) { - return false; + if ( entryRelativeDn.isChildOf( chopBeforeDn ) ) + { + return false; + } } - } - - list = subtree.getChopAfterExclusions().iterator(); - - while ( list.hasNext() ) - { - DN chopAfter = ( DN ) list.next(); - - if ( baseRelativeRdn.isChildOf( chopAfter ) && !chopAfter.equals( baseRelativeRdn ) ) + + for ( DN chopAfterDn : subtree.getChopAfterExclusions() ) { - return false; + if ( entryRelativeDn.isChildOf( chopAfterDn ) && !chopAfterDn.equals( entryRelativeDn ) ) + { + return false; + } } }