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 class | OCL/QVTo 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 |
org.eclipse.m2m.qvt.oml.util.MutableList | List |
org.eclipse.m2m.qvt.oml.util.Dictionary | Dict |
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.
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.
@Operation(contextual=true)
.
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()
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(); }