View Javadoc

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: 2004.12.16 at 07:09:42 EST 
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          // 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 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  }