add --shared
[pylucene.git] / lucene-java-3.4.0 / lucene / contrib / queryparser / src / java / org / apache / lucene / queryParser / core / config / QueryConfigHandler.java
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.queryParser.core.util.StringUtils;
24 import org.apache.lucene.util.Attribute;
25 import org.apache.lucene.util.AttributeSource;
26
27 /**
28  * This class can be used to hold any query configuration and no field
29  * configuration. For field configuration, it creates a empty
30  * {@link FieldConfig} object and delegate it to field config listeners, 
31  * these are responsible for setting up all the field configuration.
32  * 
33  * {@link QueryConfigHandler} should be extended by classes that intends to
34  * provide configuration to {@link QueryNodeProcessor} objects.
35  * 
36  * This class extends {@link AttributeSource}, so {@link Attribute}s can be
37  * attached to it.
38  * 
39  * The class that extends {@link QueryConfigHandler} should also provide
40  * {@link FieldConfig} objects for each collection field.
41  * 
42  * @see Attribute
43  * @see FieldConfig
44  * @see FieldConfigListener
45  * @see QueryConfigHandler
46  * 
47  */
48 public abstract class QueryConfigHandler extends AbstractQueryConfig {
49
50   private LinkedList<FieldConfigListener> listeners = new LinkedList<FieldConfigListener>();
51
52   /**
53    * Returns an implementation of
54    * {@link FieldConfig} for a specific field name. If the implemented
55    * {@link QueryConfigHandler} does not know a specific field name, it may
56    * return <code>null</code>, indicating there is no configuration for that
57    * field.
58    * 
59    * @param fieldName
60    *          the field name
61    * @return a {@link FieldConfig} object containing the field name
62    *         configuration or <code>null</code>, if the implemented
63    *         {@link QueryConfigHandler} has no configuration for that field
64    *         
65    * @deprecated use {@link #getFieldConfig(String)} instead
66    * 
67    */
68   @Deprecated
69   public FieldConfig getFieldConfig(CharSequence fieldName) {
70     return getFieldConfig(StringUtils.toString(fieldName));
71   }
72   
73   /**
74    * Returns an implementation of
75    * {@link FieldConfig} for a specific field name. If the implemented
76    * {@link QueryConfigHandler} does not know a specific field name, it may
77    * return <code>null</code>, indicating there is no configuration for that
78    * field.
79    * 
80    * @param fieldName
81    *          the field name
82    * @return a {@link FieldConfig} object containing the field name
83    *         configuration or <code>null</code>, if the implemented
84    *         {@link QueryConfigHandler} has no configuration for that field
85    */
86   public FieldConfig getFieldConfig(String fieldName) {
87     FieldConfig fieldConfig = new FieldConfig(fieldName);
88
89     for (FieldConfigListener listener : this.listeners) {
90       listener.buildFieldConfig(fieldConfig);
91     }
92
93     return fieldConfig;
94
95   }
96   
97   /**
98    * Adds a listener. The added listeners are called in the order they are
99    * added.
100    * 
101    * @param listener
102    *          the listener to be added
103    */
104   public void addFieldConfigListener(FieldConfigListener listener) {
105     this.listeners.add(listener);
106   }
107   
108 }