Skip to main content

Notice: This Wiki is now read only and edits are no longer possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.

Jump to: navigation, search

Resource Modeling use cases

COSMOS Main Page > COSMOS Use Cases

This document describes the basic scenarios for validating and editing SML and SML-IF resources. The intention is to provide a common framework and initial implementations which will allow a user to easily create and validate SML and SML-IF models.

Overview

The goal is to be able to deliver an SML editor and validator on the first release of Cosmos. We should reuse and extend or provide a common user interaction scenario with any other open source projects providing the same type of functionality.

The Resource Modeling workgroup is proposing to investigate which Eclipse projects are providing XML editors or schema validation and work together to provide a scenario which will make the Cosmos and these projects interact and complement each other.

WTP has been identified as one of the projects offering xml schema and instance validation. The action is available for any document with the extension XML and XSD (right click and select Run Validate or Validation XML File action). A good usability scenario would require extending these actions with SML extra validation and not providing new validate actions on an xml or xsd resource. Since this may require working with the WTP team to define a common scenario and the set of extensions required to hook in SML validation, this may not be a viable delivery for the first release of Cosmos. This should not stop us from starting the collaboration with WTP (and any other projects) with the goal of identifying required API and extension points for making this happen.

Useful links

SML site

Here is a link to the external SML site: http://www.serviceml.org/

SML repository sample

http://www.serviceml.org/SMLspec/

Creating SML and SML-IF editors

There are three scenarios covered here:

Editors for building SML schema definitions

We'll need to investigate what is already available. WTP has support for creating schema documents; unless we have a well defined usecase for SML schema editors, the WTP editor can be used to build this type of documents. Going forward we can improve the user experience and build a more sophisticated editor.

Editors for SML instances

Allow to create SML instances using existing SML schema definitions. Similarly, we can use the existing WTP xml editor and going forward look for a more sophisticated SML instance editor.


Editors for SML-IF instances

Allow to create SML-IF instances using existing SML instances.

User interaction:

  • Create a new project or select an existing project. The project type can be anything arbitrary.
  • Select File > New > Other
  • Expand the “Resource Modeling” category
  • Select “SML-IF instance”
  • The user has the option of specifying a name, display name, description, and a base URI.
  • The user has the option of selecting one or more SML instances to be added to the phenic section. Schema documents for these SML instances will be automatically added under the genic section.
  • Optionally, the user should be able to specify schematron documents used to validate phenic documents. They will be added under the genic section.
  • The user can select SML schemas (no instances) to be added under the genic section.
  • Click finish to create the document


For performance reasons, based on the user selection, a simple ini document will be created. This document will contain a genic section with pointers to the schema documents and a phenic section with pointers to the phenic documents. This document will be the underlying model for the editor. Once the content is finalized, the SML-IF document will be generated from this ini file using an ‘Export to SML-IF’ option. The ‘Export to SML-IF’ action will in-line the phenic and genic documents into an SML-IF instance file and will write this content to the disk.

Actions available in the SML-IF editor:

  • Add new genic document
    • The user selects the genic section and click Add
    • In the Browse dialog he can select an existing schema available on the file system or point to a uri location.
    • After the user presses finish in the Browse dialog, the ini file is updated with a link to the schema document in the genic section.
  • Add new phenic document
    • The user selects the phenic section and click Add
    • Using the browse dialog, he can select an SML instance from the file system
    • After the user presses finish in the Browse dialog, the ini file is updated with a lonk to the schema instance in the phenic section. The genic section is updated wit a link to the schema document for that SML instance.
  • Validate SML instance – on any phenic document
  • Validate SML-IF – global action on the selected SML-IF instance
  • Generate SML-IF content
    • The content of the ini file is inlined into an SML-IF document. The SML-IF document will congaing all phenic and genic documents described by the ini file.

A detailed description of the UI content will be defined next.

SML and SML-IF validation

