1 23 24 package org.objectweb.fractal.julia; 25 26 import org.objectweb.fractal.api.Component; 27 import org.objectweb.fractal.api.Interface; 28 import org.objectweb.fractal.api.NoSuchInterfaceException; 29 30 import java.io.PrintStream ; 31 import java.io.PrintWriter ; 32 import java.io.ObjectOutputStream ; 33 import java.io.IOException ; 34 import java.io.ObjectInputStream ; 35 36 39 40 public class ChainedNoSuchInterfaceException extends NoSuchInterfaceException { 41 42 45 46 private final Throwable exception; 47 48 51 52 private transient Component component; 53 54 62 63 public ChainedNoSuchInterfaceException ( 64 final Throwable exception, 65 final Component component, 66 final String message) 67 { 68 super(message); 69 this.exception = exception; 70 this.component = component; 71 } 72 73 78 79 public Throwable getException () { 80 return exception; 81 } 82 83 89 90 public Component getComponent () { 91 if (component != null && !(component instanceof Interface)) { 92 try { 93 return (Component)component.getFcInterface("component"); 94 } catch (NoSuchInterfaceException ignored) { 95 } 96 } 97 return component; 98 } 99 100 104 109 110 public String toString () { 111 StringBuffer buf = new StringBuffer (); 112 buf.append("NoSuchInterfaceException: "); 113 buf.append(getMessage()); 114 if (getComponent() != null) { 115 buf.append(" in component "); 116 Util.toString(getComponent(), buf); 117 } 118 return buf.toString(); 119 } 120 121 124 125 public void printStackTrace () { 126 if (exception != null) { 127 System.err.println(this); 128 exception.printStackTrace(); 129 } else { 130 super.printStackTrace(); 131 } 132 } 133 134 139 140 public void printStackTrace (final PrintStream s) { 141 if (exception != null) { 142 s.println(this); 143 exception.printStackTrace(s); 144 } else { 145 super.printStackTrace(s); 146 } 147 } 148 149 154 155 public void printStackTrace (final PrintWriter s) { 156 if (exception != null) { 157 s.write(this + "\n"); 158 exception.printStackTrace(s); 159 } else { 160 super.printStackTrace(s); 161 } 162 } 163 164 private void writeObject (final ObjectOutputStream out) throws IOException { 165 out.defaultWriteObject(); 166 Component c = getComponent(); 167 out.writeObject(c instanceof Interface ? c : null); 168 } 169 170 private void readObject (final ObjectInputStream in) 171 throws IOException , ClassNotFoundException 172 { 173 in.defaultReadObject(); 174 component = (Component)in.readObject(); 175 } 176 } 177 | Popular Tags |