KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > mvnforum > jaxb > db > impl > runtime > ValidatingUnmarshaller


1 //
2
// This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, v1.0.5-b16-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: 2005.12.17 at 09:43:27 AM GMT+07:00
6
//
7

8 package com.mvnforum.jaxb.db.impl.runtime;
9
10 import javax.xml.bind.JAXBException;
11 import javax.xml.bind.ValidationEvent;
12
13 import org.iso_relax.verifier.impl.ForkContentHandler;
14 import org.xml.sax.Attributes JavaDoc;
15 import org.xml.sax.SAXException JavaDoc;
16 import org.xml.sax.helpers.AttributesImpl JavaDoc;
17
18 import com.sun.msv.grammar.Grammar;
19 import com.sun.msv.verifier.Verifier;
20 import com.sun.msv.verifier.VerifierFilter;
21 import com.sun.msv.verifier.regexp.REDocumentDeclaration;
22 import com.sun.xml.bind.validator.Locator;
23
24 /**
25  * Filter implementation of SAXUnmarshallerHandler.
26  *
27  * <p>
28  * This component internally uses a VerifierFilter to validate
29  * SAX events that goes through this component.
30  * Discovered error information is just passed down to the next component.
31  *
32  * <p>
33  * This will enable the implementation to validate all sources of SAX events
34  * in the RI - XMLReader, DOMScanner
35  *
36  * SAX events will go the VerifierFilter and then to the SAXUnmarshaller...
37  *
38  */

39 public class ValidatingUnmarshaller extends ForkContentHandler
40     implements SAXUnmarshallerHandler {
41     
42     /**
43      * Creates a new instance of ValidatingUnmarshaller.
44      */

45     public static ValidatingUnmarshaller create( Grammar grammar,
46                             SAXUnmarshallerHandler _core,
47                             Locator locator ) {
48         
49         // create a VerifierFilter and configure it
50
// so that error messages will be sent to the core,
51
Verifier v = new Verifier(
52             new REDocumentDeclaration(grammar),
53             new ErrorHandlerAdaptor(_core,locator) );
54         v.setPanicMode( true );
55
56         return new ValidatingUnmarshaller(
57             new VerifierFilter( v ), _core );
58     }
59     
60     private ValidatingUnmarshaller( VerifierFilter filter,
61                             SAXUnmarshallerHandler _core ) {
62         
63         super( filter, _core );
64         this.core = _core;
65     }
66     
67     // delegate to the next component
68
public Object JavaDoc getResult() throws JAXBException, IllegalStateException JavaDoc {
69         return core.getResult();
70     }
71
72     public void handleEvent(ValidationEvent event, boolean canRecover ) throws SAXException JavaDoc {
73         // SAXUnmarshallerHandler already checks for RuntimeExceptions, so
74
// there is no need to wrap this call in a try/catch
75
core.handleEvent(event,canRecover);
76     }
77     
78     private final SAXUnmarshallerHandler core;
79     
80     
81     private final AttributesImpl JavaDoc xsiLessAtts = new AttributesImpl JavaDoc();
82     
83     public void startElement( String JavaDoc nsUri, String JavaDoc local, String JavaDoc qname, Attributes JavaDoc atts ) throws SAXException JavaDoc {
84         // create an attributes set for MSV that doesn't contains xsi:schemaLocation
85
xsiLessAtts.clear();
86         int len = atts.getLength();
87         for( int i=0; i<len; i++ ) {
88             String JavaDoc aUri = atts.getURI(i);
89             String JavaDoc aLocal = atts.getLocalName(i);
90             if(aUri.equals("http://www.w3.org/2001/XMLSchema-instance")
91             && (aLocal.equals("schemaLocation") ||
92                 aLocal.equals("noNamespaceSchemaLocation") //||
93
/*aLocal.equals("type")*/))
94                 continue;
95                 
96             // we do handle xsi:nil.
97
xsiLessAtts.addAttribute( aUri, aLocal,
98                 atts.getQName(i), atts.getType(i), atts.getValue(i) );
99         }
100         
101         super.startElement(nsUri,local,qname,xsiLessAtts);
102     }
103 }
104
105
106
107
108
109
110
111
Popular Tags