001: /***************************************************************
002: * This file is part of the [fleXive](R) project.
003: *
004: * Copyright (c) 1999-2008
005: * UCS - unique computing solutions gmbh (http://www.ucs.at)
006: * All rights reserved
007: *
008: * The [fleXive](R) project is free software; you can redistribute
009: * it and/or modify it under the terms of the GNU General Public
010: * License as published by the Free Software Foundation;
011: * either version 2 of the License, or (at your option) any
012: * later version.
013: *
014: * The GNU General Public License can be found at
015: * http://www.gnu.org/copyleft/gpl.html.
016: * A copy is found in the textfile GPL.txt and important notices to the
017: * license from the author are found in LICENSE.txt distributed with
018: * these libraries.
019: *
020: * This library is distributed in the hope that it will be useful,
021: * but WITHOUT ANY WARRANTY; without even the implied warranty of
022: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
023: * GNU General Public License for more details.
024: *
025: * For further information about UCS - unique computing solutions gmbh,
026: * please see the company website: http://www.ucs.at
027: *
028: * For further information about [fleXive](R), please see the
029: * project website: http://www.flexive.org
030: *
031: *
032: * This copyright notice MUST APPEAR in all copies of the file!
033: ***************************************************************/package com.flexive.sqlParser;
034:
035: import com.flexive.shared.FxSharedUtils;
036: import com.flexive.shared.FxLanguage;
037: import com.flexive.shared.exceptions.FxExceptionMessage;
038:
039: public class SqlParserException extends Exception {
040:
041: Object[] params;
042:
043: public SqlParserException(TokenMgrError pe, String query) {
044: super ("ex.sqlSearch.tokenMgrException");
045: params = new Object[] { pe.getErrorLine(), pe.getErrorColumn(),
046: pe.getCurCharEscaped(), pe.getErrorAfter(), query };
047:
048: }
049:
050: public SqlParserException(ParseException pe, String query) {
051: super ("ex.sqlSearch.parserException");
052: String expected = "";
053: String encountered = "";
054:
055: // Expected
056: int[][] expectedTokenSequences = pe.expectedTokenSequences;
057: int maxSize = 0;
058: for (int[] expectedTokenSequence : expectedTokenSequences) {
059: if (maxSize < expectedTokenSequence.length) {
060: maxSize = expectedTokenSequence.length;
061: }
062: for (int anExpectedTokenSequence : expectedTokenSequence) {
063: expected += pe.tokenImage[anExpectedTokenSequence]
064: + " ";
065: }
066: if (expectedTokenSequence[expectedTokenSequence.length - 1] != 0) {
067: expected += "...";
068: }
069: }
070:
071: // Encountered
072: Token tok = pe.currentToken.next;
073: for (int i = 0; i < maxSize; i++) {
074: if (i != 0)
075: encountered += " ";
076: if (tok.kind == 0) {
077: encountered += pe.tokenImage[0];
078: break;
079: }
080: encountered += pe.add_escapes(tok.image);
081: tok = tok.next;
082: }
083: int line = pe.currentToken.next.beginLine;
084: int column = pe.currentToken.next.beginColumn;
085: params = new Object[] { line, column, encountered, expected,
086: pe.getMessage(), query };
087: }
088:
089: public SqlParserException(String message, Throwable cause,
090: Object... values) {
091: super (message, cause);
092: this .params = values;
093: }
094:
095: public SqlParserException(String message, Object... values) {
096: super (message);
097: this .params = values;
098: }
099:
100: public Object[] getValues() {
101: return params == null ? new Object[0] : params;
102: }
103:
104: @Override
105: public String getMessage() {
106: return new FxExceptionMessage(super.getMessage(), getValues())
107: .getLocalizedMessage(FxLanguage.DEFAULT_ID,
108: FxLanguage.DEFAULT_ISO);
109: }
110: }
|