KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > japex > testsuite > impl > runtime > ErrorHandlerAdaptor


1 //
2
// This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, v1.0.3-b18-fcs
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.14 at 12:02:17 PDT
6
//
7

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 JavaDoc;
15 import org.xml.sax.SAXException JavaDoc;
16 import org.xml.sax.SAXParseException JavaDoc;
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 JavaDoc {
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 JavaDoc exception)
43         throws SAXException JavaDoc {
44             
45         propagateEvent( ValidationEvent.ERROR, exception );
46     }
47     
48     public void warning(SAXParseException JavaDoc exception)
49         throws SAXException JavaDoc {
50             
51         propagateEvent( ValidationEvent.WARNING, exception );
52     }
53     
54     public void fatalError(SAXParseException JavaDoc exception)
55         throws SAXException JavaDoc {
56             
57         propagateEvent( ValidationEvent.FATAL_ERROR, exception );
58     }
59     
60     private void propagateEvent( int severity, SAXParseException JavaDoc saxException )
61         throws SAXException JavaDoc {
62             
63         // get location info:
64
// sax locators simply use the location info embedded in the
65
// sax exception, dom locators keep a reference to their DOMScanner
66
// and call back to figure out where the error occurred.
67
ValidationEventLocator vel =
68             locator.getLocation( saxException );
69
70         ValidationEventImpl ve =
71             new ValidationEventImpl( severity, saxException.getMessage(), vel );
72
73         Exception JavaDoc e = saxException.getException();
74         if( e != null ) {
75             ve.setLinkedException( e );
76         } else {
77             ve.setLinkedException( saxException );
78         }
79         
80         // call the client's event handler.
81
host.handleEvent( ve, severity!=ValidationEvent.FATAL_ERROR );
82     }
83 }
84
Popular Tags