pylucene 3.5.0-3
[pylucene.git] / lucene-java-3.5.0 / lucene / contrib / queryparser / src / java / org / apache / lucene / queryParser / core / QueryNodeParseException.java
1 package org.apache.lucene.queryParser.core;
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 org.apache.lucene.messages.Message;
21 import org.apache.lucene.messages.MessageImpl;
22 import org.apache.lucene.queryParser.core.messages.QueryParserMessages;
23 import org.apache.lucene.queryParser.core.nodes.QueryNode;
24 import org.apache.lucene.queryParser.core.parser.SyntaxParser;
25
26 /**
27  * This should be thrown when an exception happens during the query parsing from
28  * string to the query node tree.
29  * 
30  * @see QueryNodeException
31  * @see SyntaxParser
32  * @see QueryNode
33  */
34 public class QueryNodeParseException extends QueryNodeException {
35
36   private static final long serialVersionUID = 8197535103538766773L;
37
38   private CharSequence query;
39
40   private int beginColumn = -1;
41
42   private int beginLine = -1;
43
44   private String errorToken = "";
45
46   public QueryNodeParseException(Message message) {
47     super(message);
48   }
49
50   public QueryNodeParseException(Throwable throwable) {
51     super(throwable);
52   }
53
54   public QueryNodeParseException(Message message, Throwable throwable) {
55     super(message, throwable);
56   }
57
58   public void setQuery(CharSequence query) {
59     this.query = query;
60     this.message = new MessageImpl(
61         QueryParserMessages.INVALID_SYNTAX_CANNOT_PARSE, query, "");
62   }
63
64   public CharSequence getQuery() {
65     return this.query;
66   }
67
68   /**
69    * @param errorToken
70    *          the errorToken in the query
71    */
72   protected void setErrorToken(String errorToken) {
73     this.errorToken = errorToken;
74   }
75
76   public String getErrorToken() {
77     return this.errorToken;
78   }
79
80   public void setNonLocalizedMessage(Message message) {
81     this.message = message;
82   }
83
84   /**
85    * For EndOfLine and EndOfFile ("<EOF>") parsing problems the last char in the
86    * string is returned For the case where the parser is not able to figure out
87    * the line and column number -1 will be returned
88    * 
89    * @return line where the problem was found
90    */
91   public int getBeginLine() {
92     return this.beginLine;
93   }
94
95   /**
96    * For EndOfLine and EndOfFile ("<EOF>") parsing problems the last char in the
97    * string is returned For the case where the parser is not able to figure out
98    * the line and column number -1 will be returned
99    * 
100    * @return column of the first char where the problem was found
101    */
102   public int getBeginColumn() {
103     return this.beginColumn;
104   }
105
106   /**
107    * @param beginLine
108    *          the beginLine to set
109    */
110   protected void setBeginLine(int beginLine) {
111     this.beginLine = beginLine;
112   }
113
114   /**
115    * @param beginColumn
116    *          the beginColumn to set
117    */
118   protected void setBeginColumn(int beginColumn) {
119     this.beginColumn = beginColumn;
120   }
121 }