001    //
002    // This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, v1.0.1-05/30/2003 05:06 AM(java_re)-fcs 
003    // See <a href="http://java.sun.com/xml/jaxb">http://java.sun.com/xml/jaxb</a> 
004    // Any modifications to this file will be lost upon recompilation of the source schema. 
005    // Generated on: 2004.10.11 at 12:13:34 EDT 
006    //
007    
008    /*
009     * Copyright 2003 Sun Microsystems, Inc. All rights reserved.
010     * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
011     */
012    
013    /*
014     * @(#)$Id: ErrorHandlerAdaptor.java,v 1.2.4.1 2003/05/28 20:17:16 kk122374 Exp $
015     */
016    package astronomy.data.spectra.impl.runtime;
017    
018    import javax.xml.bind.ValidationEvent;
019    import javax.xml.bind.ValidationEventLocator;
020    import javax.xml.bind.helpers.ValidationEventImpl;
021    
022    import org.xml.sax.ErrorHandler;
023    import org.xml.sax.SAXException;
024    import org.xml.sax.SAXParseException;
025    
026    import com.sun.xml.bind.validator.Locator;
027    
028    /**
029     * Receives errors through {@link ErrorHandler} and reports to the
030     * {@link SAXUnmarshallerHandler}.
031     * 
032     * @author
033     *     Kohsuke Kawaguchi (kohsuke.kawaguchi@sun.com)
034     */
035    public class ErrorHandlerAdaptor implements ErrorHandler {
036        
037        /** the client event handler that will receive the validation events */
038        private final SAXUnmarshallerHandler host;
039        
040        /** the locator object responsible for filling in the validation event
041         *  location info **/
042        private final Locator locator;
043       
044        public ErrorHandlerAdaptor(
045            SAXUnmarshallerHandler _host, Locator locator ) {
046            this.host = _host;
047            this.locator = locator;
048        }
049        
050        public void error(SAXParseException exception) 
051            throws SAXException {
052                
053            propagateEvent( ValidationEvent.ERROR, exception );
054        }
055        
056        public void warning(SAXParseException exception) 
057            throws SAXException {
058                
059            propagateEvent( ValidationEvent.WARNING, exception );
060        }
061        
062        public void fatalError(SAXParseException exception) 
063            throws SAXException {
064                
065            propagateEvent( ValidationEvent.FATAL_ERROR, exception );
066        }
067        
068        private void propagateEvent( int severity, SAXParseException saxException ) 
069            throws SAXException {
070                
071            // get location info:
072            //     sax locators simply use the location info embedded in the 
073            //     sax exception, dom locators keep a reference to their DOMScanner
074            //     and call back to figure out where the error occurred.
075            ValidationEventLocator vel = 
076                locator.getLocation( saxException );
077    
078            ValidationEventImpl ve = 
079                new ValidationEventImpl( severity, saxException.getMessage(), vel  );
080    
081            Exception e = saxException.getException();
082            if( e != null ) {
083                ve.setLinkedException( e );
084            } else {
085                ve.setLinkedException( saxException );
086            }
087            
088            // call the client's event handler.
089            host.handleEvent( ve, severity!=ValidationEvent.FATAL_ERROR );
090        }
091    }