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