issrg.pba.rbac.xmlpolicy.schemachecking
Class W3CXMLSchemaValidator

java.lang.Object
  extended by issrg.pba.rbac.xmlpolicy.schemachecking.W3CXMLSchemaValidator
All Implemented Interfaces:
SchemaValidatorInterface

public class W3CXMLSchemaValidator
extends java.lang.Object
implements SchemaValidatorInterface

Class that abstracts the W3C XML Schema validation process. It is an implementation of the SchemaValidatorInterface.

Author:
Dimitry Bragin

Constructor Summary
W3CXMLSchemaValidator()
          Create a Validator instance with the default Schema as specified in schema_checking.properties file.
W3CXMLSchemaValidator(java.io.File schemaFile)
          Create a Validator instance with the Schema represented by the given File object.
 
Method Summary
static java.lang.String getExceptionDiagnostic(org.xml.sax.SAXParseException ex)
          Get a meaningful report about a validation exception.
 javax.xml.validation.Schema getSchema()
          Get the Schema used by the Validator to check instance documents.
 void setSchema(javax.xml.validation.Schema schema)
          Set the Schema used by the Validator to check instance documents.
 void validate(org.w3c.dom.Node r)
          Checks if xml represented by a node is valid according to the current schema.
 void validate(java.io.Reader r)
          Checks if xml content represented by a Reader is valid according to the current schema.
 void validate(javax.xml.transform.Source source)
          Check if xml represented by a Source is valid according to the current schema.
 void validate(java.lang.String s)
          Checks if a given xml string is valid according to the current schema.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

W3CXMLSchemaValidator

public W3CXMLSchemaValidator()
                      throws org.xml.sax.SAXException,
                             java.io.IOException
Create a Validator instance with the default Schema as specified in schema_checking.properties file. This constructor uses CustomisePERMIS.getDefaultSchemaLocation() method to determine the path for the default schema.

Throws:
org.xml.sax.SAXException - Thrown if parsing of the Schema file fails
java.io.IOException - Thrown is a file operation fails

W3CXMLSchemaValidator

public W3CXMLSchemaValidator(java.io.File schemaFile)
                      throws org.xml.sax.SAXException,
                             java.io.IOException
Create a Validator instance with the Schema represented by the given File object.

Parameters:
schemaFile - File that contains the Schema to be used
Throws:
org.xml.sax.SAXException - Thrown if parsing of the Schema file fails
java.io.IOException - Thrown is a file operation fails
Method Detail

getSchema

public javax.xml.validation.Schema getSchema()
Get the Schema used by the Validator to check instance documents.

Specified by:
getSchema in interface SchemaValidatorInterface
Returns:
The Schema used by the Validator to check instance documents

setSchema

public void setSchema(javax.xml.validation.Schema schema)
Set the Schema used by the Validator to check instance documents.

Specified by:
setSchema in interface SchemaValidatorInterface
Parameters:
schema - Schema to be used for validation

validate

public void validate(java.lang.String s)
              throws org.xml.sax.SAXException,
                     java.io.IOException
Checks if a given xml string is valid according to the current schema.

Specified by:
validate in interface SchemaValidatorInterface
Parameters:
s - String to be validated
Throws:
org.xml.sax.SAXException - If parsing of the schema instance fails
java.io.IOException - Thrown on IO error

validate

public void validate(java.io.Reader r)
              throws org.xml.sax.SAXException,
                     java.io.IOException
Checks if xml content represented by a Reader is valid according to the current schema.

Specified by:
validate in interface SchemaValidatorInterface
Parameters:
r - Reader accessing the xml content
Throws:
org.xml.sax.SAXException - If parsing of the schema instance fails
java.io.IOException - Thrown on IO error

validate

public void validate(org.w3c.dom.Node r)
              throws org.xml.sax.SAXException,
                     java.io.IOException
Checks if xml represented by a node is valid according to the current schema.

Specified by:
validate in interface SchemaValidatorInterface
Parameters:
r - XML Node that is to be validated
Throws:
org.xml.sax.SAXException - If parsing of the schema instance fails
java.io.IOException - Thrown on IO error

validate

public void validate(javax.xml.transform.Source source)
              throws org.xml.sax.SAXException,
                     java.io.IOException
Check if xml represented by a Source is valid according to the current schema.

Specified by:
validate in interface SchemaValidatorInterface
Parameters:
source - Source to be validated
Throws:
org.xml.sax.SAXException - If parsing of the schema instance fails
java.io.IOException - Thrown on IO error

getExceptionDiagnostic

public static java.lang.String getExceptionDiagnostic(org.xml.sax.SAXParseException ex)
Get a meaningful report about a validation exception. The report includes complete data from the exception object.

Parameters:
ex - SAXParseException to get the report for
Returns:
String report of the meaningful data contained in the exception