KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > dream > InitializationException


1 /**
2  * Dream Copyright (C) 2003-2004 INRIA Rhone-Alpes
3  *
4  * This library is free software; you can redistribute it and/or modify it under
5  * the terms of the GNU Lesser General Public License as published by the Free
6  * Software Foundation; either version 2 of the License, or (at your option) any
7  * later version.
8  *
9  * This library is distributed in the hope that it will be useful, but WITHOUT
10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11  * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
12  * details.
13  *
14  * You should have received a copy of the GNU Lesser General Public License
15  * along with this library; if not, write to the Free Software Foundation, Inc.,
16  * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  *
18  * Contact: dream@objectweb.org
19  *
20  * Initial developer(s): Matthieu Leclercq
21  * Contributor(s):
22  */

23
24 package org.objectweb.dream;
25
26 import java.io.PrintStream JavaDoc;
27
28 import org.objectweb.fractal.api.Component;
29 import org.objectweb.fractal.api.Interface;
30 import org.objectweb.fractal.api.NoSuchInterfaceException;
31 import org.objectweb.fractal.julia.Util;
32
33 /**
34  * Exception thrown by {@link AbstractComponent#initComponent(Component)}.
35  */

36 public class InitializationException extends Exception JavaDoc
37 {
38
39   /**
40    * The exception that caused this exception. May be <tt>null</tt>.
41    */

42   private final Throwable JavaDoc exception;
43
44   /**
45    * The component whose life cycle state is illegal.
46    */

47   private transient Component component;
48
49   /**
50    * Constructs a new {@link InitializationException}exception.
51    *
52    * @param exception the cause of this exception. May be <tt>null</tt>.
53    * @param component the component whose life cycle state is illegal.
54    * @param message a detailed error message.
55    */

56   public InitializationException(final Throwable JavaDoc exception,
57       final Component component, final String JavaDoc message)
58   {
59     super(message);
60     this.exception = exception;
61     this.component = component;
62   }
63
64   /**
65    * Returns the exception that caused in this exception.
66    *
67    * @return the exception that caused this exception. May be <tt>null</tt>.
68    */

69
70   public Throwable JavaDoc getException()
71   {
72     return exception;
73   }
74
75   /**
76    * Returns the component whose life cycle state is illegal.
77    *
78    * @return the component whose life cycle state is illegal.
79    */

80
81   public Component getComponent()
82   {
83     if (component != null && !(component instanceof Interface))
84     {
85       try
86       {
87         return (Component) component.getFcInterface("component");
88       }
89       catch (NoSuchInterfaceException ignored)
90       {
91       }
92     }
93     return component;
94   }
95
96   // ---------------------------------------------------------------------------
97
// Overriden Exception methods
98
// ---------------------------------------------------------------------------
99

100   /**
101    * @see Throwable#toString()
102    */

103   public String JavaDoc toString()
104   {
105     StringBuffer JavaDoc buf = new StringBuffer JavaDoc();
106     buf.append("InitializationException: ");
107     buf.append(getMessage());
108     if (getComponent() != null)
109     {
110       buf.append(" (component = ");
111       Util.toString(getComponent(), buf);
112       buf.append(')');
113     }
114     return buf.toString();
115   }
116
117   /**
118    * @see Throwable#printStackTrace(PrintStream)
119    */

120   public void printStackTrace(final PrintStream JavaDoc s)
121   {
122     super.printStackTrace(s);
123     if (exception != null)
124     {
125       s.print("Caused by : ");
126       exception.printStackTrace(s);
127     }
128   }
129 }
Popular Tags