View Javadoc

1   //
2   // This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, v@@BUILD_VERSION@@ 
3   // 	See <a href="http://java.sun.com/xml/jaxb">http://java.sun.com/xml/jaxb</a> 
4   // 	Any modifications to this file will be lost upon recompilation of the source schema. 
5   // 	Generated on: 2005.06.30 um 05:21:08 CEST 
6   //
7   
8   package de.nierbeck.timeTrack.model.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  /***
21   * Receives errors through {@link ErrorHandler} and reports to the
22   * {@link SAXUnmarshallerHandler}.
23   * 
24   * @author Kohsuke Kawaguchi (kohsuke.kawaguchi@sun.com)
25   */
26  public class ErrorHandlerAdaptor implements ErrorHandler {
27  
28  	/*** the client event handler that will receive the validation events */
29  	private final SAXUnmarshallerHandler host;
30  
31  	/****************************************************************************
32  	 * the locator object responsible for filling in the validation event
33  	 * location info
34  	 **************************************************************************/
35  	private final Locator locator;
36  
37  	public ErrorHandlerAdaptor(SAXUnmarshallerHandler _host, Locator locator) {
38  		this.host = _host;
39  		this.locator = locator;
40  	}
41  
42  	public void error(SAXParseException exception) throws SAXException {
43  
44  		propagateEvent(ValidationEvent.ERROR, exception);
45  	}
46  
47  	public void warning(SAXParseException exception) throws SAXException {
48  
49  		propagateEvent(ValidationEvent.WARNING, exception);
50  	}
51  
52  	public void fatalError(SAXParseException exception) throws SAXException {
53  
54  		propagateEvent(ValidationEvent.FATAL_ERROR, exception);
55  	}
56  
57  	private void propagateEvent(int severity, SAXParseException saxException)
58  			throws SAXException {
59  
60  		// get location info:
61  		// sax locators simply use the location info embedded in the
62  		// sax exception, dom locators keep a reference to their DOMScanner
63  		// and call back to figure out where the error occurred.
64  		ValidationEventLocator vel = locator.getLocation(saxException);
65  
66  		ValidationEventImpl ve = new ValidationEventImpl(severity, saxException
67  				.getMessage(), vel);
68  
69  		Exception e = saxException.getException();
70  		if (e != null) {
71  			ve.setLinkedException(e);
72  		} else {
73  			ve.setLinkedException(saxException);
74  		}
75  
76  		// call the client's event handler.
77  		host.handleEvent(ve, severity != ValidationEvent.FATAL_ERROR);
78  	}
79  }