KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > percederberg > grammatica > parser > ParserLogException


1 /*
2  * ParserLogException.java
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public License
6  * as published by the Free Software Foundation; either version 2.1
7  * of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the Free
16  * Software Foundation, Inc., 59 Temple Place, Suite 330, Boston,
17  * MA 02111-1307, USA.
18  *
19  * Copyright (c) 2003-2005 Per Cederberg. All rights reserved.
20  */

21
22 package net.percederberg.grammatica.parser;
23
24 import java.util.ArrayList JavaDoc;
25
26 /**
27  * A parser log exception. This class contains a list of all the parse
28  * errors encountered while parsing.
29  *
30  * @author Per Cederberg, <per at percederberg dot net>
31  * @version 1.1
32  * @since 1.1
33  */

34 public class ParserLogException extends Exception JavaDoc {
35
36     /**
37      * The list of errors found.
38      */

39     private ArrayList JavaDoc errors = new ArrayList JavaDoc();
40
41     /**
42      * Creates a new empty parser log exception.
43      */

44     public ParserLogException() {
45     }
46
47     /**
48      * Returns the number of errors in this log.
49      *
50      * @return the number of errors in this log
51      */

52     public int getErrorCount() {
53         return errors.size();
54     }
55
56     /**
57      * Returns a specific error from the log.
58      *
59      * @param index the error index, 0 <= index < count
60      *
61      * @return the parse error requested
62      */

63     public ParseException getError(int index) {
64         return (ParseException) errors.get(index);
65     }
66
67     /**
68      * Adds a parse error to the log.
69      *
70      * @param e the parse error to add
71      */

72     public void addError(ParseException e) {
73         errors.add(e);
74     }
75
76     /**
77      * Returns the detailed error message. This message will contain
78      * the error messages from all errors in this log, separated by
79      * a newline.
80      *
81      * @return the detailed error message
82      */

83     public String JavaDoc getMessage() {
84         StringBuffer JavaDoc buffer = new StringBuffer JavaDoc();
85
86         for (int i = 0; i < getErrorCount(); i++) {
87             if (i > 0) {
88                 buffer.append("\n");
89             }
90             buffer.append(getError(i).getMessage());
91         }
92         return buffer.toString();
93     }
94 }
95
Popular Tags