The current support for black-box implementation in QVT Operational enables the users for library modules definition. The MDT OCL mapping for predefined OCL types to Java classes in runtime is followed, user model elements are limited to java generated EMF models only.
For the case of simplicity, an analogy of a public Java class declaring public operations is adopted
and mapped to corresponding QVT Library AST model, which in turn owns 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 class | OCL type |
---|---|
java.lang.Object | OclAny |
java.lang.String | String |
java.lang.Boolean | Boolean |
java.lang.Integer | Integer |
java.lang.Double | Real |
java.util.Collection | Collection |
java.util.List | Sequence |
java.util.Set | Set |
java.util.LinkedHashset | OrderedSet |
org.eclipse.ocl.util.Bag | Bag |
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 Collection instance creation, the user should use org.eclipse.ocl.util.CollectionUtil utility class.
Java class | OCL type |
---|---|
java.lang.Short | Integer |
java.lang.Long | Integer |
java.math.BigInteger | Integer |
java.lang.Float | Real |
java.math.BigDecimal | Real |
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.
object
(contextual instance) of the call. This is indicated by marking the operation by the predefined annotation @Operation(contextual=true)
.
Remark:At the moment, the java operation is required to be static
, however in the future, the non-static variant will be support as well,
thus offering the benefit of access to a state shared per library instance.
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(); } }
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(); }