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: ValidatingUnmarshaller.java,v 1.5 2003/05/14 18:36:19 lschwenk Exp $
015 */
016 package astronomy.data.spectra.impl.runtime;
017
018 import javax.xml.bind.JAXBException;
019 import javax.xml.bind.ValidationEvent;
020
021 import org.iso_relax.verifier.impl.ForkContentHandler;
022 import org.xml.sax.Attributes;
023 import org.xml.sax.SAXException;
024 import org.xml.sax.helpers.AttributesImpl;
025
026 import com.sun.msv.grammar.Grammar;
027 import com.sun.msv.verifier.Verifier;
028 import com.sun.msv.verifier.VerifierFilter;
029 import com.sun.msv.verifier.regexp.REDocumentDeclaration;
030 import com.sun.xml.bind.validator.Locator;
031
032 /**
033 * Filter implementation of SAXUnmarshallerHandler.
034 *
035 * <p>
036 * This component internally uses a VerifierFilter to validate
037 * SAX events that goes through this component.
038 * Discovered error information is just passed down to the next component.
039 *
040 * <p>
041 * This will enable the implementation to validate all sources of SAX events
042 * in the RI - XMLReader, DOMScanner
043 *
044 * SAX events will go the VerifierFilter and then to the SAXUnmarshaller...
045 *
046 */
047 public class ValidatingUnmarshaller extends ForkContentHandler
048 implements SAXUnmarshallerHandler {
049
050 /**
051 * Creates a new instance of ValidatingUnmarshaller.
052 */
053 public static ValidatingUnmarshaller create( Grammar grammar,
054 SAXUnmarshallerHandler _core,
055 Locator locator ) {
056
057 // create a VerifierFilter and configure it
058 // so that error messages will be sent to the core,
059 Verifier v = new Verifier(
060 new REDocumentDeclaration(grammar),
061 new ErrorHandlerAdaptor(_core,locator) );
062 v.setPanicMode( true );
063
064 return new ValidatingUnmarshaller(
065 new VerifierFilter( v ), _core );
066 }
067
068 private ValidatingUnmarshaller( VerifierFilter filter,
069 SAXUnmarshallerHandler _core ) {
070
071 super( filter, _core );
072 this.core = _core;
073 }
074
075 // delegate to the next component
076 public Object getResult() throws JAXBException, IllegalStateException {
077 return core.getResult();
078 }
079
080 public void handleEvent(ValidationEvent event, boolean canRecover ) throws SAXException {
081 // SAXUnmarshallerHandler already checks for RuntimeExceptions, so
082 // there is no need to wrap this call in a try/catch
083 core.handleEvent(event,canRecover);
084 }
085
086 private final SAXUnmarshallerHandler core;
087
088
089 private final AttributesImpl xsiLessAtts = new AttributesImpl();
090
091 public void startElement( String nsUri, String local, String qname, Attributes atts ) throws SAXException {
092 // create an attributes set for MSV that doesn't contains xsi:schemaLocation
093 xsiLessAtts.clear();
094 int len = atts.getLength();
095 for( int i=0; i<len; i++ ) {
096 String aUri = atts.getURI(i);
097 String aLocal = atts.getLocalName(i);
098 if(aUri.equals("http://www.w3.org/2001/XMLSchema-instance")
099 && (aLocal.equals("schemaLocation") ||
100 aLocal.equals("noNamespaceSchemaLocation") ||
101 aLocal.equals("type")))
102 continue;
103
104 // we do handle xsi:nil.
105 xsiLessAtts.addAttribute( aUri, aLocal,
106 atts.getQName(i), atts.getType(i), atts.getValue(i) );
107 }
108
109 super.startElement(nsUri,local,qname,xsiLessAtts);
110 }
111 }
112
113
114
115
116
117
118