KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > tc > jrexx > regex > InvalidExpression


1 /*
2 * 01/07/2003 - 15:19:32
3 *
4 * InvalidExpression.java -
5 * Copyright (C) 2003 Buero fuer Softwarearchitektur GbR
6 * ralf.meyer@karneim.com
7 * http://jrexx.sf.net
8 *
9 * 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 JavaDoc {
26
27     private String JavaDoc expression;
28     private String JavaDoc illegalToken;
29     private int tokenPosition = -1;
30
31     private static String JavaDoc makeMessage(String JavaDoc expression, String JavaDoc illegalToken, int tokenPosition) {
32         try {
33         String JavaDoc message = "Token \"" + illegalToken + "\" not allowed at this position: ";
34                message+= expression.substring( 0,tokenPosition );
35                message+= "\u0010" + illegalToken + "\u0011";
36                message+= expression.substring( tokenPosition+illegalToken.length() );
37             return message;
38         } catch ( Exception JavaDoc e) {
39             System.out.println( e);
40             System.out.println( "EXPRESSION="+expression+" TOKENPOS="+tokenPosition+ " ILLEGALTOKEN="+illegalToken);
41         }
42         throw new RuntimeException JavaDoc();
43     }
44
45     InvalidExpression() {};
46
47     public InvalidExpression(String JavaDoc message) {super(message);}
48
49     public InvalidExpression(String JavaDoc expression,String JavaDoc illegalToken,int tokenPosition) {
50         super (InvalidExpression.makeMessage(expression,illegalToken,tokenPosition));
51         this.expression = expression;
52         this.illegalToken = illegalToken;
53         this.tokenPosition = tokenPosition;
54     }
55
56     public String JavaDoc getExpression() {
57         return this.expression;
58     }
59
60     public String JavaDoc getIllegalToken() {
61         return this.illegalToken;
62     }
63
64     public int getIllegalTokenPosition() {
65         return this.tokenPosition;
66     }
67
68 }
Popular Tags