KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > jdon > servicelocator > ServiceLocatorException


1 package com.jdon.servicelocator;
2
3 /**
4  * This class implements an exception which can wrapped a lower-level exception.
5  *
6  */

7 public class ServiceLocatorException extends Exception JavaDoc {
8   private Exception JavaDoc exception;
9
10   /**
11    * Creates a new ServiceLocatorException wrapping another exception, and with a detail message.
12    * @param message the detail message.
13    * @param exception the wrapped exception.
14    */

15   public ServiceLocatorException(String JavaDoc message, Exception JavaDoc exception) {
16     super(message);
17     this.exception = exception;
18     return;
19   }
20
21   /**
22    * Creates a ServiceLocatorException with the specified detail message.
23    * @param message the detail message.
24    */

25   public ServiceLocatorException(String JavaDoc message) {
26     this(message, null);
27     return;
28   }
29
30   /**
31    * Creates a new ServiceLocatorException wrapping another exception, and with no detail message.
32    * @param exception the wrapped exception.
33    */

34   public ServiceLocatorException(Exception JavaDoc exception) {
35     this(null, exception);
36     return;
37   }
38
39   /**
40    * Gets the wrapped exception.
41    *
42    * @return the wrapped exception.
43    */

44   public Exception JavaDoc getException() {
45     return exception;
46   }
47
48   /**
49    * Retrieves (recursively) the root cause exception.
50    *
51    * @return the root cause exception.
52    */

53   public Exception JavaDoc getRootCause() {
54     if (exception instanceof ServiceLocatorException) {
55       return ((ServiceLocatorException) exception).getRootCause();
56     }
57     return exception == null ? this : exception;
58   }
59
60   public String JavaDoc toString() {
61     if (exception instanceof ServiceLocatorException) {
62       return ((ServiceLocatorException) exception).toString();
63     }
64     return exception == null ? super.toString() : exception.toString();
65   }
66 }
67
Popular Tags