1 17 package org.apache.ws.jaxme.xs.parser.impl; 18 19 import java.io.PrintStream ; 20 import java.io.PrintWriter ; 21 22 import org.xml.sax.Locator ; 23 import org.xml.sax.SAXException ; 24 import org.xml.sax.SAXParseException ; 25 26 27 32 public class LocSAXException extends SAXParseException { 33 public static String formatMsg(String pMsg, String pPublicId, String pSystemId, int pLineNumber, int pColNumber) { 34 StringBuffer sb = new StringBuffer (); 35 if (pSystemId != null) { 36 sb.append(pSystemId); 37 } 38 if (pLineNumber != -1) { 39 if (sb.length() > 0) { 40 sb.append(", "); 41 } 42 sb.append("line ").append(pLineNumber); 43 } 44 if (pColNumber != -1) { 45 if (sb.length() > 0) { 46 sb.append(", "); 47 } 48 sb.append("column ").append(pColNumber); 49 } 50 if (sb.length() == 0) { 51 return "" + pMsg; 52 } else { 53 return "At " + sb + ": " + pMsg; 54 } 55 } 56 57 private static String formatMsg(String pMsg, Locator pLocator) { 58 if (pLocator == null) { 59 return pMsg; 60 } else { 61 return formatMsg(pMsg, pLocator.getPublicId(), pLocator.getSystemId(), pLocator.getLineNumber(), pLocator.getColumnNumber()); 62 } 63 } 64 65 public LocSAXException(String pMsg, String pPublicId, String pSystemId, 66 int pLineNumber, int pColumnNumber, Exception pException) { 67 super(formatMsg(pMsg, pPublicId, pSystemId, pLineNumber, pColumnNumber), 68 pPublicId, pSystemId, pLineNumber, pColumnNumber, pException); 69 } 70 71 public LocSAXException(String pMsg, String pPublicId, String pSystemId, 72 int pLineNumber, int pColumnNumber) { 73 super(formatMsg(pMsg, pPublicId, pSystemId, pLineNumber, pColumnNumber), 74 pPublicId, pSystemId, pLineNumber, pColumnNumber); 75 } 76 77 public LocSAXException(String pMsg, Locator pLocator, Exception pException) { 78 super(formatMsg(pMsg, pLocator), pLocator, pException); 79 } 80 81 public LocSAXException(String pMsg, Locator pLocator) { 82 super(formatMsg(pMsg, pLocator), pLocator); 83 } 84 85 public void printStackTrace(PrintStream pStream) { 86 super.printStackTrace(pStream); 87 Exception e = getException(); 88 while (e != null) { 89 pStream.println("Caused by:"); 90 e.printStackTrace(pStream); 91 if (e instanceof SAXException ) { 92 e = ((SAXException ) e).getException(); 93 } else { 94 e = null; 95 } 96 } 97 } 98 99 public void printStackTrace(PrintWriter pWriter) { 100 super.printStackTrace(pWriter); 101 Exception e = getException(); 102 while (e != null) { 103 pWriter.println("Caused by:"); 104 e.printStackTrace(pWriter); 105 if (e instanceof SAXException ) { 106 e = ((SAXException ) e).getException(); 107 } else { 108 e = null; 109 } 110 } 111 } 112 } 113 | Popular Tags |