add --shared
[pylucene.git] / lucene-java-3.4.0 / lucene / contrib / queryparser / src / test / org / apache / lucene / queryParser / spans / SpansValidatorQueryNodeProcessor.java
1 package org.apache.lucene.queryParser.spans;
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.List;
21
22 import org.apache.lucene.messages.MessageImpl;
23 import org.apache.lucene.queryParser.core.QueryNodeException;
24 import org.apache.lucene.queryParser.core.messages.QueryParserMessages;
25 import org.apache.lucene.queryParser.core.nodes.AndQueryNode;
26 import org.apache.lucene.queryParser.core.nodes.BooleanQueryNode;
27 import org.apache.lucene.queryParser.core.nodes.FieldQueryNode;
28 import org.apache.lucene.queryParser.core.nodes.OrQueryNode;
29 import org.apache.lucene.queryParser.core.nodes.QueryNode;
30 import org.apache.lucene.queryParser.core.processors.QueryNodeProcessorImpl;
31
32 /**
33  * Validates every query node in a query node tree. This processor will pass
34  * fine if the query nodes are only {@link BooleanQueryNode}s,
35  * {@link OrQueryNode}s or {@link FieldQueryNode}s, otherwise an exception will
36  * be thrown. <br/>
37  * <br/>
38  * 
39  * If they are {@link AndQueryNode} or an instance of anything else that
40  * implements {@link FieldQueryNode} the exception will also be thrown.
41  */
42 public class SpansValidatorQueryNodeProcessor extends QueryNodeProcessorImpl {
43
44   @Override
45   protected QueryNode postProcessNode(QueryNode node) throws QueryNodeException {
46
47     return node;
48
49   }
50
51   @Override
52   protected QueryNode preProcessNode(QueryNode node) throws QueryNodeException {
53
54     if (!((node instanceof BooleanQueryNode && !(node instanceof AndQueryNode)) || node
55         .getClass() == FieldQueryNode.class)) {
56       throw new QueryNodeException(new MessageImpl(
57           QueryParserMessages.NODE_ACTION_NOT_SUPPORTED));
58     }
59
60     return node;
61
62   }
63
64   @Override
65   protected List<QueryNode> setChildrenOrder(List<QueryNode> children)
66       throws QueryNodeException {
67
68     return children;
69
70   }
71
72 }