jdk/test/javax/xml/jaxp/testng/validation/SpecialCaseErrorHandler.java
author joehw
Mon, 13 Oct 2014 14:11:20 -0700
changeset 27037 5a6ef51923c4
permissions -rw-r--r--
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java Reviewed-by: lancea
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
27037
5a6ef51923c4 8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
diff changeset
     1
package validation;
5a6ef51923c4 8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
diff changeset
     2
5a6ef51923c4 8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
diff changeset
     3
import java.util.HashMap;
5a6ef51923c4 8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
diff changeset
     4
import java.util.Iterator;
5a6ef51923c4 8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
diff changeset
     5
5a6ef51923c4 8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
diff changeset
     6
import org.xml.sax.ErrorHandler;
5a6ef51923c4 8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
diff changeset
     7
import org.xml.sax.SAXException;
5a6ef51923c4 8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
diff changeset
     8
import org.xml.sax.SAXParseException;
5a6ef51923c4 8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
diff changeset
     9
5a6ef51923c4 8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
diff changeset
    10
public class SpecialCaseErrorHandler implements ErrorHandler {
5a6ef51923c4 8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
diff changeset
    11
    public static final boolean DEBUG = false;
5a6ef51923c4 8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
diff changeset
    12
5a6ef51923c4 8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
diff changeset
    13
    private HashMap errors;
5a6ef51923c4 8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
diff changeset
    14
5a6ef51923c4 8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
diff changeset
    15
    public SpecialCaseErrorHandler(String[] specialCases) {
5a6ef51923c4 8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
diff changeset
    16
        errors = new HashMap();
5a6ef51923c4 8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
diff changeset
    17
        for (int i = 0; i < specialCases.length; ++i) {
5a6ef51923c4 8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
diff changeset
    18
            errors.put(specialCases[i], Boolean.FALSE);
5a6ef51923c4 8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
diff changeset
    19
        }
5a6ef51923c4 8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
diff changeset
    20
    }
5a6ef51923c4 8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
diff changeset
    21
5a6ef51923c4 8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
diff changeset
    22
    public void reset() {
5a6ef51923c4 8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
diff changeset
    23
        for (Iterator iter = errors.keySet().iterator(); iter.hasNext();) {
5a6ef51923c4 8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
diff changeset
    24
            String error = (String) iter.next();
5a6ef51923c4 8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
diff changeset
    25
            errors.put(error, Boolean.FALSE);
5a6ef51923c4 8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
diff changeset
    26
        }
5a6ef51923c4 8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
diff changeset
    27
    }
5a6ef51923c4 8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
diff changeset
    28
5a6ef51923c4 8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
diff changeset
    29
    public void warning(SAXParseException arg0) throws SAXException {
5a6ef51923c4 8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
diff changeset
    30
        if (DEBUG) {
5a6ef51923c4 8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
diff changeset
    31
            System.err.println(arg0.getMessage());
5a6ef51923c4 8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
diff changeset
    32
        }
5a6ef51923c4 8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
diff changeset
    33
    }
5a6ef51923c4 8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
diff changeset
    34
5a6ef51923c4 8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
diff changeset
    35
    public void error(SAXParseException arg0) throws SAXException {
5a6ef51923c4 8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
diff changeset
    36
        if (DEBUG) {
5a6ef51923c4 8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
diff changeset
    37
            System.err.println(arg0.getMessage());
5a6ef51923c4 8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
diff changeset
    38
        }
5a6ef51923c4 8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
diff changeset
    39
        for (Iterator iter = errors.keySet().iterator(); iter.hasNext();) {
5a6ef51923c4 8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
diff changeset
    40
            String error = (String) iter.next();
5a6ef51923c4 8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
diff changeset
    41
            if (arg0.getMessage().startsWith(error)) {
5a6ef51923c4 8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
diff changeset
    42
                errors.put(error, Boolean.TRUE);
5a6ef51923c4 8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
diff changeset
    43
            }
5a6ef51923c4 8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
diff changeset
    44
        }
5a6ef51923c4 8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
diff changeset
    45
    }
5a6ef51923c4 8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
diff changeset
    46
5a6ef51923c4 8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
diff changeset
    47
    public void fatalError(SAXParseException arg0) throws SAXException {
5a6ef51923c4 8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
diff changeset
    48
        throw arg0;
5a6ef51923c4 8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
diff changeset
    49
    }
5a6ef51923c4 8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
diff changeset
    50
5a6ef51923c4 8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
diff changeset
    51
    public boolean specialCaseFound(String key) {
5a6ef51923c4 8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
diff changeset
    52
        return ((Boolean) errors.get(key)).booleanValue();
5a6ef51923c4 8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
diff changeset
    53
    }
5a6ef51923c4 8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
diff changeset
    54
}