001: //
002: // This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, v1.0.5-b16-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: 2005.12.17 at 09:43:27 AM GMT+07:00
006: //
007:
008: package com.mvnforum.jaxb.db.impl.runtime;
009:
010: import javax.xml.bind.JAXBException;
011: import javax.xml.bind.ValidationEvent;
012:
013: import org.iso_relax.verifier.impl.ForkContentHandler;
014: import org.xml.sax.Attributes;
015: import org.xml.sax.SAXException;
016: import org.xml.sax.helpers.AttributesImpl;
017:
018: import com.sun.msv.grammar.Grammar;
019: import com.sun.msv.verifier.Verifier;
020: import com.sun.msv.verifier.VerifierFilter;
021: import com.sun.msv.verifier.regexp.REDocumentDeclaration;
022: import 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: */
039: public 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, Locator locator) {
047:
048: // create a VerifierFilter and configure it
049: // so that error messages will be sent to the core,
050: Verifier v = new Verifier(new REDocumentDeclaration(grammar),
051: new ErrorHandlerAdaptor(_core, locator));
052: v.setPanicMode(true);
053:
054: return new ValidatingUnmarshaller(new VerifierFilter(v), _core);
055: }
056:
057: private ValidatingUnmarshaller(VerifierFilter filter,
058: SAXUnmarshallerHandler _core) {
059:
060: super (filter, _core);
061: this .core = _core;
062: }
063:
064: // delegate to the next component
065: public Object getResult() throws JAXBException,
066: IllegalStateException {
067: return core.getResult();
068: }
069:
070: public void handleEvent(ValidationEvent event, boolean canRecover)
071: throws SAXException {
072: // SAXUnmarshallerHandler already checks for RuntimeExceptions, so
073: // there is no need to wrap this call in a try/catch
074: core.handleEvent(event, canRecover);
075: }
076:
077: private final SAXUnmarshallerHandler core;
078:
079: private final AttributesImpl xsiLessAtts = new AttributesImpl();
080:
081: public void startElement(String nsUri, String local, String qname,
082: Attributes atts) throws SAXException {
083: // create an attributes set for MSV that doesn't contains xsi:schemaLocation
084: xsiLessAtts.clear();
085: int len = atts.getLength();
086: for (int i = 0; i < len; i++) {
087: String aUri = atts.getURI(i);
088: String aLocal = atts.getLocalName(i);
089: if (aUri
090: .equals("http://www.w3.org/2001/XMLSchema-instance")
091: && (aLocal.equals("schemaLocation") || aLocal
092: .equals("noNamespaceSchemaLocation") //||
093: /*aLocal.equals("type")*/))
094: continue;
095:
096: // we do handle xsi:nil.
097: xsiLessAtts.addAttribute(aUri, aLocal, atts.getQName(i),
098: atts.getType(i), atts.getValue(i));
099: }
100:
101: super.startElement(nsUri, local, qname, xsiLessAtts);
102: }
103: }
|