blob: 583ef8316a6525c2170d3499297989a7efd5d5cd [file] [log] [blame]
<html>
<head>
<META http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Extensions (in the Unified/Pivot OCL prototype)</title>
<link href="book.css" rel="stylesheet" type="text/css">
<meta content="DocBook XSL Stylesheets V1.75.1" name="generator">
<link rel="home" href="index.html" title="OCL Documentation">
<link rel="up" href="Tutorials.html" title="Tutorials">
<link rel="prev" href="OCLInterpreterTutorial.html" title="Working with Classic OCL">
<link rel="next" href="Installation.html" title="Installing the Eclipse OCL Examples and Editors">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<h1 xmlns:l="http://docbook.sourceforge.net/xmlns/l10n/1.0">Extensions (in the Unified/Pivot OCL prototype)</h1>
<div class="section" title="Extensions (in the Unified/Pivot OCL prototype)">
<div class="titlepage">
<div>
<div>
<h2 class="title" style="clear: both">
<a name="Extensions"></a>Extensions (in the Unified/Pivot OCL prototype)</h2>
</div>
</div>
</div>
<p>This section highlights some of the OCL extensions prototyped by the Pivot OCL.</p>
<div class="section" title="Models">
<div class="titlepage">
<div>
<div>
<h3 class="title">
<a name="Models"></a>Models</h3>
</div>
</div>
</div>
<p>The Abstract Syntax classes and interfaces are autogenerated from Pivot.ecore using standard EMF tooling. Pivot.ecore is auto-generated by custom QVTo transformations from OMG&rsquo;s UML.xmi and prototype OCL.uml models. This gives some degree of UML alignment.</p>
<p>The Standard Library is defined by OCL-2.5.oclstdlib for which an OCLstdlib Xtext editor is available. The library is therefore modelled.</p>
<p>The Concrete Syntax classes and editors are also autogenerated from Ecore modesl using standard EMF tooling. Autogeneation of the Ecore models from UML modesl is still work in progress.</p>
<p>The grammars are defined by Xtext models.</p>
<p>The run-time Value classes and interfaces are partially generated from Values.ecore. Full auto-generation is still work in progress.</p>
<p>There is also a model of the code generation intermediate.</p>
</div>
<div class="section" title="XMI">
<div class="titlepage">
<div>
<div>
<h3 class="title">
<a name="XMI"></a>XMI</h3>
</div>
</div>
</div>
<p>The abstract syntax models are fully persistable as standard XMI using the *.oclas file extension. Pivot.oclas and OCL-2.5.oclas models form part of the Eclipse OCL distribution.</p>
<p>The problem of interchange of synthetic types such as Sequence(String) is solved by an orphan package in which a singleton copy of every singleton is maintained.</p>
<p>The problem of Complete OCL&rsquo;s open classes allowing additional features is solved by CompleteModel/CompletePackage/CompleteClass additions to the abstract syntax so that a CompleteClass may aggregate many ordinary Classes; one from the primary user (UML/Ecore) model, any number of further (Compete OCL or OCLstdlib) over;ays.</p>
<p>The problem of references to unnavigable opposites is solved by an OppositePropertyCallExp class.</p>
<p>The problem of references to modelled Iterations is resolved by adding a referredIteration property to IterateExp/IteratorExp.</p>
<p>The problem of references to Stereotype properties is resolved by normalizing the UML representation to exploit regular Class/Property usage.</p>
<p>The problem of references to Association properties is resolved by normalizing the UML representation to exploit regular Class/Property usage.</p>
</div>
<div class="section" title="Templates">
<div class="titlepage">
<div>
<div>
<h3 class="title">
<a name="Templates"></a>Templates</h3>
</div>
</div>
</div>
<p>In OMG OCL, types such as Sequence(String) magically associate String and an ill-defined concept of T. In UML and consequently the UML-aligned pivot OCL, String is a TemplateParameter for which further classes such as TemplateParameterSubstitution define bindings. The use of magic T for library classes is genertalized to arbitrary user
classes and operations; jusr like UML. Template types of cource conform and since in OCL all values are immutable a
Set(Integer) is conformat to a Sert(Real) and a Set(OclAny). This can bew slightly surprising since typos may not lead immediately to type errors, rather an expression with inferred OclAny errors. Use the hovertext to inspect your expression types.</p>
</div>
<div class="section" title="Extensibility">
<div class="titlepage">
<div>
<div>
<h3 class="title">
<a name="Extensibility"></a>Extensibility</h3>
</div>
</div>
</div>
<p>The Pivot OCL is extended by the Eclipse QVTd project to support QVTc and QVTr. The models are therefore extensible, but not readily so. Rather too mauch Java programming is required. True extensibilitty and in partocular a modular OCL Standrad Library is still work in progress.</p>
</div>
<div class="section" title="Operation Overloading">
<div class="titlepage">
<div>
<div>
<h3 class="title">
<a name="OperationOverloading"></a>Operation Overloading</h3>
</div>
</div>
</div>
<p>The buck passing between UML and OCL in regards to operation overloading is resolved in the Pivot OCL by implementing a Java-style dynamic dispatch to the most derived implmentation with a matching signature.</p>
</div>
<div class="section" title="Stereotypes">
<div class="titlepage">
<div>
<div>
<h3 class="title">
<a name="Stereotypes"></a>Stereotypes</h3>
</div>
</div>
</div>
<p>The UML specification hinyts in regards to base_XXX and extension_XXX properties are followed through in conjunction with an ElementExtension lass to model the instance of a Stereotype. Typesafe stereotype navigation is therefore possible without resorting to the proprietary getXXX Java API of Eclipse UML2.</p>
</div>
<div class="section" title="Safe Navigation">
<div class="titlepage">
<div>
<div>
<h3 class="title">
<a name="SafeNavigation"></a>Safe Navigation</h3>
</div>
</div>
</div>
<p>The UML [ 1 ] and [ ? ] multiplicities are exploited to distinguish nullable and non-null objects and diagnose unsafe navigations. To make this useful an extension to null-free collections is possible by defing e.g Set(String[*|1]) as
a Set of String with unbounded [ * ] collection multiplity and never-null [ 1 ] element multiplicity. The additional ?. and &ldquo;?-&gt;&rdquo; safe navigation operators avoid nullhazards. See
<a class="ulink" href="http://www.eclipse.org/modeling/mdt/ocl/docs/publications/OCL2015SafeNavigation/SafeNavigation.pdf" target="_new">Safe Navigation in OCL</a> for more details.
</p>
</div>
<div class="section" title="Reflection">
<div class="titlepage">
<div>
<div>
<h3 class="title">
<a name="Reflection"></a>Reflection</h3>
</div>
</div>
</div>
<p>In the Pivot OCL the oclType() libary method has a pivot::Class return type allowing further navigation to make reflective access to the user metamodel.</p>
</div>
<div class="section" title="Lambda Expressions">
<div class="titlepage">
<div>
<div>
<h3 class="title">
<a name="LambdaExpressions"></a>Lambda Expressions</h3>
</div>
</div>
</div>
<p>OCL has always had hidden lambda expressions in order to define iteratpr bodies. The Pivot OCL reifies these so that the Standard Library uses a templated LambdaType as part of its modelling. Variables and Parameters may use LamabdaType and so ooffer full lambda expression capability.</p>
</div>
<div class="section" title="Map(K,V)">
<div class="titlepage">
<div>
<div>
<h3 class="title">
<a name="MapKV"></a>Map(K,V)</h3>
</div>
</div>
</div>
<p>The Map type provides a familiar functionality comprising a set of keys with associated values.</p>
<p>Like all other OCL types, the Map type is immutable; there are therefore no
<span class="bold"><strong>put</strong></span> or
<span class="bold"><strong>set</strong></span> operations, rather a new Map may be created by
<span class="bold"><strong>including</strong></span> a key-value pair tigether with an old Map.
</p>
<p>The content of a Map may be accessed using
<span class="bold"><strong>at</strong></span>, which returns invalid for an unknown key in the same way as an ordered collection returns invalid for an unknown index.
</p>
<p>A Map may be created explicitly using the new Map Literal Syntax. Thus
<span class="bold"><strong>Map(Integer,String){1 &lt;- &lsquo;one&rsquo;,2 &lt;- &lsquo;two&rsquo;}</strong></span>
creates a Map of Integer to String with
<span class="bold"><strong>'one'</strong></span> bound to
<span class="bold"><strong>1</strong></span> and
<span class="bold"><strong>'two'</strong></span> bound to
<span class="bold"><strong>2</strong></span>. The type
<span class="bold"><strong>(Integer,String)</strong></span>
parameterisation can be omitted.
<span class="bold"><strong>null</strong></span> but not
<span class="bold"><strong>invalid</strong></span> values are permitted as keys and values.
</p>
<p>The new
<span class="bold"><strong>collectBy</strong></span> iteration may be used to construct a map from a collection or map. The iterators of the
<span class="bold"><strong>collectBy</strong></span> define the keys and the value of the body of defines the values. For instance
<span class="bold"><strong>Sequence{1..10}-&gt;collectBy(i | i+i)}</strong></span> builds a map from the values 1 to 10 to the even values 2 to 20.
</p>
<p>Most standard collection iteration operations are available for Maps using the map keys as the (primary) iterator. A secondary value iterator may be specified using the new binds-to syntax. Thus
<span class="bold"><strong>Map{1&lt;-1,2&lt;-4,3&lt;-9}-&gt;reject(k&lt;-v | k = 2 or v = 9}</strong></span> defines a reject iteration over the three entry map, with a primary iterator
<span class="bold"><strong>k</strong></span> over the set of keys and a secondary co-iterator
<span class="bold"><strong>v</strong></span> over the values bound to each key. The body causes the second entry with key 2, and the third entry with value 9 to be rejected leaving just a one entry map.
</p>
<div class="section" title="Details">
<div class="titlepage">
<div>
<div>
<h4 class="title">
<a name="Details"></a>Details</h4>
</div>
</div>
</div>
<p>The OCL metamodel is extended by a MapLiteralExp and MapType. A new abstract IterableType captures the iterable commonality of CollectionType and MapType without making map a collection.</p>
<p>The OCL standard library defines the new Map operations and the new Collection::collectBy itetation.</p>
<p>The OCL syntax is extended by the MapLiteralExp syntax and the binds-to co-iterator syntax for all iterators.</p>
<p>The OCL run-time is extended by a MapValue and an abstract IteravleValue to capture the commonality with CollectionValue.</p>
</div>
</div>
</div>
</body>
</html>