KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > openedit > OpenEditException


1 /*
2 Copyright (c) 2003 eInnovation Inc. All rights reserved
3
4 This library is free software; you can redistribute it and/or modify it under the terms
5 of the GNU Lesser General Public License as published by the Free Software Foundation;
6 either version 2.1 of the License, or (at your option) any later version.
7
8 This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
9 without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10 See the GNU Lesser General Public License for more details.
11 */

12
13 package com.openedit;
14
15 import java.io.PrintWriter JavaDoc;
16 import java.io.Serializable JavaDoc;
17 import java.io.StringWriter JavaDoc;
18
19 import org.apache.commons.logging.Log;
20 import org.apache.commons.logging.LogFactory;
21
22
23
24 /**
25  * This is the superclass of all non-runtime exceptions thrown from Open Edit.
26  *
27  * @author Eric Galluzzo
28  */

29 public class OpenEditException extends Exception JavaDoc implements Serializable JavaDoc
30 {
31     private static final long serialVersionUID = 1630227379714618008L;
32     
33     private static final Log log = LogFactory.getLog(OpenEditException.class);
34     protected String JavaDoc fieldPathWithError;
35
36     public OpenEditException()
37     {
38         this("No Error Entered");
39     }
40     public OpenEditException(String JavaDoc inMsg)
41     {
42         this(inMsg, (Throwable JavaDoc) null);
43     }
44
45     public OpenEditException(String JavaDoc inMsg, String JavaDoc inPath)
46     {
47         this(inMsg, null, inPath);
48     }
49
50     public OpenEditException(String JavaDoc inMsg, Throwable JavaDoc inRootCause, String JavaDoc inPath)
51     {
52         super(inMsg, inRootCause);
53
54         if (inRootCause instanceof OpenEditException)
55         {
56             log.error("Should not wrap an exception of type OpenEditException ");
57         }
58         setPathWithError(inPath);
59     }
60
61     public OpenEditException(String JavaDoc inMsg, Throwable JavaDoc inRootCause)
62     {
63         this(inMsg, inRootCause, null);
64     }
65
66     public OpenEditException(Throwable JavaDoc inRootCause, String JavaDoc inPath)
67     {
68         this(null, inRootCause, inPath);
69     }
70
71     public OpenEditException(Throwable JavaDoc inRootCause)
72     {
73         this(inRootCause.getMessage(), inRootCause);
74     }
75
76     /**
77      * DOCME
78      *
79      * @return DOCME
80      */

81     public String JavaDoc getMessage()
82     {
83         String JavaDoc message = super.getMessage();
84
85         if ((message == null) || (message.length() == 0))
86         {
87             if (getCause() != null)
88             {
89                 return getCause().getMessage();
90             }
91             else
92             {
93                 return "No error message";
94             }
95         }
96         else
97         {
98             return message;
99         }
100     }
101
102     /**
103      * Sets the fieldPathWithError.
104      *
105      * @param fieldPathWithError The fieldPathWithError to set
106      */

107     public void setPathWithError(String JavaDoc fieldPathWithError)
108     {
109         this.fieldPathWithError = fieldPathWithError;
110     }
111
112     /**
113      * DOCUMENT ME!
114      *
115      * @return String
116      */

117     public String JavaDoc getPathWithError()
118     {
119         return fieldPathWithError;
120     }
121
122     /**
123      * DOCUMENT ME!
124      *
125      * @return
126      */

127     public String JavaDoc toStackTrace()
128     {
129         StringWriter JavaDoc out = new StringWriter JavaDoc();
130
131         if (getCause() != null)
132         {
133             getCause().printStackTrace(new PrintWriter JavaDoc(out));
134         }
135         else
136         {
137             printStackTrace(new PrintWriter JavaDoc(out));
138         }
139
140         return out.toString();
141     }
142 }
143
Popular Tags