1 51 package org.apache.fop.apps; 52 53 import org.xml.sax.SAXException ; 54 55 56 59 public class FOPException extends Exception { 60 61 private static final String EXCEPTION_SEPARATOR = "\n---------\n"; 62 63 private Throwable _exception; 64 private String systemId; 65 private int line; 66 private int column; 67 68 73 public FOPException(String message) { 74 super(message); 75 systemId = null; 76 line = -1; 77 column = -1; 78 } 79 80 public FOPException(String message, String systemId, int line, int column) { 81 super(message); 82 this.systemId = systemId; 83 this.line = line; 84 this.column = column; 85 } 86 87 public FOPException(Throwable e) { 88 super(e.getMessage()); 89 setException(e); 90 systemId = null; 91 line = -1; 92 column = -1; 93 } 94 95 public FOPException(Throwable e, String systemId, int line, int column) { 96 super(e.getMessage()); 97 setException(e); 98 this.systemId = systemId; 99 this.line = line; 100 this.column = column; 101 } 102 103 public FOPException(String message, Throwable e) { 104 super(message); 105 setException(e); 106 systemId = null; 107 line = -1; 108 column = -1; 109 } 110 111 public FOPException(String message, Throwable e, String systemId, int line, int column) { 112 super(message); 113 setException(e); 114 this.systemId = systemId; 115 this.line = line; 116 this.column = column; 117 } 118 119 protected void setException(Throwable t) { 120 _exception = t; 121 } 122 123 public Throwable getException() { 124 return _exception; 125 } 126 127 public void setLocation(String systemId, int line, int column) { 128 this.systemId = systemId; 129 this.line = line; 130 this.column = column; 131 } 132 133 public boolean isLocationSet() { 134 return line>=0; 135 } 136 137 protected Throwable getRootException() { 138 Throwable result = _exception; 139 140 if (result instanceof SAXException ) { 141 result = ((SAXException )result).getException(); 142 } 143 if (result instanceof java.lang.reflect.InvocationTargetException ) { 144 result = 145 ((java.lang.reflect.InvocationTargetException )result).getTargetException(); 146 } 147 if (result != _exception) { 148 return result; 149 } 150 return null; 151 } 152 153 public String getMessage() { 154 if (line>=0) { 155 return systemId+':'+line+':'+column+' '+super.getMessage(); 156 } else { 157 return super.getMessage(); 158 } 159 } 160 161 public void printStackTrace() { 162 synchronized (System.err) { 163 super.printStackTrace(); 164 if (_exception != null) { 165 System.err.println(EXCEPTION_SEPARATOR); 166 _exception.printStackTrace(); 167 } 168 if (getRootException() != null) { 169 System.err.println(EXCEPTION_SEPARATOR); 170 getRootException().printStackTrace(); 171 } 172 } 173 } 174 175 public void printStackTrace(java.io.PrintStream stream) { 176 synchronized (stream) { 177 super.printStackTrace(stream); 178 if (_exception != null) { 179 stream.println(EXCEPTION_SEPARATOR); 180 _exception.printStackTrace(stream); 181 } 182 if (getRootException() != null) { 183 stream.println(EXCEPTION_SEPARATOR); 184 getRootException().printStackTrace(stream); 185 } 186 } 187 } 188 189 public void printStackTrace(java.io.PrintWriter writer) { 190 synchronized (writer) { 191 super.printStackTrace(writer); 192 if (_exception != null) { 193 writer.println(EXCEPTION_SEPARATOR); 194 _exception.printStackTrace(writer); 195 } 196 if (getRootException() != null) { 197 writer.println(EXCEPTION_SEPARATOR); 198 getRootException().printStackTrace(writer); 199 } 200 } 201 } 202 203 } 204 | Popular Tags |