View Javadoc

1   //
2   // This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, v@@BUILD_VERSION@@ 
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.06.30 um 05:21:08 CEST 
6   //
7   
8   package de.nierbeck.timeTrack.model.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;
15  import org.xml.sax.SAXException;
16  import org.xml.sax.helpers.AttributesImpl;
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 SAX events that
29   * goes through this component. Discovered error information is just passed down
30   * to the next component.
31   * 
32   * <p>
33   * This will enable the implementation to validate all sources of SAX events in
34   * 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 implements
40  		SAXUnmarshallerHandler {
41  
42  	/***
43  	 * Creates a new instance of ValidatingUnmarshaller.
44  	 */
45  	public static ValidatingUnmarshaller create(Grammar grammar,
46  			SAXUnmarshallerHandler _core, Locator locator) {
47  
48  		// create a VerifierFilter and configure it
49  		// so that error messages will be sent to the core,
50  		Verifier v = new Verifier(new REDocumentDeclaration(grammar),
51  				new ErrorHandlerAdaptor(_core, locator));
52  		v.setPanicMode(true);
53  
54  		return new ValidatingUnmarshaller(new VerifierFilter(v), _core);
55  	}
56  
57  	private ValidatingUnmarshaller(VerifierFilter filter,
58  			SAXUnmarshallerHandler _core) {
59  
60  		super(filter, _core);
61  		this.core = _core;
62  	}
63  
64  	// delegate to the next component
65  	public Object getResult() throws JAXBException, IllegalStateException {
66  		return core.getResult();
67  	}
68  
69  	public void handleEvent(ValidationEvent event, boolean canRecover)
70  			throws SAXException {
71  		// SAXUnmarshallerHandler already checks for RuntimeExceptions, so
72  		// there is no need to wrap this call in a try/catch
73  		core.handleEvent(event, canRecover);
74  	}
75  
76  	private final SAXUnmarshallerHandler core;
77  
78  	private final AttributesImpl xsiLessAtts = new AttributesImpl();
79  
80  	public void startElement(String nsUri, String local, String qname,
81  			Attributes atts) throws SAXException {
82  		// create an attributes set for MSV that doesn't contains
83  		// xsi:schemaLocation
84  		xsiLessAtts.clear();
85  		int len = atts.getLength();
86  		for (int i = 0; i < len; i++) {
87  			String aUri = atts.getURI(i);
88  			String aLocal = atts.getLocalName(i);
89  			if (aUri.equals("http://www.w3.org/2001/XMLSchema-instance")
90  					&& (aLocal.equals("schemaLocation") || aLocal
91  							.equals("noNamespaceSchemaLocation") // ||
92  					/* aLocal.equals("type") */))
93  				continue;
94  
95  			// we do handle xsi:nil.
96  			xsiLessAtts.addAttribute(aUri, aLocal, atts.getQName(i), atts
97  					.getType(i), atts.getValue(i));
98  		}
99  
100 		super.startElement(nsUri, local, qname, xsiLessAtts);
101 	}
102 }