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: UnmarshallingEventHandlerAdaptor.java,v 1.7 2003/05/20 18:27:56 kk122374 Exp $ 015 */ 016 package astronomy.data.spectra.impl.runtime; 017 018 import javax.xml.bind.ValidationEvent; 019 import javax.xml.bind.helpers.ValidationEventImpl; 020 import javax.xml.bind.helpers.ValidationEventLocatorImpl; 021 022 import org.xml.sax.Attributes; 023 import org.xml.sax.ContentHandler; 024 import org.xml.sax.SAXException; 025 026 /** 027 * Redirects events to another SAX ContentHandler. 028 * 029 * <p> 030 * Note that the SAXException returned by the ContentHandler is 031 * unreported. So we have to catch them and report it, then rethrow 032 * it if necessary. 033 * 034 * @author 035 * Kohsuke Kawaguchi (kohsuke.kawaguchi@sun.com) 036 */ 037 public class UnmarshallingEventHandlerAdaptor implements UnmarshallingEventHandler { 038 039 protected final UnmarshallingContext context; 040 041 /** This handler will receive SAX events. */ 042 protected final ContentHandler handler; 043 044 public UnmarshallingEventHandlerAdaptor(UnmarshallingContext _ctxt,ContentHandler _handler) throws SAXException { 045 this.context = _ctxt; 046 this.handler = _handler; 047 048 // emulate the start of documents 049 try { 050 handler.setDocumentLocator(context.getLocator()); 051 handler.startDocument(); 052 } catch( SAXException e ) { 053 error(e); 054 } 055 } 056 057 public Object owner() { 058 return null; 059 } 060 061 062 // nest level of elements. 063 private int depth = 0; 064 065 public void enterAttribute(String uri, String local, String qname) throws SAXException { 066 } 067 068 public void enterElement(String uri, String local, String qname, Attributes atts) throws SAXException { 069 depth++; 070 try { 071 handler.startElement(uri,local,qname,atts); 072 } catch( SAXException e ) { 073 error(e); 074 } 075 context.pushAttributes(atts,true); 076 } 077 078 public void leaveAttribute(String uri, String local, String qname) throws SAXException { 079 } 080 081 public void leaveElement(String uri, String local, String qname) throws SAXException { 082 try { 083 handler.endElement(uri,local,qname); 084 } catch( SAXException e ) { 085 error(e); 086 } 087 context.popAttributes(); 088 089 depth--; 090 if(depth==0) { 091 // emulate the end of the document 092 try { 093 handler.endDocument(); 094 } catch( SAXException e ) { 095 error(e); 096 } 097 context.popContentHandler(); 098 } 099 } 100 101 public void text(String s) throws SAXException { 102 try { 103 handler.characters(s.toCharArray(),0,s.length()); 104 } catch( SAXException e ) { 105 error(e); 106 } 107 } 108 109 private void error( SAXException e ) throws SAXException { 110 context.handleEvent(new ValidationEventImpl( 111 ValidationEvent.ERROR, 112 e.getMessage(), 113 new ValidationEventLocatorImpl(context.getLocator()), 114 e 115 ), false); 116 } 117 118 public void leaveChild(int nextState) throws SAXException { 119 } 120 }