1 23 24 package org.objectweb.fractal.julia.control.lifecycle; 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.IllegalLifeCycleException; 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 ChainedIllegalLifeCycleException 44 extends IllegalLifeCycleException 45 { 46 47 50 51 private final Throwable exception; 52 53 56 57 private transient Component component; 58 59 66 67 public ChainedIllegalLifeCycleException ( 68 final Throwable exception, 69 final Component component, 70 final String message) 71 { 72 super(message); 73 this.exception = exception; 74 this.component = component; 75 } 76 77 82 83 public Throwable getException () { 84 return exception; 85 } 86 87 92 93 public Component getComponent () { 94 if (component != null && !(component instanceof Interface)) { 95 try { 96 return (Component)component.getFcInterface("component"); 97 } catch (NoSuchInterfaceException ignored) { 98 } 99 } 100 return component; 101 } 102 103 107 112 113 public String toString () { 114 StringBuffer buf = new StringBuffer (); 115 buf.append("IllegalLifeCycleException: "); 116 buf.append(getMessage()); 117 if (getComponent() != null) { 118 buf.append(" (component = "); 119 Util.toString(getComponent(), buf); 120 buf.append(')'); 121 } 122 return buf.toString(); 123 } 124 125 128 129 public void printStackTrace () { 130 if (exception != null) { 131 System.err.println(this); 132 exception.printStackTrace(); 133 } else { 134 super.printStackTrace(); 135 } 136 } 137 138 143 144 public void printStackTrace (final PrintStream s) { 145 if (exception != null) { 146 s.println(this); 147 exception.printStackTrace(s); 148 } else { 149 super.printStackTrace(s); 150 } 151 } 152 153 158 159 public void printStackTrace (final PrintWriter s) { 160 if (exception != null) { 161 s.write(this + "\n"); 162 exception.printStackTrace(s); 163 } else { 164 super.printStackTrace(s); 165 } 166 } 167 168 private void writeObject (final ObjectOutputStream out) throws IOException { 169 out.defaultWriteObject(); 170 Component c = getComponent(); 171 out.writeObject(c instanceof Interface ? c : null); 172 } 173 174 private void readObject (final ObjectInputStream in) 175 throws IOException , ClassNotFoundException 176 { 177 in.defaultReadObject(); 178 component = (Component)in.readObject(); 179 } 180 } 181 | Popular Tags |