if ( !file.exists () ) throw new Exception("Error: schema file not found !");
InputStream istrm = new FileInputStream ( file );
InputSource is = new InputSource ( istrm );
SchemaFactory schf = SchemaFactory.lookup( SchemaFactory.NAMESPACE_SCHEMATRON );
Schema sch = schf.compileSchema( is );
Validator validator = sch.newValidator();
// set preprocessor parameters
if (args.length > 1)
validator.setProperty("phase", new String(args[1]));
ZTestBean tbean = new ZTestBean();
// measure validation speed
long time = System.currentTimeMillis ();
int i = 0;
SortedSet violations = null;
for (; i < 100; i++)
{
// perform validation
violations = validator.validate( tbean );
}
time = System.currentTimeMillis () - time;
System.out.println( "\nValidation performance:");
System.out.println( " validate() executed " + i + " times for a total of " + time + " ms");
System.out.println( "Avarage validation time: " + (time/i) + " ms " );