1 23 24 package org.objectweb.fractal.julia.control.content; 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.IllegalContentException; 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 ChainedIllegalContentException extends IllegalContentException { 44 45 48 49 private final Throwable exception; 50 51 54 55 private transient Component component; 56 57 61 62 private transient Component content; 63 64 73 74 public ChainedIllegalContentException ( 75 final Throwable exception, 76 final Component component, 77 final Component content, 78 final String message) 79 { 80 super(message); 81 this.exception = exception; 82 this.component = component; 83 this.content = content; 84 } 85 86 91 92 public Throwable getException () { 93 return exception; 94 } 95 96 101 102 public Component getComponent () { 103 if (component != null && !(component instanceof Interface)) { 104 try { 105 return (Component)component.getFcInterface("component"); 106 } catch (NoSuchInterfaceException ignored) { 107 } 108 } 109 return component; 110 } 111 112 121 122 public Component getContent () { 123 if (content != null && !(content instanceof Interface)) { 124 try { 125 return (Component)content.getFcInterface("component"); 126 } catch (NoSuchInterfaceException ignored) { 127 } 128 } 129 return content; 130 } 131 132 136 141 142 public String toString () { 143 StringBuffer buf = new StringBuffer (); 144 buf.append("IllegalContentException: "); 145 buf.append(getMessage()); 146 buf.append(" (super component = "); 147 Util.toString(getComponent(), buf); 148 if (getContent() != null) { 149 buf.append(", sub component = "); 150 Util.toString(getContent(), buf); 151 } 152 buf.append(')'); 153 return buf.toString(); 154 } 155 156 159 160 public void printStackTrace () { 161 if (exception != null) { 162 System.err.println(this); 163 exception.printStackTrace(); 164 } else { 165 super.printStackTrace(); 166 } 167 } 168 169 174 175 public void printStackTrace (final PrintStream s) { 176 if (exception != null) { 177 s.println(this); 178 exception.printStackTrace(s); 179 } else { 180 super.printStackTrace(s); 181 } 182 } 183 184 189 190 public void printStackTrace (final PrintWriter s) { 191 if (exception != null) { 192 s.write(this + "\n"); 193 exception.printStackTrace(s); 194 } else { 195 super.printStackTrace(s); 196 } 197 } 198 199 private void writeObject (final ObjectOutputStream out) throws IOException { 200 out.defaultWriteObject(); 201 Component c = getComponent(); 202 out.writeObject(c instanceof Interface ? c : null); 203 c = getContent(); 204 out.writeObject(c instanceof Interface ? c : null); 205 } 206 207 private void readObject (final ObjectInputStream in) 208 throws IOException , ClassNotFoundException 209 { 210 in.defaultReadObject(); 211 component = (Component)in.readObject(); 212 content = (Component)in.readObject(); 213 } 214 } 215 | Popular Tags |