01: /*
02: * $Id: InitializationException.java,v 1.28 2007/09/13 11:09:54 agoubard Exp $
03: *
04: * Copyright 2003-2007 Orange Nederland Breedband B.V.
05: * See the COPYRIGHT file for redistribution and use restrictions.
06: */
07: package org.xins.common.manageable;
08:
09: import org.xins.common.text.TextUtils;
10:
11: import org.xins.logdoc.ExceptionUtils;
12:
13: /**
14: * Exception thrown when the initialization of a <code>Manageable</code>
15: * object failed.
16: *
17: * @version $Revision: 1.28 $ $Date: 2007/09/13 11:09:54 $
18: * @author <a href="mailto:ernst@ernstdehaan.com">Ernst de Haan</a>
19: *
20: * @since XINS 1.0.0
21: *
22: * @see Manageable#init(org.xins.common.collections.PropertyReader)
23: */
24: public final class InitializationException extends Exception {
25:
26: /**
27: * Constructs a new <code>InitializationException</code> with the specified
28: * detail message.
29: *
30: * @param detail
31: * the detail message, or <code>null</code>.
32: */
33: public InitializationException(String detail) {
34: this (detail, null);
35: }
36:
37: /**
38: * Constructs a new <code>InitializationException</code> with the specified
39: * cause exception.
40: *
41: * @param cause
42: * the cause exception, or <code>null</code>.
43: */
44: public InitializationException(Throwable cause) {
45: this (null, cause);
46: }
47:
48: /**
49: * Constructs a new <code>InitializationException</code> with the specified
50: * detail message and cause exception.
51: *
52: * @param detail
53: * the detail message, or <code>null</code>.
54: *
55: * @param cause
56: * the cause exception, or <code>null</code>.
57: */
58: public InitializationException(String detail, Throwable cause) {
59: super (createMessage(detail, cause));
60: if (cause != null) {
61: ExceptionUtils.setCause(this , cause);
62: }
63: }
64:
65: /**
66: * Creates a message based on the specified constructor arguments.
67: *
68: * @param detail
69: * the detail message passed to the constructor, or <code>null</code>.
70: *
71: * @param cause
72: * the cause exception, or <code>null</code>.
73: *
74: * @return
75: * the message, never <code>null</code>.
76: */
77: private static String createMessage(String detail, Throwable cause) {
78:
79: String message = "Initialization failed";
80:
81: if (detail != null) {
82: message += ": \"" + detail + '"';
83: }
84:
85: if (cause != null) {
86: message += ". Caught " + cause.getClass().getName();
87:
88: String causeMessage = TextUtils.trim(cause.getMessage(),
89: null);
90: if (causeMessage != null) {
91: message += " with message \"" + causeMessage + '"';
92: }
93: }
94: message += '.';
95:
96: return message;
97: }
98: }
|