| 1 | package com.thaiopensource.relaxng.jarv; |
| 2 | |
| 3 | import com.thaiopensource.relaxng.pattern.Pattern; |
| 4 | import com.thaiopensource.relaxng.sax.PatternValidator; |
| 5 | import com.thaiopensource.relaxng.pattern.ValidatorPatternBuilder; |
| 6 | import com.thaiopensource.xml.sax.CountingErrorHandler; |
| 7 | import org.iso_relax.verifier.VerifierHandler; |
| 8 | import org.xml.sax.ErrorHandler; |
| 9 | import org.xml.sax.SAXException; |
| 10 | |
| 11 | class VerifierHandlerImpl extends PatternValidator implements VerifierHandler { |
| 12 | private boolean complete = false; |
| 13 | private final CountingErrorHandler ceh; |
| 14 | |
| 15 | VerifierHandlerImpl(Pattern pattern, ValidatorPatternBuilder builder, CountingErrorHandler ceh) { |
| 16 | super(pattern, builder, ceh); |
| 17 | this.ceh = ceh; |
| 18 | } |
| 19 | |
| 20 | public void endDocument() throws SAXException { |
| 21 | super.endDocument(); |
| 22 | complete = true; |
| 23 | } |
| 24 | |
| 25 | public boolean isValid() throws IllegalStateException { |
| 26 | if (!complete) |
| 27 | throw new IllegalStateException(); |
| 28 | return !ceh.getHadErrorOrFatalError(); |
| 29 | } |
| 30 | |
| 31 | void setErrorHandler(ErrorHandler eh) { |
| 32 | ceh.setErrorHandler(eh); |
| 33 | } |
| 34 | |
| 35 | public void reset() { |
| 36 | super.reset(); |
| 37 | if (ceh != null) |
| 38 | ceh.reset(); |
| 39 | } |
| 40 | } |