001/*
002 *  Licensed to the Apache Software Foundation (ASF) under one
003 *  or more contributor license agreements.  See the NOTICE file
004 *  distributed with this work for additional information
005 *  regarding copyright ownership.  The ASF licenses this file
006 *  to you under the Apache License, Version 2.0 (the
007 *  "License"); you may not use this file except in compliance
008 *  with the License.  You may obtain a copy of the License at
009 *  
010 *    http://www.apache.org/licenses/LICENSE-2.0
011 *  
012 *  Unless required by applicable law or agreed to in writing,
013 *  software distributed under the License is distributed on an
014 *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015 *  KIND, either express or implied.  See the License for the
016 *  specific language governing permissions and limitations
017 *  under the License. 
018 *  
019 */
020package org.apache.directory.server.xdbm.search.evaluator;
021
022
023import org.apache.directory.api.ldap.model.entry.Entry;
024import org.apache.directory.api.ldap.model.filter.SimpleNode;
025import org.apache.directory.api.ldap.model.schema.AttributeType;
026import org.apache.directory.api.ldap.model.schema.LdapComparator;
027import org.apache.directory.api.ldap.model.schema.Normalizer;
028import org.apache.directory.api.ldap.model.schema.SchemaManager;
029import org.apache.directory.server.xdbm.Index;
030import org.apache.directory.server.xdbm.Store;
031import org.apache.directory.server.xdbm.search.Evaluator;
032
033
034/**
035 * An abstract evaluator to store the common fileds for the Simple node evaluators
036 * (ApproximateEvaluator, EqualityEvaluator, GreaterEqEvluator and LessEqEvluator)
037 *
038 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
039 * @version $Rev$, $Date$
040 */
041public abstract class LeafEvaluator<T> implements Evaluator<SimpleNode<T>>
042{
043    /** The ExprNode to evaluate */
044    protected final SimpleNode<T> node;
045
046    /** The backend */
047    protected final Store db;
048
049    /** The SchemaManager instance */
050    protected final SchemaManager schemaManager;
051
052    /** The AttributeType we will use for the evaluation */
053    protected final AttributeType attributeType;
054
055    /** The associated normalizer */
056    protected Normalizer normalizer;
057
058    /** The associated comparator */
059    protected LdapComparator<? super Object> ldapComparator;
060
061    /** The index to use if any */
062    protected Index<T, Entry, String> idx;
063
064
065    @SuppressWarnings("unchecked")
066    public LeafEvaluator( SimpleNode<T> node, Store db, SchemaManager schemaManager )
067        throws Exception
068    {
069        this.db = db;
070        this.node = node;
071        this.schemaManager = schemaManager;
072        this.attributeType = node.getAttributeType();
073    }
074
075
076    /**
077     * @return The AttributeType
078     */
079    public AttributeType getAttributeType()
080    {
081        return attributeType;
082    }
083
084
085    /**
086     * @return The Normalizer associated with the AttributeType
087     */
088    public Normalizer getNormalizer()
089    {
090        return normalizer;
091    }
092
093
094    /**
095     * @return The LdapComparator associated with the AttributeType
096     */
097    public LdapComparator<? super Object> getComparator()
098    {
099        return ldapComparator;
100    }
101
102
103    /**
104     * @see Object#toString()
105     */
106    public String toString()
107    {
108        StringBuilder sb = new StringBuilder();
109
110        sb.append( node );
111
112        return sb.toString();
113    }
114}