1 17 18 27 package org.apache.ldap.server.db; 28 29 30 import org.apache.ldap.common.filter.ExprNode; 31 import org.apache.ldap.common.filter.ScopeNode; 32 import org.apache.ldap.common.message.DerefAliasesEnum; 33 34 import javax.naming.NamingException ; 35 import javax.naming.directory.SearchControls ; 36 import java.math.BigInteger ; 37 38 39 45 public class ScopeEvaluator implements Evaluator 46 { 47 48 private Database db; 49 50 51 56 public ScopeEvaluator( Database db ) 57 { 58 this.db = db; 59 } 60 61 62 65 public boolean evaluate( ExprNode node, IndexRecord record ) 66 throws NamingException 67 { 68 ScopeNode snode = ( ScopeNode ) node; 69 70 switch( snode.getScope() ) 71 { 72 case( SearchControls.OBJECT_SCOPE ): 73 String dn = db.getEntryDn( record.getEntryId() ); 74 return dn.equals( snode.getBaseDn() ); 75 case( SearchControls.ONELEVEL_SCOPE ): 76 return assertOneLevelScope( snode, record.getEntryId() ); 77 case( SearchControls.SUBTREE_SCOPE ): 78 return assertSubtreeScope( snode, record.getEntryId() ); 79 default: 80 throw new NamingException ( "Unrecognized search scope!" ); 81 } 82 } 83 84 85 95 public boolean assertSubtreeScope( final ScopeNode node, 96 final BigInteger id ) throws NamingException 97 { 98 String dn = db.getEntryDn( id ); 99 DerefAliasesEnum mode = node.getDerefAliases(); 100 Object baseId = db.getEntryId( node.getBaseDn() ); 101 boolean isDescendant = dn.endsWith( node.getBaseDn() ); 102 103 108 if ( ! mode.derefInSearching() ) 109 { 110 return isDescendant; 111 } 112 113 118 Index idx = db.getAliasIndex(); 119 if ( null != idx.reverseLookup( id ) ) 120 { 121 return false; 122 } 123 124 128 if ( isDescendant ) 129 { 130 return true; 131 } 132 133 146 idx = db.getSubAliasIndex(); 147 return idx.hasValue( baseId, id ); 148 } 149 150 151 161 public boolean assertOneLevelScope( final ScopeNode node, 162 final BigInteger id ) throws NamingException 163 { 164 DerefAliasesEnum mode = node.getDerefAliases(); 165 Object baseId = db.getEntryId( node.getBaseDn() ); 166 Index idx = db.getHierarchyIndex(); 167 boolean isChild = idx.hasValue( baseId, id ); 168 169 174 if ( ! mode.derefInSearching() ) 175 { 176 return isChild; 177 } 178 179 184 idx = db.getAliasIndex(); 185 if ( null != idx.reverseLookup( id ) ) 186 { 187 return false; 188 } 189 190 194 if ( isChild ) 195 { 196 return true; 197 } 198 199 209 idx = db.getOneAliasIndex(); 210 return idx.hasValue( baseId, id ); 211 } 212 } 213 | Popular Tags |