blob: 118f8170403a7529f7edfb756a32540b774d876d [file] [log] [blame]
<html>
<head>
<META http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Parsing OCL Documents</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="PivotProgrammersGuide.html" title="Unified or Pivot Programmers Guide">
<link rel="prev" href="PivotEvaluatingConstraints.html" title="Evaluating Constraints and Queries">
<link rel="next" href="PivotMetamodels.html" title="OCL Relationship to Metamodels">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<h1 xmlns:l="http://docbook.sourceforge.net/xmlns/l10n/1.0">Parsing OCL Documents</h1>
<div class="section" title="Parsing OCL Documents">
<div class="titlepage">
<div>
<div>
<h2 class="title" style="clear: both">
<a name="PivotParsingDocuments"></a>Parsing OCL Documents</h2>
</div>
</div>
</div>
<p>As we saw in the
<a class="link" href="PivotParsingConstraints.html" title="Parsing Constraints and Queries">Parsing Constraints and Queries</a> topic, the
<a class="ulink" href="http://download.eclipse.org/ocl/javadoc/6.4.0/org/eclipse/ocl/utilities/OCL.html" target="_new">
<code class="code">OCL</code>
</a>
Facade provides an API for parsing OCL expressions embedded in models as constraints.
</p>
<p>The OCL specification defines a Complete OCL text document with which a UML (or Ecore) metamodel
may be completed by providing many complementary constraints and expressions. In this case,
the concrete syntax for context declarations indicates the context of
constraints, equivalent to their placement in models.</p>
<p>As an example, consider the following Complete OCL document:</p>
<p>
</p>
<div class="mediaobject">
<img src="images/6320-extlibrary.png"></div>
<p>
<a class="ulink" href="../references/6320-extlibrary.ocl" target="_new">[Text for cut and paste]</a>
</p>
<div class="section" title="The OCL Input">
<div class="titlepage">
<div>
<div>
<h3 class="title">
<a name="TheOCLInput2"></a>The OCL Input</h3>
</div>
</div>
</div>
<p>The Pivot binding provides a UML-aligned representation and so a Complete OCL document can be parsed to provide a similar Resource to that
derived from a UML or Ecore metamodel. A
<code class="code">Root</code> contains a
<code class="code">Model</code> which contains
<code class="code">Package</code>s
and
<code class="code">Class</code>es. The complementing Resource from the Complete OCL document is independent of the similarly structured
complemented Resource of the completed metamodel.
</p>
<p>The Pivot binding uses an Xtext parser with a UML-aligned output. The input text is therefore specified by
a URI and loaded by the Xtext parser to create a Concrete Syntax Resource. This may then be converted to the Pivot Abstract Syntax Resource. The Abstract Syntax Resource has a conventional Model, Package, Class, Operation hierarchy in order to provide a coherent composition context for the Constraints.</p>
<p>The elements of the independent complementing and complemented Resources are merged within
<code class="code">CompleteClass</code>es and
<code class="code">CompletePackage</code>s of the
<code class="code">CompleteModel</code> managed behind the OCL facade.
</p>
<p>There are therefore two
<code class="code">Class</code> objects named
<span class="bold"><strong>Library</strong></span>, one for each Resource. The objects are distinct in so far as they belong to different resources, which can be separately serialized, and in so far as they may appear distinct to OCL expressions that use reflective access. However they are logically merged and the
<code class="code">CompleteEnvironment</code> provides utility methods that allow the multiple objects to be accessed as a merged object.
</p>
<div class="blockquote">
<blockquote class="blockquote">
<p>
The Ecore binding provided an
<code class="code">OCLInput</code> class to supervise the OCL source text, and the result of parsing the document was a
<code class="code">List&lt;Constraint&gt;</code>.
p.
</p>
</blockquote>
</div>
<p>The Complete OCL document is a textual Resource with an associated text tooling. The
<code class="code">OCL</code> facade provides
an API to load a Resource from a given
<code class="code">URI</code>.
</p>
<p>
</p>
<div class="mediaobject">
<img src="images/6320-parsing.png"></div>
<p>
<a class="ulink" href="../references/6320-parsing.txt" target="_new">[Text for cut and paste]</a>
</p>
</div>
<div class="section" title="Traversing the Constraints">
<div class="titlepage">
<div>
<div>
<h3 class="title">
<a name="TraversingtheConstraints"></a>Traversing the Constraints</h3>
</div>
</div>
</div>
<p>The parsed resurce can be traversed in the same way as other EMF resources.</p>
<p>
</p>
<div class="mediaobject">
<img src="images/6320-traversing.png"></div>
<p>
<a class="ulink" href="../references/6320-traversing.txt" target="_new">[Text for cut and paste]</a>
</p>
</div>
<div class="section" title="Accessing the Constraints">
<div class="titlepage">
<div>
<div>
<h3 class="title">
<a name="AccessingtheConstraints2"></a>Accessing the Constraints</h3>
</div>
</div>
</div>
<p>The contents of the Complete OCL document contribute to a
<code class="code">CompleteModel</code> that merges all the contributions.
The contributions can therefore be used as if defined in a primary metamodel.
</p>
<p>
</p>
<div class="mediaobject">
<img src="images/6320-accessing.png"></div>
<p>
<a class="ulink" href="../references/6320-accessing.txt" target="_new">[Text for cut and paste]</a>
</p>
</div>
<div class="section" title="Using the Constraints to Validate a Model">
<div class="titlepage">
<div>
<div>
<h3 class="title">
<a name="UsingtheConstraintstoValidateaModel"></a>Using the Constraints to Validate a Model</h3>
</div>
</div>
</div>
<p>The standard EMF validation makes use of an
<code class="code">EValidatorRegistry</code> that maps the URI of an
<code class="code">EPackage</code> to the
derived
<code class="code">EValidator</code> that provides the constraints appilcable to the
<code class="code">EPackage</code>. If we want to exploit
additional constraints defined in a Complete OCL document, we must extend the underlying
<code class="code">EValidator</code>.
The
<code class="code">ComposedValidator</code> enables multiple
<code class="code">EValidator</code> to be composed and to behave as a single
<code class="code">EValidator</code>.
<code class="code">ComposedEValidator.install()</code> replaces the single
<code class="code">EValidator</code> by a composite
initially containing just the replaced
<code class="code">EValidator</code>. A
<code class="code">CompleteOCLEObjectValidator</code> provides the additional validation of the given
<code class="code">uri</code> and
<code class="code">EPackage</code>.
</p>
<p>
</p>
<div class="mediaobject">
<img src="images/6320-validating.png"></div>
<p>
<a class="ulink" href="../references/6320-validating.txt" target="_new">[Text for cut and paste]</a>
</p>
<p>The standard
<code class="code">Diagnostician</code> does not directly support validation of a
<code class="code">Resource</code>.
<code class="code">MyDiagnostician</code> remedies this deficiency and provides a
<code class="code">SubstitutionLabelProvider</code>
that provides slightly better labels within OCL diagnostics.
</p>
<p>
</p>
<div class="mediaobject">
<img src="images/6320-diagnostician.png"></div>
<p>
<a class="ulink" href="../references/6320-diagnostician.txt" target="_new">[Text for cut and paste]</a>
</p>
<p>The source for these examples may be found in the org.eclipse.ocl.examples.xtext.tests plugin in model/parsingDocumentsExample.ocl and in src/org/eclipse/ocl/examples/test/xtext/PivotDocumentationExamples.java.</p>
</div>
</div>
</body>
</html>