KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > teamkonzept > publishing > markups > TKMarkupParserException


1 /*
2  * $Header: /cvsroot/webman-cms/source/webman/com/teamkonzept/publishing/markups/TKMarkupParserException.java,v 1.7 2001/06/11 09:14:10 alex Exp $
3  *
4  */

5 package com.teamkonzept.publishing.markups;
6
7 import com.teamkonzept.lib.*;
8
9 public class TKMarkupParserException extends Exception JavaDoc {
10
11     int pos;
12     
13     public TKMarkupParserException (String JavaDoc msg) {
14     
15         super (msg);
16
17         this.pos = -1;
18     }
19
20     public TKMarkupParserException (String JavaDoc msg, int pos) {
21     
22         super (msg);
23
24         this.pos = pos;
25     }
26
27     public void throwAgain () throws TKMarkupParserException {
28     
29         throwAgain ((String JavaDoc) null,-1);
30     }
31
32     public void throwAgain (int pos) throws TKMarkupParserException {
33
34         throwAgain ((String JavaDoc) null,pos);
35     }
36     
37     public void throwAgain (String JavaDoc msg, int pos)
38         throws TKMarkupParserException {
39
40         if (this.pos >= 0) pos = this.pos;
41
42         throwAgain (this,msg,pos);
43     }
44
45     public String JavaDoc getMsg () {
46
47         return getMsg (null);
48     }
49
50     public String JavaDoc getMsg (String JavaDoc prefix) {
51
52         return (prefix == null ? "" : prefix)+
53             (pos < 0 ? "" : "Position "+pos+": ")+
54             demandMsg(this);
55     }
56
57     public TKVector handle (TKVector diagnostics) {
58
59         if (diagnostics == null) diagnostics = new TKVector();
60         diagnostics.addElement(getMsg());
61         
62         return diagnostics;
63     }
64
65     private static int count = 0;
66     
67     private static synchronized int countUp () {
68
69         return ++count;
70     }
71
72     public static void throwAgain (Exception JavaDoc ex) throws TKMarkupParserException {
73
74         throwAgain (ex,(String JavaDoc) null,-1);
75     }
76     
77     public static void throwAgain (Exception JavaDoc ex, int pos) throws TKMarkupParserException {
78
79         throwAgain (ex,(String JavaDoc) null,pos);
80     }
81     
82     public static void throwAgain (Exception JavaDoc ex, String JavaDoc msg, int pos)
83         throws TKMarkupParserException {
84
85         String JavaDoc old = demandMsg(ex);
86
87         if (msg == null) throw new TKMarkupParserException (old,pos);
88         else throw new TKMarkupParserException (msg+": "+old,pos);
89     }
90
91     public static String JavaDoc demandMsg (Exception JavaDoc ex) {
92
93         String JavaDoc msg = ex.getMessage();
94
95         if (msg == null) {
96
97             int id = countUp();
98             msg = "Unbekannter Fehler #"+id+" (siehe Logfile)";
99         }
100         
101         return msg;
102     }
103
104     public static TKVector handle (Exception JavaDoc ex, TKVector diagnostics) {
105
106         if (diagnostics == null) diagnostics = new TKVector();
107         diagnostics.addElement(demandMsg(ex));
108         
109         return diagnostics;
110     }
111 }
112
113
Popular Tags