1 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 ; 34 import java.io.PrintWriter ; 35 import java.io.ObjectOutputStream ; 36 import java.io.IOException ; 37 import java.io.ObjectInputStream ; 38 39 42 43 public class ChainedIllegalBindingException extends IllegalBindingException { 44 45 48 49 private final Throwable exception; 50 51 54 55 private transient Component clientComp; 56 57 60 61 private transient Component serverComp; 62 63 66 67 private final String clientItf; 68 69 73 74 private final String serverItf; 75 76 88 89 public ChainedIllegalBindingException ( 90 final Throwable exception, 91 final Component clientComponent, 92 final Component serverComponent, 93 final String clientItf, 94 final String serverItf, 95 final String 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 110 111 public Throwable getException () { 112 return exception; 113 } 114 115 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 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 153 154 public String getClientInterface () { 155 return clientItf; 156 } 157 158 164 165 public String getServerInterface () { 166 return serverItf; 167 } 168 169 173 178 179 public String toString () { 180 StringBuffer buf = new StringBuffer (); 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 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 215 216 public void printStackTrace (final PrintStream s) { 217 if (exception != null) { 218 s.println(this); 219 exception.printStackTrace(s); 220 } else { 221 super.printStackTrace(s); 222 } 223 } 224 225 230 231 public void printStackTrace (final PrintWriter 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 out) throws IOException { 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 in) 249 throws IOException , ClassNotFoundException 250 { 251 in.defaultReadObject(); 252 clientComp = (Component)in.readObject(); 253 serverComp = (Component)in.readObject(); 254 } 255 } 256 257 | Popular Tags |