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