KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > fractal > julia > control > binding > ChainedIllegalBindingException


1 /***
2  * Julia: France Telecom's implementation of the Fractal API
3  * Copyright (C) 2001-2002 France Telecom R&D
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18  *
19  * Contact: Eric.Bruneton@rd.francetelecom.com
20  *
21  * Author: Eric Bruneton
22  */

23
24 package org.objectweb.fractal.julia.control.binding;
25
26 import org.objectweb.fractal.api.Component;
27 import org.objectweb.fractal.api.Interface;
28 import org.objectweb.fractal.api.NoSuchInterfaceException;
29 import org.objectweb.fractal.api.control.IllegalBindingException;
30
31 import org.objectweb.fractal.julia.Util;
32
33 import java.io.PrintStream JavaDoc;
34 import java.io.PrintWriter JavaDoc;
35 import java.io.ObjectOutputStream JavaDoc;
36 import java.io.IOException JavaDoc;
37 import java.io.ObjectInputStream JavaDoc;
38
39 /**
40  * A sub class of the {@link IllegalBindingException} class.
41  */

42
43 public class ChainedIllegalBindingException extends IllegalBindingException {
44
45   /**
46    * The exception that caused this exception. May be <tt>null</tt>.
47    */

48
49   private final Throwable JavaDoc exception;
50
51   /**
52    * The client side component of the illegal binding.
53    */

54
55   private transient Component clientComp;
56
57   /**
58    * The server side component of the illegal binding. May be <tt>null</tt>.
59    */

60
61   private transient Component serverComp;
62
63   /**
64    * The name of the client interface of the illegal binding.
65    */

66
67   private final String JavaDoc clientItf;
68
69   /**
70    * The name of the server interface of the illegal binding. May be
71    * <tt>null</tt>.
72    */

73
74   private final String JavaDoc serverItf;
75
76   /**
77    * Constructs a new {@link ChainedIllegalBindingException} exception.
78    *
79    * @param exception the cause of this exception. May be <tt>null</tt>.
80    * @param clientComponent the client side component of the illegal binding.
81    * @param serverComponent the server side component of the illegal binding.
82    * May be <tt>null</tt>.
83    * @param clientItf the name of the client interface of the illegal binding.
84    * @param serverItf the name of the server interface of the illegal binding.
85    * May be <tt>null</tt>.
86    * @param message a detailed error message.
87    */

88
89   public ChainedIllegalBindingException (
90     final Throwable JavaDoc exception,
91     final Component clientComponent,
92     final Component serverComponent,
93     final String JavaDoc clientItf,
94     final String JavaDoc serverItf,
95     final String JavaDoc message)
96   {
97     super(message);
98     this.exception = exception;
99     this.clientComp = clientComponent;
100     this.serverComp = serverComponent;
101     this.clientItf = clientItf;
102     this.serverItf = serverItf;
103   }
104
105   /**
106    * Returns the exception that caused in this exception.
107    *
108    * @return the exception that caused this exception. May be <tt>null</tt>.
109    */

110
111   public Throwable JavaDoc getException () {
112     return exception;
113   }
114
115   /**
116    * Returns the client side component of the illegal binding.
117    *
118    * @return the client side component of the illegal binding.
119    */

120
121   public Component getClientComponent () {
122     if (clientComp != null && !(clientComp instanceof Interface)) {
123       try {
124         return (Component)clientComp.getFcInterface("component");
125       } catch (NoSuchInterfaceException ignored) {
126       }
127     }
128     return clientComp;
129   }
130
131   /**
132    * Returns the server side component of the illegal binding.
133    *
134    * @return the server side component of the illegal binding. May be
135    * <tt>null</tt>.
136    */

137
138   public Component getServerComponent () {
139     if (serverComp != null && !(serverComp instanceof Interface)) {
140       try {
141         return (Component)serverComp.getFcInterface("component");
142       } catch (NoSuchInterfaceException ignored) {
143       }
144     }
145     return serverComp;
146   }
147
148   /**
149    * Returns the name of the client interface of the illegal binding.
150    *
151    * @return the name of the client interface of the illegal binding.
152    */

153
154   public String JavaDoc getClientInterface () {
155     return clientItf;
156   }
157
158   /**
159    * Returns he name of the server interface of the illegal binding.
160    *
161    * @return the name of the server interface of the illegal binding. May be
162    * <tt>null</tt>.
163    */

164
165   public String JavaDoc getServerInterface () {
166     return serverItf;
167   }
168
169   // -------------------------------------------------------------------------
170
// Overriden Exception methods
171
// -------------------------------------------------------------------------
172

173   /**
174    * Returns a String representation of this exception.
175    *
176    * @return a String representation of this exception.
177    */

178
179   public String JavaDoc toString () {
180     StringBuffer JavaDoc buf = new StringBuffer JavaDoc();
181     buf.append("IllegalBindingException: ");
182     buf.append(getMessage());
183     buf.append(" (client interface = ");
184     Util.toString(getClientComponent(), buf);
185     buf.append('.');
186     buf.append(getClientInterface());
187     if (getServerComponent() != null) {
188       buf.append(", server interface = ");
189       Util.toString(getServerComponent(), buf);
190       buf.append('.');
191       buf.append(getServerInterface());
192     }
193     buf.append(')');
194     return buf.toString();
195   }
196
197   /**
198    * Prints the stack backtrace.
199    */

200
201   public void printStackTrace () {
202     if (exception != null) {
203       System.err.println(this);
204       exception.printStackTrace();
205     } else {
206       super.printStackTrace();
207     }
208   }
209
210   /**
211    * Prints this exception and its backtrace to the specified print stream.
212    *
213    * @param s <tt>PrintStream</tt> to use for output.
214    */

215
216   public void printStackTrace (final PrintStream JavaDoc s) {
217     if (exception != null) {
218       s.println(this);
219       exception.printStackTrace(s);
220     } else {
221       super.printStackTrace(s);
222     }
223   }
224
225   /**
226    * Prints this exception and its backtrace to the specified print writer.
227    *
228    * @param s <tt>PrintWriter</tt> to use for output.
229    */

230
231   public void printStackTrace (final PrintWriter JavaDoc s) {
232     if (exception != null) {
233       s.write(this + "\n");
234       exception.printStackTrace(s);
235     } else {
236       super.printStackTrace(s);
237     }
238   }
239   
240   private void writeObject (final ObjectOutputStream JavaDoc out) throws IOException JavaDoc {
241     out.defaultWriteObject();
242     Component c = getClientComponent();
243     out.writeObject(c instanceof Interface ? c : null);
244     c = getServerComponent();
245     out.writeObject(c instanceof Interface ? c : null);
246   }
247
248   private void readObject (final ObjectInputStream JavaDoc in)
249     throws IOException JavaDoc, ClassNotFoundException JavaDoc
250   {
251     in.defaultReadObject();
252     clientComp = (Component)in.readObject();
253     serverComp = (Component)in.readObject();
254   }
255 }
256
257
Popular Tags