1
2
3
4
5
6
7
8 package net.sf.jour.config.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
25 * Kohsuke Kawaguchi (kohsuke.kawaguchi@sun.com)
26 */
27 public class ErrorHandlerAdaptor implements ErrorHandler {
28
29 /*** the client event handler that will receive the validation events */
30 private final SAXUnmarshallerHandler host;
31
32 /*** the locator object responsible for filling in the validation event
33 * location info **/
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
64
65
66
67 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
81 host.handleEvent( ve, severity!=ValidationEvent.FATAL_ERROR );
82 }
83 }