1 17 package org.apache.ldap.server.db; 18 19 20 import org.apache.ldap.common.filter.AbstractExprNode; 21 import org.apache.ldap.common.filter.BranchNode; 22 import org.apache.ldap.common.filter.ExprNode; 23 import org.apache.ldap.common.filter.ScopeNode; 24 import org.apache.ldap.common.message.DerefAliasesEnum; 25 import org.apache.ldap.common.name.LdapName; 26 27 import javax.naming.Name ; 28 import javax.naming.NamingEnumeration ; 29 import javax.naming.NamingException ; 30 import javax.naming.directory.SearchControls ; 31 import java.math.BigInteger ; 32 import java.util.Map ; 33 34 35 42 public class DefaultSearchEngine implements SearchEngine 43 { 44 45 private final Optimizer optimizer; 46 47 private Database db; 48 49 private ExpressionEvaluator evaluator; 50 51 private ExpressionEnumerator enumerator; 52 53 54 58 59 63 public DefaultSearchEngine( Database db, 64 ExpressionEvaluator evaluator, 65 ExpressionEnumerator enumerator ) 66 { 67 this.db = db; 68 this.evaluator = evaluator; 69 this.enumerator = enumerator; 70 optimizer = new DefaultOptimizer( db ); 71 } 72 73 74 79 public Optimizer getOptimizer() 80 { 81 return optimizer; 82 } 83 84 85 88 public NamingEnumeration search( Name base, Map env, ExprNode filter, 89 SearchControls searchCtls ) 90 throws NamingException 91 { 92 Name effectiveBase = null; 93 BigInteger baseId = db.getEntryId( base.toString() ); 94 String aliasedBase = ( String ) db.getAliasIndex().reverseLookup( baseId ); 95 DerefAliasesEnum mode = DerefAliasesEnum.getEnum( env ); 96 97 98 102 103 108 if ( null == aliasedBase || ! mode.derefFindingBase() ) 109 { 110 effectiveBase = base; 111 } 112 117 else if ( null != aliasedBase ) { 119 effectiveBase = new LdapName( aliasedBase ); 120 } 121 124 else 125 { 126 effectiveBase = base; 127 } 128 129 BranchNode root = new BranchNode( AbstractExprNode.AND ); 131 ExprNode node = new ScopeNode( env, effectiveBase.toString(), 132 searchCtls.getSearchScope() ); 133 root.getChildren().add( node ); 134 root.getChildren().add( filter ); 135 136 optimizer.annotate( root ); 138 return enumerator.enumerate( root ); 139 } 140 141 142 145 public boolean evaluate( ExprNode ilter, BigInteger id ) throws NamingException 146 { 147 IndexRecord rec = new IndexRecord(); 148 rec.setEntryId( id ); 149 return evaluator.evaluate( ilter, rec ); 150 } 151 } 152 | Popular Tags |