1 4 package org.jboss.xb.binding.sunday.unmarshalling; 5 6 import org.w3c.dom.DOMError ; 7 import org.w3c.dom.DOMErrorHandler ; 8 import org.w3c.dom.DOMLocator ; 9 10 public class XsdBinderLoggingErrorHandler implements DOMErrorHandler 11 { 12 private static XsdBinderLoggingErrorHandler errorHandler; 13 14 private XsdBinderLoggingErrorHandler() 16 { 17 } 18 19 public static XsdBinderLoggingErrorHandler newInstance() 20 { 21 if (errorHandler == null) 22 { 23 errorHandler = new XsdBinderLoggingErrorHandler(); 24 } 25 return errorHandler; 26 } 27 28 public boolean handleError(DOMError error) 29 { 30 switch (error.getSeverity()) 35 { 36 case DOMError.SEVERITY_ERROR: 37 XsdBinder.log.error(formatMessage(error)); 38 case DOMError.SEVERITY_FATAL_ERROR: 39 XsdBinder.log.fatal(formatMessage(error)); 40 case DOMError.SEVERITY_WARNING: 41 XsdBinder.log.warn(formatMessage(error)); 42 break; 43 } 44 return false; 45 } 46 47 String formatMessage(DOMError error) 48 { 49 StringBuffer buf = new StringBuffer (); 50 DOMLocator location = error.getLocation(); 51 if (location != null) 52 { 53 buf.append(location.getLineNumber()).append(':').append(location.getColumnNumber()); 54 } 55 else 56 { 57 buf.append("[location unavailable]"); 58 } 59 60 buf.append(' ').append(error.getMessage()); 61 return buf.toString(); 62 } 63 } | Popular Tags |