add --shared
[pylucene.git] / lucene-java-3.4.0 / lucene / contrib / queryparser / src / java / org / apache / lucene / queryParser / standard / config / NumericFieldConfigListener.java
1 package org.apache.lucene.queryParser.standard.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.Map;
21
22 import org.apache.lucene.queryParser.core.config.FieldConfig;
23 import org.apache.lucene.queryParser.core.config.FieldConfigListener;
24 import org.apache.lucene.queryParser.core.config.QueryConfigHandler;
25 import org.apache.lucene.queryParser.standard.config.StandardQueryConfigHandler.ConfigurationKeys;
26
27 /**
28  * This listener is used to listen to {@link FieldConfig} requests in
29  * {@link QueryConfigHandler} and add {@link ConfigurationKeys#NUMERIC_CONFIG}
30  * based on the {@link ConfigurationKeys#NUMERIC_CONFIG_MAP} set in the
31  * {@link QueryConfigHandler}.
32  * 
33  * @see NumericConfig
34  * @see QueryConfigHandler
35  * @see ConfigurationKeys#NUMERIC_CONFIG
36  * @see ConfigurationKeys#NUMERIC_CONFIG_MAP
37  */
38 public class NumericFieldConfigListener implements FieldConfigListener {
39   
40   final private QueryConfigHandler config;
41   
42   /**
43    * Construcs a {@link NumericFieldConfigListener} object using the given {@link QueryConfigHandler}.
44    * 
45    * @param config the {@link QueryConfigHandler} it will listen too
46    */
47   public NumericFieldConfigListener(QueryConfigHandler config) {
48     
49     if (config == null) {
50       throw new IllegalArgumentException("config cannot be null!");
51     }
52     
53     this.config = config;
54     
55   }
56   
57   public void buildFieldConfig(FieldConfig fieldConfig) {
58     Map<String,NumericConfig> numericConfigMap = config
59         .get(ConfigurationKeys.NUMERIC_CONFIG_MAP);
60     
61     if (numericConfigMap != null) {
62       NumericConfig numericConfig = numericConfigMap
63           .get(fieldConfig.getField());
64       
65       if (numericConfig != null) {
66         fieldConfig.set(ConfigurationKeys.NUMERIC_CONFIG, numericConfig);
67       }
68       
69     }
70     
71   }
72   
73 }