Validation is done in two phases:

XML Validation - SML schema extension validation

The SML schema extension validation phase will ensure that the documents conform to the schema extensions as specified by the SML specification. This includes the following extensions:

  1. sml:acyclic
  2. sml:targetElement
  3. sml:targetType
  4. sml:key
  5. sml:unique
  6. sml:keyref

In addition to validating the additional constraints that SML adds on top of Schema, this phase will also validate all inter-document references using equivalence of URIs as defined by RFC 3986.

JAXP 1.3 Schema Validation Framework

Use Java 1.5 Validation API to validate the SML extensions. https://jaxp.dev.java.net/article/jaxp-1_3-article.html

JAXP 1.3 introduces a new Schema independent Validation Framework (called the Validation API).

JAXP 1.3 Validation API decouples the validation of an instance document as a process independent of parsing. This new approach has several advantages. Applications relying heavily on XML Schema can greatly improve the performance of schema validation. The performance gain largely depends on the ratio (Size of XML Schema / Size of XML document), larger ratios lead to greater performance gains. The document listed above describes in details how to use the new frameworks and what can be done using the specified framework.

JAXP 1.3 sample implementation

Define an SML schema which will be reused for different instance validation. Use this schema to validate an instance sml.

private static final String smlSchemaValidationFactory="org.eclipse.cosmos.sml.validation.SMLSchemaFactoryImpl";
private static final String smlLanguage="org.eclipse.cosmos.smlLanguage";
private static final String smlValidationSystemProperty="javax.xml.validation.SchemaFactory:"+smlLanguage;

try {
	// <SCHEMA LANGUAGE> could be W3C XML Schema, Relax NG etc.
	SchemaFactory sf = SchemaFactory.newInstance(smlLanguage);
	sf.setErrorHandler(new SMLSchemaErrorHandler());
	// set the resource resolver to customize resource resolution
	sf.setResourceResolver(new SMLSchemaResourceResolver());
	// load a WXS schema, represented by a Schema instance 
	Schema schema = sf.newSchema(new StreamSource(new File(smlSchema)));	
}
catch (SAXException exc)
{
	exc.printStackTrace();
}

// Create a Validator which can be used to validate instance document against this schema(s)
Validator validator = schema.newValidator();
validator.setErrorHandler(new SMLSchemaErrorHandler());
// Validate this instance document against the Instance document supplied
validator.validate(new StreamSource(new File(smlInstance)));
			
// parse an xml using this schema
SAXParserFactory spf = SAXParserFactory.newInstance();
// Just set the Schema instance on SAXParserFactory
spf.setSchema(schema);
// Obtain the SAXParser instance
SAXParser saxParser = spf.newSAXParser();
// parser will parse the XML document but validate it using Schema instance
saxParser.parse(new File(smlInstance), new SMLInstanceHandler());

Schematron validation

The proposal is to use XSLT transforms to validate schematron rules.

http://www.ldodds.com/papers/schematron_xsltuk.html

Schematron instances can be transformed through a stylesheet (skeleton-1.5.xsl), produces XSLT validators which is then applied to the xml instance.

Schematron validation using XSLT transform

This section describes how to do schematron validation using XSLT transform.


//pass a schematron file and generates an xslt result file
//The resulting xslt file will be used to validate an xml file against the schematron file		
transform(schematron, skeleton, schematronXSLT);			

//validate the xml instance against the schematron file by appliyng the xslt result to the xml file			
transform(xmlInstance, schematronXSLT, result);

	private static void transform(String input, String xsl, String output) {

		
		try {			
		    TransformerFactory m_tfactory = TransformerFactory.newInstance();
		    Transformer transformer = m_tfactory.newTransformer(new StreamSource(xsl));
		    transformer.transform(new StreamSource(input), new StreamResult(output));
		}
		catch(Exception exc)
		{
			exc.printStackTrace();
		}
        
	}

Back to the top