verinec.util
Class SchemaValidator

java.lang.Object
  extended by verinec.util.SchemaValidator

public class SchemaValidator
extends Object

Creates a validating parser and tries to parse a document with schema validation turned on. Needs the apache.org xerces XML parser.

Version:
$Revision: 543 $
Author:
david.buchmann at unifr.ch

Field Summary
private  Exception lastError
          The exception that caused a validation failure.
private  SAXBuilder xmlbuilder
          A SAX builder with schema validation turned on.
 
Constructor Summary
SchemaValidator()
          Create an instance of the SchemaValidator.
 
Method Summary
 Exception getLastError()
          Get the exception that caused a validation failure.
static void main(String[] args)
          Creates an instance of SchemaValidator and loads the document specified on the command line.
 boolean validate(Document xml)
          Validate a document with the schema validating parser.
 boolean validate(Element xml)
          Convenience method to validate an Element.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

xmlbuilder

private SAXBuilder xmlbuilder
A SAX builder with schema validation turned on.


lastError

private Exception lastError
The exception that caused a validation failure.

Constructor Detail

SchemaValidator

public SchemaValidator()
                throws VerinecException
Create an instance of the SchemaValidator. Initializes a SAXBuilder to use the Xerces parser and turns schema validation on.

Throws:
VerinecException - if the validator can not be instantiated.
Method Detail

main

public static void main(String[] args)
                 throws Throwable
Creates an instance of SchemaValidator and loads the document specified on the command line.
java verinec.util.SchemaValidator filename.xml

Parameters:
args - Expects one String denoting the filename to be parsed.
Throws:
Throwable - does not catch errors.

validate

public boolean validate(Element xml)
                 throws VerinecException
Convenience method to validate an Element.

Parameters:
xml - element to validate, variables resovled.
Returns:
True if valid, false otherwise.
Throws:
VerinecException - If the XML can not be serialized (Should never happen).
See Also:
validate(Document)

validate

public boolean validate(Document xml)
                 throws VerinecException
Validate a document with the schema validating parser. The schema references must be set correctly in the xml document. All variables have to be expanded. You can get the reason for an invalid document using getLastError immediately after using validate (beware of using the same instance in different threads...).

Parameters:
xml - The document to validate.
Returns:
True if valid, false otherwise.
Throws:
VerinecException - If the XML can not be serialized (Should never happen).

getLastError

public Exception getLastError()
Get the exception that caused a validation failure. Returns null if there was no error during the last validation within this instance of the validator.

Returns:
The exception that occured during the last validation

Copyright © 2005 Verinec, DIUF