Search in sources :

Example 1 with Verifier

use of org.iso_relax.verifier.Verifier in project scheduling by ow2-proactive.

the class ValidationUtil method validate.

/**
 * Validates the job descriptor file against the specified schema.
 *
 * @param jobFile
 *            the job descriptor file
 * @param schemaIs
 *            the job schema
 *
 * @throws JobCreationException
 *             if the job descriptor is invalid
 */
public static void validate(File jobFile, InputStream schemaIs) throws SAXException, IOException, JobCreationException {
    try {
        XMLReader reader = XMLReaderFactory.createXMLReader("org.apache.xerces.parsers.SAXParser");
        VerifierFactory vfactory = new com.sun.msv.verifier.jarv.TheFactoryImpl();
        Schema schema = vfactory.compileSchema(schemaIs);
        Verifier verifier = schema.newVerifier();
        VerifierHandler handler = verifier.getVerifierHandler();
        ContentHandlerDecorator contentHandlerDecorator = new ContentHandlerDecorator(handler);
        reader.setContentHandler(contentHandlerDecorator);
        ValidationErrorHandler errHandler = new ValidationErrorHandler(contentHandlerDecorator);
        verifier.setErrorHandler(errHandler);
        reader.parse(jobFile.getAbsolutePath());
    } catch (SAXException se) {
        Throwable cause = se.getCause();
        if (cause != null && cause instanceof JobCreationException) {
            // unwrap
            throw (JobCreationException) cause;
        } else {
            throw se;
        }
    } catch (VerifierConfigurationException e) {
        throw new IllegalStateException(e);
    }
}
Also used : VerifierFactory(org.iso_relax.verifier.VerifierFactory) VerifierHandler(org.iso_relax.verifier.VerifierHandler) Schema(org.iso_relax.verifier.Schema) JobCreationException(org.ow2.proactive.scheduler.common.exception.JobCreationException) Verifier(org.iso_relax.verifier.Verifier) VerifierConfigurationException(org.iso_relax.verifier.VerifierConfigurationException) SAXException(org.xml.sax.SAXException) XMLReader(org.xml.sax.XMLReader)

Aggregations

Schema (org.iso_relax.verifier.Schema)1 Verifier (org.iso_relax.verifier.Verifier)1 VerifierConfigurationException (org.iso_relax.verifier.VerifierConfigurationException)1 VerifierFactory (org.iso_relax.verifier.VerifierFactory)1 VerifierHandler (org.iso_relax.verifier.VerifierHandler)1 JobCreationException (org.ow2.proactive.scheduler.common.exception.JobCreationException)1 SAXException (org.xml.sax.SAXException)1 XMLReader (org.xml.sax.XMLReader)1