Home » lucene-3.0.1-src » org.apache.lucene.queryParser.core.config » [javadoc | source]

    1   package org.apache.lucene.queryParser.core.config;
    2   
    3   /**
    4    * Licensed to the Apache Software Foundation (ASF) under one or more
    5    * contributor license agreements.  See the NOTICE file distributed with
    6    * this work for additional information regarding copyright ownership.
    7    * The ASF licenses this file to You under the Apache License, Version 2.0
    8    * (the "License"); you may not use this file except in compliance with
    9    * the License.  You may obtain a copy of the License at
   10    *
   11    *     http://www.apache.org/licenses/LICENSE-2.0
   12    *
   13    * Unless required by applicable law or agreed to in writing, software
   14    * distributed under the License is distributed on an "AS IS" BASIS,
   15    * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   16    * See the License for the specific language governing permissions and
   17    * limitations under the License.
   18    */
   19   
   20   import java.util.LinkedList;
   21   
   22   import org.apache.lucene.queryParser.core.processors.QueryNodeProcessor;
   23   import org.apache.lucene.util.Attribute;
   24   import org.apache.lucene.util.AttributeSource;
   25   
   26   /**
   27    * This class can be used to hold any query configuration and no field
   28    * configuration. For field configuration, it creates a empty
   29    * {@link FieldConfig} object and delegate it to field config listeners, 
   30    * these are responsible for setting up all the field configuration.
   31    * 
   32    * {@link QueryConfigHandler} should be extended by classes that intends to
   33    * provide configuration to {@link QueryNodeProcessor} objects.
   34    * 
   35    * This class extends {@link AttributeSource}, so {@link Attribute}s can be
   36    * attached to it.
   37    * 
   38    * The class that extends {@link QueryConfigHandler} should also provide
   39    * {@link FieldConfig} objects for each collection field.
   40    * 
   41    * @see Attribute
   42    * @see FieldConfig
   43    * @see FieldConfigListener
   44    * @see QueryConfigHandler
   45    */
   46   public abstract class QueryConfigHandler extends AttributeSource {
   47   
   48     private LinkedList<FieldConfigListener> listeners = new LinkedList<FieldConfigListener>();;
   49   
   50     /**
   51      * Returns an implementation of
   52      * {@link FieldConfig} for a specific field name. If the implemented
   53      * {@link QueryConfigHandler} does not know a specific field name, it may
   54      * return <code>null</code>, indicating there is no configuration for that
   55      * field.
   56      * 
   57      * @param fieldName
   58      *          the field name
   59      * @return a {@link FieldConfig} object containing the field name
   60      *         configuration or <code>null</code>, if the implemented
   61      *         {@link QueryConfigHandler} has no configuration for that field
   62      */
   63     public FieldConfig getFieldConfig(CharSequence fieldName) {
   64       FieldConfig fieldConfig = new FieldConfig(fieldName);
   65   
   66       for (FieldConfigListener listener : this.listeners) {
   67         listener.buildFieldConfig(fieldConfig);
   68       }
   69   
   70       return fieldConfig;
   71   
   72     }
   73   
   74     /**
   75      * Adds a listener. The added listeners are called in the order they are
   76      * added.
   77      * 
   78      * @param listener
   79      *          the listener to be added
   80      */
   81     public void addFieldConfigListener(FieldConfigListener listener) {
   82       this.listeners.add(listener);
   83     }
   84     
   85   }

Home » lucene-3.0.1-src » org.apache.lucene.queryParser.core.config » [javadoc | source]