1 16 19 package com.sun.org.apache.xpath.internal; 20 21 import javax.xml.transform.TransformerException ; 22 23 import org.w3c.dom.Node ; 24 25 34 public class XPathException extends TransformerException 35 { 36 37 39 Object m_styleNode = null; 40 41 45 public Object getStylesheetNode() 46 { 47 return m_styleNode; 48 } 49 50 54 public void setStylesheetNode(Object styleNode) 55 { 56 m_styleNode = styleNode; 57 } 58 59 60 62 protected Exception m_exception; 63 64 69 public XPathException(String message, ExpressionNode ex) 70 { 71 super(message); 72 this.setLocator(ex); 73 setStylesheetNode(getStylesheetNode(ex)); 74 } 75 76 81 public XPathException(String message) 82 { 83 super(message); 84 } 85 86 87 92 public org.w3c.dom.Node getStylesheetNode(ExpressionNode ex) 93 { 94 95 ExpressionNode owner = getExpressionOwner(ex); 96 97 if (null != owner && owner instanceof org.w3c.dom.Node ) 98 { 99 return ((org.w3c.dom.Node )owner); 100 } 101 return null; 102 103 } 104 105 109 protected ExpressionNode getExpressionOwner(ExpressionNode ex) 110 { 111 ExpressionNode parent = ex.exprGetParent(); 112 while((null != parent) && (parent instanceof Expression)) 113 parent = parent.exprGetParent(); 114 return parent; 115 } 116 117 118 119 126 public XPathException(String message, Object styleNode) 127 { 128 129 super(message); 130 131 m_styleNode = styleNode; 132 } 133 134 143 public XPathException(String message, Node styleNode, Exception e) 144 { 145 146 super(message); 147 148 m_styleNode = styleNode; 149 this.m_exception = e; 150 } 151 152 159 public XPathException(String message, Exception e) 160 { 161 162 super(message); 163 164 this.m_exception = e; 165 } 166 167 173 public void printStackTrace(java.io.PrintStream s) 174 { 175 176 if (s == null) 177 s = System.err; 178 179 try 180 { 181 super.printStackTrace(s); 182 } 183 catch (Exception e){} 184 185 Throwable exception = m_exception; 186 187 for (int i = 0; (i < 10) && (null != exception); i++) 188 { 189 s.println("---------"); 190 exception.printStackTrace(s); 191 192 if (exception instanceof TransformerException ) 193 { 194 TransformerException se = (TransformerException ) exception; 195 Throwable prev = exception; 196 197 exception = se.getException(); 198 199 if (prev == exception) 200 break; 201 } 202 else 203 { 204 exception = null; 205 } 206 } 207 } 208 209 214 public String getMessage() 215 { 216 217 String lastMessage = super.getMessage(); 218 Throwable exception = m_exception; 219 220 while (null != exception) 221 { 222 String nextMessage = exception.getMessage(); 223 224 if (null != nextMessage) 225 lastMessage = nextMessage; 226 227 if (exception instanceof TransformerException ) 228 { 229 TransformerException se = (TransformerException ) exception; 230 Throwable prev = exception; 231 232 exception = se.getException(); 233 234 if (prev == exception) 235 break; 236 } 237 else 238 { 239 exception = null; 240 } 241 } 242 243 return (null != lastMessage) ? lastMessage : ""; 244 } 245 246 252 public void printStackTrace(java.io.PrintWriter s) 253 { 254 255 if (s == null) 256 s = new java.io.PrintWriter (System.err); 257 258 try 259 { 260 super.printStackTrace(s); 261 } 262 catch (Exception e){} 263 264 Throwable exception = m_exception; 265 266 for (int i = 0; (i < 10) && (null != exception); i++) 267 { 268 s.println("---------"); 269 270 try 271 { 272 exception.printStackTrace(s); 273 } 274 catch (Exception e) 275 { 276 s.println("Could not print stack trace..."); 277 } 278 279 if (exception instanceof TransformerException ) 280 { 281 TransformerException se = (TransformerException ) exception; 282 Throwable prev = exception; 283 284 exception = se.getException(); 285 286 if (prev == exception) 287 { 288 exception = null; 289 290 break; 291 } 292 } 293 else 294 { 295 exception = null; 296 } 297 } 298 } 299 300 306 public Throwable getException() 307 { 308 return m_exception; 309 } 310 } 311 | Popular Tags |