Black-box implementation support

The current support for black-box implementation in QVT Operational enables the users for library modules definition. The Eclipse OCL mapping for predefined OCL types to Java classes in runtime is followed, user model elements are limited to Java-linked EMF models only.

For the case of simplicity, an analogy of a public Java class declaring public operations is adopted and mapped to a corresponding QVT Library AST model, which in turn owns the corresponding imperative operations. Predefined Java-OCL type mapping rules are applied, eventually complemented by Java annotations to add missing information that are not expressable in Java language.

See an example at 'Examples/Operational QVT Transformation/Black-box Library Definition' wizard.

Java classes mapped to predefined OCL/QVTo types

Java classOCL/QVTo type
java.lang.ObjectOclAny
java.lang.StringString
java.lang.BooleanBoolean
java.lang.IntegerInteger
java.lang.DoubleReal
java.util.CollectionCollection
java.util.ListSequence
java.util.SetSet
java.util.LinkedHashsetOrderedSet
org.eclipse.ocl.util.BagBag
org.eclipse.m2m.qvt.oml.util.MutableListList
org.eclipse.m2m.qvt.oml.util.DictionaryDict

The collection element types are expressed using Java generics, so java.util.Set<java.util.List<java.lang.String>> is mapped to Set(Sequence(String)) in QVT. For OCL Collection instance creation, the user should use the org.eclipse.ocl.util.CollectionUtil utility class, and respectively org.eclipse.m2m.qvt.oml.util.Utils for QVTo mutable collection types.

Additional Java numeric types recognized as OCL predefined types:

Java classOCL type
java.lang.ShortInteger
java.lang.LongInteger
java.math.BigIntegerInteger
java.lang.FloatReal
java.math.BigDecimalReal

User model types

The user model types are represented by corresponding Java interfaces generated for the model classes or by Java classes bound to individual datatypes. The resolution is performed based on lookup of EClassifier by instance class name within the EClassifiers of EPackages referenced by the given QVT module.
In other words, the org.eclipse.emf.ecore.EAttribute Java interface specified in an operation signature is resolved ecore::EAttribute class in the QVT type system, provided that the owning QVT module is declared as referencing "http://www.eclipse.org/emf/2002/Ecore" metamodel. The default package registry EPackage.Registry.INSTANCE is used to lookup the metamodel package by its nsURI.

Library class

A public Java class that with a public default constructor. The public operations declared by this class are considered the QVT library defined operation. In order to make the library class visible, it has to be deployed in a black-unit using the org.eclipse.m2m.qvt.oml.javaBlackboxUnits extension point.

Library operations

A public operation having both the return type and all parameter types resolvable to corresponding OCL types.

Non-contextual operation

Operation owned by the library and having no contextual type to be used as the source object of operation calls. It is defined as an ordinary public Java operation.

Contextual operation

Operation 'physically' owned by the defining library but having a contextual type to be used as the source object of operation calls. It is defined as a public Java operation of which the first argument is reserved for passing the source object (contextual instance) of the call. This is indicated by marking the operation by the predefined annotation @Operation(contextual=true).

Simple library class example

import java.util.Date;
import org.eclipse.m2m.qvt.oml.blackbox.java.Operation;
import org.eclipse.m2m.qvt.oml.blackbox.java.Parameter;
import org.eclipse.emf.ecore.EClassifier;

public class MyLibrary {

	public MyLibrary() {
		super()
	}
		
	public Date createDate(String dateStr) {
		return (Date)EcoreFactory.eINSTANCE.createFromString(EcorePackage.eINSTANCE.getEDate(), dateStr);
	}
	
	/*
	* java.util.Date resolved as ecore::EDate, which as an opaque data type to the QVT type system, however
	* here equipped by this additional operation.
	*/
	@Operation(contextual=true)
	public static boolean before(Date self, Date when) {
		return self.before(when);
	}
	
	@Operation(contextual=true)
	public static String getQualifiedName(EClassifier self) {
		return self.getEPackage().getName() + "::" + self.getName();
	}	
}

The library Java class declared above appears to the importing QVT module as in the main() operation example bellow.

main() {
	var date : ecore::EDate := createDate('2008-10-31');
	var isBefore := date.before(createDate('2008-11-01'));
	
	var eClass := object ecore::EClass {};
	var qname := eClass.getQualifiedName();
}