KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > javax > jcr > RepositoryException


1 /*
2  * $Id: RepositoryException.java,v 1.2 2004/07/24 00:16:21 benjmestrallet Exp $
3  *
4  * Copyright 2002-2004 Day Management AG, Switzerland.
5  *
6  * Licensed under the Day RI License, Version 2.0 (the "License"),
7  * as a reference implementation of the following specification:
8  *
9  * Content Repository API for Java Technology, revision 0.12
10  * <http://www.jcp.org/en/jsr/detail?id=170>
11  *
12  * You may not use this file except in compliance with the License.
13  * You may obtain a copy of the License files at
14  *
15  * http://www.day.com/content/en/licenses/day-ri-license-2.0
16  * http://www.apache.org/licenses/LICENSE-2.0
17  *
18  * Unless required by applicable law or agreed to in writing, software
19  * distributed under the License is distributed on an "AS IS" BASIS,
20  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
21  * See the License for the specific language governing permissions and
22  * limitations under the License.
23  */

24 package javax.jcr;
25
26 import java.io.PrintStream JavaDoc;
27 import java.io.PrintWriter JavaDoc;
28
29 /**
30  * Main exception thrown by classes in this package. May either contain
31  * an error message or another exception wrapped inside this exception.
32  *
33  * @author Peeter Piegaze
34  */

35 public class RepositoryException extends Exception JavaDoc {
36
37   /**
38    * Root failure cause
39    */

40   protected Exception JavaDoc rootException;
41
42   /**
43    * Constructs a new instance of this class.
44    */

45   public RepositoryException() {
46     super();
47   }
48
49   /**
50    * Constructs a new instance of this class given a message describing the
51    * failure cause.
52    *
53    * @param s description
54    */

55   public RepositoryException(String JavaDoc s) {
56     super(s);
57   }
58
59   /**
60    * Constructs a new instance of this class given a message describing the
61    * failure and a root exception.
62    *
63    * @param s description
64    * @param e root failure cause
65    */

66   public RepositoryException(String JavaDoc s, Exception JavaDoc e) {
67     super(s);
68
69 /* don't create a proxy to a proxy */
70     if (e instanceof RepositoryException) {
71       RepositoryException e2 = (RepositoryException) e;
72       rootException = e2.rootException;
73     } else {
74       rootException = e;
75     }
76   }
77
78   /**
79    * Constructs a new instance of this class given a root exception.
80    *
81    * @param e root failure cause
82    */

83   public RepositoryException(Exception JavaDoc e) {
84     this(null, e);
85   }
86
87   /**
88    * Returns the error message string of this exception.
89    *
90    * @return error message string of this exception.
91    */

92   public String JavaDoc getMessage() {
93     String JavaDoc s = super.getMessage();
94     if (rootException == null) {
95       return s;
96     } else {
97       String JavaDoc s2 = rootException.getMessage();
98       return s == null ? s2 : s + ": " + s2;
99     }
100   }
101
102   /**
103    * Returns the root exception of this exception.
104    *
105    * @return the root exception of this exception
106    */

107   public Exception JavaDoc getRootException() {
108     return rootException;
109   }
110
111   /**
112    * Prints this <code>RepositoryException</code> and its backtrace to the
113    * standard error stream.
114    */

115   public void printStackTrace() {
116     synchronized (System.err) {
117       super.printStackTrace();
118       if (rootException != null) {
119         rootException.printStackTrace();
120       }
121     }
122   }
123
124   /**
125    * Prints this <code>RepositoryException</code> and its backtrace to the
126    * specified print stream.
127    *
128    * @param s <code>PrintStream</code> to use for output
129    */

130   public void printStackTrace(PrintStream JavaDoc s) {
131     synchronized (s) {
132       super.printStackTrace(s);
133       if (rootException != null) {
134         rootException.printStackTrace(s);
135       }
136     }
137   }
138
139   /**
140    * Prints this <code>RepositoryException</code> and its backtrace to
141    * the specified print writer.
142    *
143    * @param s <code>PrintWriter</code> to use for output
144    * @since JDK1.1
145    */

146   public void printStackTrace(PrintWriter JavaDoc s) {
147     synchronized (s) {
148       super.printStackTrace(s);
149       if (rootException != null) {
150         rootException.printStackTrace(s);
151       }
152     }
153   }
154 }
155
Popular Tags