001// 002// This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, v1.0.6-01/24/2006 06:15 PM(kohsuke)-fcs 003// See <a href="http://java.sun.com/xml/jaxb">http://java.sun.com/xml/jaxb</a> 004// Any modifications to this file will be lost upon recompilation of the source schema. 005// Generated on: 2012.10.03 at 04:27:47 AM CEST 006// 007 008package org.jdtaus.mojo.resource.model.impl.runtime; 009 010import javax.xml.bind.ValidationEvent; 011import javax.xml.bind.ValidationEventLocator; 012import javax.xml.bind.helpers.ValidationEventImpl; 013 014import org.xml.sax.ErrorHandler; 015import org.xml.sax.SAXException; 016import org.xml.sax.SAXParseException; 017 018import com.sun.xml.bind.validator.Locator; 019 020/** 021 * Receives errors through {@link ErrorHandler} and reports to the 022 * {@link SAXUnmarshallerHandler}. 023 * 024 * @author 025 * Kohsuke Kawaguchi (kohsuke.kawaguchi@sun.com) 026 */ 027public class ErrorHandlerAdaptor implements ErrorHandler { 028 029 /** the client event handler that will receive the validation events */ 030 private final SAXUnmarshallerHandler host; 031 032 /** the locator object responsible for filling in the validation event 033 * location info **/ 034 private final Locator locator; 035 036 public ErrorHandlerAdaptor( 037 SAXUnmarshallerHandler _host, Locator locator ) { 038 this.host = _host; 039 this.locator = locator; 040 } 041 042 public void error(SAXParseException exception) 043 throws SAXException { 044 045 propagateEvent( ValidationEvent.ERROR, exception ); 046 } 047 048 public void warning(SAXParseException exception) 049 throws SAXException { 050 051 propagateEvent( ValidationEvent.WARNING, exception ); 052 } 053 054 public void fatalError(SAXParseException exception) 055 throws SAXException { 056 057 propagateEvent( ValidationEvent.FATAL_ERROR, exception ); 058 } 059 060 private void propagateEvent( int severity, SAXParseException saxException ) 061 throws SAXException { 062 063 // get location info: 064 // sax locators simply use the location info embedded in the 065 // sax exception, dom locators keep a reference to their DOMScanner 066 // and call back to figure out where the error occurred. 067 ValidationEventLocator vel = 068 locator.getLocation( saxException ); 069 070 ValidationEventImpl ve = 071 new ValidationEventImpl( severity, saxException.getMessage(), vel ); 072 073 Exception e = saxException.getException(); 074 if( e != null ) { 075 ve.setLinkedException( e ); 076 } else { 077 ve.setLinkedException( saxException ); 078 } 079 080 // call the client's event handler. 081 host.handleEvent( ve, severity!=ValidationEvent.FATAL_ERROR ); 082 } 083}