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);
}
}
Aggregations