01: /*
02: * 01/07/2003 - 15:19:32
03: *
04: * InvalidExpression.java -
05: * Copyright (C) 2003 Buero fuer Softwarearchitektur GbR
06: * ralf.meyer@karneim.com
07: * http://jrexx.sf.net
08: *
09: * This program is free software; you can redistribute it and/or
10: * modify it under the terms of the GNU Lesser General Public License
11: * as published by the Free Software Foundation; either version 2
12: * of the License, or (at your option) any later version.
13: *
14: * This program is distributed in the hope that it will be useful,
15: * but WITHOUT ANY WARRANTY; without even the implied warranty of
16: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17: * GNU Lesser General Public License for more details.
18: *
19: * You should have received a copy of the GNU Lesser General Public License
20: * along with this program; if not, write to the Free Software
21: * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22: */
23: package com.tc.jrexx.regex;
24:
25: public class InvalidExpression extends RuntimeException {
26:
27: private String expression;
28: private String illegalToken;
29: private int tokenPosition = -1;
30:
31: private static String makeMessage(String expression,
32: String illegalToken, int tokenPosition) {
33: try {
34: String message = "Token \"" + illegalToken
35: + "\" not allowed at this position: ";
36: message += expression.substring(0, tokenPosition);
37: message += "\u0010" + illegalToken + "\u0011";
38: message += expression.substring(tokenPosition
39: + illegalToken.length());
40: return message;
41: } catch (Exception e) {
42: System.out.println(e);
43: System.out.println("EXPRESSION=" + expression
44: + " TOKENPOS=" + tokenPosition + " ILLEGALTOKEN="
45: + illegalToken);
46: }
47: throw new RuntimeException();
48: }
49:
50: InvalidExpression() {
51: };
52:
53: public InvalidExpression(String message) {
54: super (message);
55: }
56:
57: public InvalidExpression(String expression, String illegalToken,
58: int tokenPosition) {
59: super (InvalidExpression.makeMessage(expression, illegalToken,
60: tokenPosition));
61: this .expression = expression;
62: this .illegalToken = illegalToken;
63: this .tokenPosition = tokenPosition;
64: }
65:
66: public String getExpression() {
67: return this .expression;
68: }
69:
70: public String getIllegalToken() {
71: return this .illegalToken;
72: }
73:
74: public int getIllegalTokenPosition() {
75: return this.tokenPosition;
76: }
77:
78: }
|