1 8 package com.sun.japex.testsuite.impl.runtime; 9 10 import javax.xml.bind.ValidationEvent; 11 import javax.xml.bind.ValidationEventLocator; 12 import javax.xml.bind.helpers.ValidationEventImpl; 13 14 import org.xml.sax.ErrorHandler ; 15 import org.xml.sax.SAXException ; 16 import org.xml.sax.SAXParseException ; 17 18 import com.sun.xml.bind.validator.Locator; 19 20 27 public class ErrorHandlerAdaptor implements ErrorHandler { 28 29 30 private final SAXUnmarshallerHandler host; 31 32 34 private final Locator locator; 35 36 public ErrorHandlerAdaptor( 37 SAXUnmarshallerHandler _host, Locator locator ) { 38 this.host = _host; 39 this.locator = locator; 40 } 41 42 public void error(SAXParseException exception) 43 throws SAXException { 44 45 propagateEvent( ValidationEvent.ERROR, exception ); 46 } 47 48 public void warning(SAXParseException exception) 49 throws SAXException { 50 51 propagateEvent( ValidationEvent.WARNING, exception ); 52 } 53 54 public void fatalError(SAXParseException exception) 55 throws SAXException { 56 57 propagateEvent( ValidationEvent.FATAL_ERROR, exception ); 58 } 59 60 private void propagateEvent( int severity, SAXParseException saxException ) 61 throws SAXException { 62 63 ValidationEventLocator vel = 68 locator.getLocation( saxException ); 69 70 ValidationEventImpl ve = 71 new ValidationEventImpl( severity, saxException.getMessage(), vel ); 72 73 Exception e = saxException.getException(); 74 if( e != null ) { 75 ve.setLinkedException( e ); 76 } else { 77 ve.setLinkedException( saxException ); 78 } 79 80 host.handleEvent( ve, severity!=ValidationEvent.FATAL_ERROR ); 82 } 83 } 84 | Popular Tags |