1
2
3
4
5
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
61
62
63
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
77 host.handleEvent(ve, severity != ValidationEvent.FATAL_ERROR);
78 }
79 }