Skip to main content

Notice: this Wiki will be going read only early in 2024 and edits will no longer be possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.

Jump to: navigation, search

COSMOS SDD Tooling Validator Design

Overview

The SDD Validator is an Eclipse plug-in that provides functionality for validating XML against various types of rule sets. Currently supported types of rules are XML Schema rules, Schematron rules and custom user created rules written in Java. The Validator also provides the ability to read XML into SDO's, and write the SDO's back out to XML. While intended primarily for working with SDD's, the Validator is flexible enough to handle any arbitrary XML.

There are two methods available for using the Validator. First, an Eclipse based application may required the Validator as plug-in dependency and use the provided API's. Second, the Validator includes the ability to run as an Eclipse Rich Client Platform (RCP) application with a command line interface.

Rules

All rules must implement the ValidationRule interface, which contains a single method: validate(). A rule may perform any kind of validation action desired, provided it takes an InputStream as input and returns an array of XMLValidationError. Below are the pre-written rule types included with the Validator.

XML Schema Rules

SchemaValidationRule provides functionality for validating against one or more XML Schemas. A SchemaValidationRule is constructed with an array of either Files or InputStreams containing the schemas against which the XML will be validated. Schemas may be added to or removed from the rule at any time. It is also possible to get a list of all schema Files or InputStreams associated with an instance of SchemaValidationRule.

SchemaValidationRule performs validation using the Java API for XML Processing (JAXP), which allows the validation to be independent of the underlying XML parser and thus run the same on different JRE versions and implementations.

Schematron Rules

SchematronValidationRule provides functionality for validating against an ISO Schematron rules file. A SchematronValidationRule is constructed with a Schematron rules file and a Schematron skeleton file. The provided implementation is tied to the Schematron Text validator, which extends the base ISO Schematron skeleton file. Users would need to create a Custom Rule if another type of Schematron error reporting is desired.

Briefly, a Schematron skeleton is an XSL Transform that can be thought of as a compiler for rules files. The result of transforming the rules file with the skeleton is another XSL Transform, which can then be applied against an XML file to generate an error report. SchematronValidationRule takes care of compiling the rules file are parsing the generated error report.

SDD Specific Rules

More info goes here about rules required to ensure compliance with SDD spec, above what the Schema requires.

Custom Java Rules

Users can create their own rules to perform other types of validation beyond what the included rule types provide. There is no restriction on what custom rules can do, other than that they must implement the ValidationRule interface.

Interfaces

API

The Validator API provides two different levels of functionality:

  1. A low level API for reading, writing and validating generic XML or a single Package or Deployment Descriptor. This capability is available through the XML_DAS and SDD_DAS interfaces.
  2. A high level API for handling entire SDD's, meaning one or more Package Descriptors and one or more Deployment Descriptor. This capability is provided by the SDDManager interface.

A more detailed description of each interface is provided below.

XML_DAS

DataGraph loadDataGraph(InputStream inputStream, String[] schemaFiles)

Creates an SDO DataGraph representing the XML in the given InputStream. Since some basic validation occurs during loading of the XML, a list of Schema files referenced by the XML is required. An XMLValidationException may be thrown, but lack of an exception does not necessarily mean the XML is valid.

void saveDataGraph(DataGraph dataGraph, OutputStream outputStream, String rootElementName, String rootElementURI,
String encoding)

Converts the DataGraph to XML and writes it to the given OutputStream. Requires the desired Root Element Name and URI to be specified since that information is not stored in the DataGraph. Optionally, a character encoding can be specified, or null results in the default encoding. This method validates the XML before writing it out.

void saveDataGraph(DataGraph dataGraph, OutputStream outputStream, String rootElementName, String rootElementURI,
String encoding, boolean performValidation)

Converts the DataGraph to XML and writes it to the given OutputStream. Requires the desired Root Element Name and URI to be specified since that information is not stored in the DataGraph. Optionally, a character encoding can be specified, or null results in the default encoding. This method allows a choice of whether the XML is validated before being written out.

XMLValidationError[] validate(DataGraph dataGraph, String rootElementName, String rootElementURI)

Validates the given DataGraph by running all the ValidationRules associated with the XML_DAS. Since the DataGraph will be converted to XML before validation, the Root Element Name and URI are required. Returns a list of validation errors found, or an empty list if the XML is valid.

void addValidation(ValidationRule validationRule)

Adds a ValidationRule to the list of rules associated with the XML_DAS.

void removeValidation(ValidationRule validationRule)

Removes a ValidationRule from the list of rules associated with the XML_DAS.

ValidationRule[] getValidationRules()

Returns a list of all ValidationRules associated with an XML_DAS.

SDD_DAS

DataGraph loadDataGraph(InputStream inputStream)

Creates an SDO DataGraph representing the XML in the given InputStream. The SDD Schema files are used for the basic validation that occurs during loading of the XML. An XMLValidationException may be thrown, but lack of an exception does not necessarily mean the XML is valid.

void saveDataGraph(DataGraph dataGraph, OutputStream outputStream, String encoding)

Converts the DataGraph to XML and writes it to the given OutputStream. The appropriate Root Elemenet Name and URI are used depending on whether the DataGraph is a Package Descriptor or Deployment Descriptor. Optionally, a character encoding can be specified, or null results in the default encoding. This method validates the XML before writing it out.

void saveDataGraph(DataGraph dataGraph, OutputStream outputStream, String encoding, boolean performValidation)

Converts the DataGraph to XML and writes it to the given OutputStream. The appropriate Root Elemenet Name and URI are used depending on whether the DataGraph is a Package Descriptor or Deployment Descriptor. Optionally, a character encoding can be specified, or null results in the default encoding. This method allows a choice of whether the XML is validated before being written out.

XMLValidationError[] validate(DataGraph dataGraph)

Validates the given DataGraph by running all the ValidationRules associated with the SDD_DAS. Returns a list of validation errors found, or an empty list if the XML is valid.

void addValidation(ValidationRule validationRule)

Adds a ValidationRule to the list of rules associated with the SDD_DAS.

void removeValidation(ValidationRule validationRule)

Removes a ValidationRule from the list of rules associated with the SDD_DAS.

ValidationRule[] getValidationRules()

Returns a list of all ValidationRules associated with an SDD_DAS.

SDDManager

Command Line

More info about command line interface goes here.

Back to the top