1 16 package org.apache.cocoon; 17 18 import java.io.IOException ; 19 import java.io.PrintStream ; 20 import java.io.PrintWriter ; 21 22 import org.apache.avalon.framework.CascadingThrowable; 23 import org.xml.sax.SAXParseException ; 24 import javax.xml.transform.TransformerException ; 25 import javax.xml.transform.SourceLocator ; 26 27 33 34 public class CascadingIOException 35 extends IOException 36 implements CascadingThrowable { 37 38 41 private final Throwable m_throwable; 42 43 44 47 public CascadingIOException(String message) { 48 this(message, null); 49 } 50 51 56 public CascadingIOException(Exception ex) { 57 this(ex.getMessage(), ex); 58 } 59 60 64 public CascadingIOException(String message, Throwable t) { 65 super( message ); 66 this.m_throwable = t; 67 } 68 69 74 public final Throwable getCause() 75 { 76 return this.m_throwable; 77 } 78 79 public String toString() { 80 StringBuffer s = new StringBuffer (); 81 s.append(super.toString()); 82 final Throwable t = getCause(); 83 if(t!=null) { 84 s.append(": "); 85 s.append( extraInfo(t) ); 87 s.append(t.toString()); 88 } 89 return s.toString(); 90 } 91 92 103 private String extraInfo( Throwable t ) { 104 StringBuffer sb = new StringBuffer (); 105 if (t instanceof SAXParseException ) { 106 SAXParseException spe = (SAXParseException )t; 107 sb.append( String.valueOf(spe.getSystemId())); 108 sb.append( ":" ); 109 sb.append( String.valueOf(spe.getLineNumber())); 110 sb.append( ":" ); 111 sb.append( String.valueOf(spe.getColumnNumber())); 112 sb.append( ":" ); 113 } else if (t instanceof TransformerException ) { 114 TransformerException transformerException = (TransformerException ) t; 115 SourceLocator sourceLocator = transformerException.getLocator(); 116 117 if( null != sourceLocator ) { 118 sb.append( String.valueOf(sourceLocator.getSystemId())); 119 sb.append( ":" ); 120 sb.append( String.valueOf(sourceLocator.getLineNumber())); 121 sb.append( ":" ); 122 sb.append( String.valueOf(sourceLocator.getColumnNumber())); 123 sb.append( ":" ); 124 } 125 } 126 return sb.toString(); 127 } 128 129 public void printStackTrace() { 130 super.printStackTrace(); 131 if(getCause()!=null) 132 getCause().printStackTrace(); 133 } 134 135 public void printStackTrace( PrintStream s ) { 136 super.printStackTrace(s); 137 if(getCause()!=null) 138 getCause().printStackTrace(s); 139 } 140 141 public void printStackTrace( PrintWriter s ) { 142 super.printStackTrace(s); 143 if(getCause()!=null) 144 getCause().printStackTrace(s); 145 } 146 147 } 148 149 | Popular Tags |