KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > ibm > icu > text > StringPrepParseException


1 /*
2  *******************************************************************************
3  * Copyright (C) 2003-2005, International Business Machines Corporation and *
4  * others. All Rights Reserved. *
5  *******************************************************************************
6  */

7 package com.ibm.icu.text;
8
9 import java.text.ParseException JavaDoc;
10
11 /**
12  * Exception that signals an error has occurred while parsing the
13  * input to StringPrep or IDNA.
14  *
15  * @author Ram Viswanadha
16  * @stable ICU 2.8
17  */

18 public class StringPrepParseException extends ParseException JavaDoc {
19     // Generated by serialver from JDK 1.4.1_01
20
static final long serialVersionUID = 7160264827701651255L;
21     
22     /**
23      * @stable ICU 2.8
24      */

25     public static final int INVALID_CHAR_FOUND = 0;
26     /**
27      * @stable ICU 2.8
28      */

29     public static final int ILLEGAL_CHAR_FOUND = 1;
30     /**
31      * @stable ICU 2.8
32      */

33     public static final int PROHIBITED_ERROR = 2;
34     /**
35      * @stable ICU 2.8
36      */

37     public static final int UNASSIGNED_ERROR = 3;
38     /**
39      * @stable ICU 2.8
40      */

41     public static final int CHECK_BIDI_ERROR = 4;
42     /**
43      * @stable ICU 2.8
44      */

45     public static final int STD3_ASCII_RULES_ERROR = 5;
46     /**
47      * @stable ICU 2.8
48      */

49     public static final int ACE_PREFIX_ERROR = 6;
50     /**
51      * @stable ICU 2.8
52      */

53     public static final int VERIFICATION_ERROR = 7;
54     /**
55      * @stable ICU 2.8
56      */

57     public static final int LABEL_TOO_LONG_ERROR = 8;
58     /**
59      * @stable ICU 2.8
60      */

61     public static final int BUFFER_OVERFLOW_ERROR = 9;
62     
63     /**
64      * @stable ICU 2.2
65      */

66     public static final int ZERO_LENGTH_LABEL = 10;
67     
68     /**
69      * Construct a ParseException object with the given message
70      * and error code
71      *
72      * @param message A string describing the type of error that occurred
73      * @param error The error that has occurred
74      * @stable ICU 2.8
75      */

76     public StringPrepParseException(String JavaDoc message,int error){
77         super(message, -1);
78         this.error = error;
79         this.line = 0;
80     }
81     
82     /**
83      * Construct a ParseException object with the given message and
84      * error code
85      *
86      * @param message A string describing the type of error that occurred
87      * @param error The error that has occurred
88      * @param rules The input rules string
89      * @param pos The position of error in the rules string
90      * @stable ICU 2.8
91      */

92     public StringPrepParseException(String JavaDoc message,int error, String JavaDoc rules, int pos){
93         super(message, -1);
94         this.error = error;
95         setContext(rules,pos);
96         this.line = 0;
97     }
98     /**
99      * Construct a ParseException object with the given message and error code
100      *
101      * @param message A string describing the type of error that occurred
102      * @param error The error that has occurred
103      * @param rules The input rules string
104      * @param pos The position of error in the rules string
105      * @param lineNumber The line number at which the error has occurred.
106      * If the parse engine is not using this field, it should set it to zero. Otherwise
107      * it should be a positive integer. The default value of this field
108      * is -1. It will be set to 0 if the code populating this struct is not
109      * using line numbers.
110      * @stable ICU 2.8
111      */

112     public StringPrepParseException(String JavaDoc message, int error, String JavaDoc rules, int pos, int lineNumber){
113         super(message, -1);
114         this.error = error;
115         setContext(rules,pos);
116         this.line = lineNumber;
117     }
118     /**
119      * Compare this ParseException to another and evaluate if they are equal.
120      * The comparison works only on the type of error and does not compare
121      * the rules strings, if any, for equality.
122      *
123      * @param other The exception that this object should be compared to
124      * @return true if the objects are equal, false if unequal
125      * @stable ICU 2.8
126      */

127     public boolean equals(Object JavaDoc other){
128         if(!(other instanceof StringPrepParseException)){
129             return false;
130         }
131         return ((StringPrepParseException)other).error == this.error;
132         
133     }
134     /**
135      * Returns the position of error in the rules string
136      *
137      * @return String
138      * @stable ICU 2.8
139      */

140     public String JavaDoc toString(){
141         StringBuffer JavaDoc buf = new StringBuffer JavaDoc();
142         buf.append(super.getMessage());
143         buf.append(". preContext: ");
144         buf.append(preContext);
145         buf.append(". postContext: ");
146         buf.append(postContext);
147         buf.append("\n");
148         return buf.toString();
149     }
150
151     private int error;
152     
153     /**
154      * The line on which the error occured. If the parse engine
155      * is not using this field, it should set it to zero. Otherwise
156      * it should be a positive integer. The default value of this field
157      * is -1. It will be set to 0 if the code populating this struct is not
158      * using line numbers.
159      * @stable ICU 2.8
160      */

161     private int line;
162
163
164     /**
165      * Textual context before the error. Null-terminated.
166      * May be the empty string if not implemented by parser.
167      * @stable ICU 2.8
168      */

169     private StringBuffer JavaDoc preContext = new StringBuffer JavaDoc();
170
171     /**
172      * Textual context after the error. Null-terminated.
173      * May be the empty string if not implemented by parser.
174      * @stable ICU 2.8
175      */

176     private StringBuffer JavaDoc postContext = new StringBuffer JavaDoc();
177     
178     private static final int PARSE_CONTEXT_LEN = 16;
179     
180     private void setPreContext(String JavaDoc str, int pos){
181         setPreContext(str.toCharArray(),pos);
182     }
183     
184     private void setPreContext(char[] str, int pos){
185         int start = (pos <= PARSE_CONTEXT_LEN)? 0 : (pos - (PARSE_CONTEXT_LEN-1));
186         int len = (start <= PARSE_CONTEXT_LEN)? start : PARSE_CONTEXT_LEN;
187         preContext.append(str,start,len);
188  
189     }
190     
191     private void setPostContext(String JavaDoc str, int pos){
192         setPostContext(str.toCharArray(),pos);
193     }
194     
195     private void setPostContext(char[] str, int pos){
196         int start = pos;
197         int len = str.length - start;
198         postContext.append(str,start,len);
199
200     }
201     
202     private void setContext(String JavaDoc str,int pos){
203         setPreContext(str,pos);
204         setPostContext(str,pos);
205     }
206 }
207
Popular Tags