1 package org.apache.lucene.queryParser.core.config;
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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.
20 import java.util.LinkedList;
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;
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.
33 * {@link QueryConfigHandler} should be extended by classes that intends to
34 * provide configuration to {@link QueryNodeProcessor} objects.
36 * This class extends {@link AttributeSource}, so {@link Attribute}s can be
39 * The class that extends {@link QueryConfigHandler} should also provide
40 * {@link FieldConfig} objects for each collection field.
44 * @see FieldConfigListener
45 * @see QueryConfigHandler
48 public abstract class QueryConfigHandler extends AbstractQueryConfig {
50 private LinkedList<FieldConfigListener> listeners = new LinkedList<FieldConfigListener>();
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
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
65 * @deprecated use {@link #getFieldConfig(String)} instead
69 public FieldConfig getFieldConfig(CharSequence fieldName) {
70 return getFieldConfig(StringUtils.toString(fieldName));
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
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
86 public FieldConfig getFieldConfig(String fieldName) {
87 FieldConfig fieldConfig = new FieldConfig(fieldName);
89 for (FieldConfigListener listener : this.listeners) {
90 listener.buildFieldConfig(fieldConfig);
98 * Adds a listener. The added listeners are called in the order they are
102 * the listener to be added
104 public void addFieldConfigListener(FieldConfigListener listener) {
105 this.listeners.add(listener);