blob: 36a8e47219a7d0160ea85257d16dfe807c6359aa [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="ProgrammersGuide.html" title="Classic Ecore/UML Programmers Guide">
<link rel="prev" href="EvaluatingConstraints.html" title="Evaluating Constraints and Queries">
<link rel="next" href="TargetMetamodels.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="ParsingDocuments"></a>Parsing OCL Documents</h2>
</div>
</div>
</div>
<p>As we saw in the
<a class="link" href="ProgrammersGuide.html#ParsingConstraints" title="Parsing Constraints and Queries">Parsing Constraints and Queries</a> topic, the OCL parser provides an
<a class="ulink" href="http://download.eclipse.org/ocl/javadoc/6.4.0/org/eclipse/ocl/helper/OCLHelper.html" target="_new">
<code class="code">OCLHelper</code>
</a> API for parsing constraints embedded in models. OCL also permits constraints
to be specified in a text document, as an adjunct to the model. 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/5120-extlibrary.png"></div>
<p>
<a class="ulink" href="../references/5120-extlibrary.ocl" target="_new">[Text for cut and paste]</a>
</p>
<div class="blockquote">
<blockquote class="blockquote">
<p>
The
<span class="emphasis"><em>import</em></span> on the first line is an extension supported by the Complete OCL editor for use with the Pivot meta-model. The
<span class="emphasis"><em>import</em></span> is ignored by the parsers for the Ecore or UML bindings, which assume that the relevant metamodels have been registered in either the global EPackage.Registry or the local EPackage.Registry passed to the EnvironmentFactory..
</p>
</blockquote>
</div>
<p></p>
<div class="section" title="The OCL Input">
<div class="titlepage">
<div>
<div>
<h3 class="title">
<a name="TheOCLInput"></a>The OCL Input</h3>
</div>
</div>
</div>
<p>The
<a class="ulink" href="http://download.eclipse.org/ocl/javadoc/6.4.0/org/eclipse/ocl/OCLInput.html" target="_new">
<code class="code">OCLInput</code>
</a> class encapsulates an OCL document. An input can be created from a string or an
input stream.
</p>
<p>
</p>
<div class="mediaobject">
<img src="images/5120-input.png"></div>
<p>
</p>
<p>Given an
<code class="code">OCLInput</code>, simply ask an
<code class="code">OCL</code> to parse it: "
</p>
<p>
</p>
<div class="mediaobject">
<img src="images/5120-parsing.png"></div>
<p>
<a class="ulink" href="../references/5120-parsing.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="AccessingtheConstraints"></a>Accessing the Constraints</h3>
</div>
</div>
</div>
<p>The
<code class="code">OCL</code> returns the list of constraints if they were
successfully parsed. They are retained by the OCL (available via the
<code class="code">getConstraints()</code> method at any time), and in particular,
any definitions of additional operations or attributes are available for
subsequent constraint parsing. Any number of OCL documents may be parsed by
the same
<code class="code">OCL</code> instance, combined also with constraints
parsed by
<code class="code">OCLHelpers</code>. All of these constraints are
retained by the
<code class="code">OCL</code> environment.
</p>
<p>
</p>
<div class="mediaobject">
<img src="images/5120-accessing.png"></div>
<p>
<a class="ulink" href="../references/5120-accessing.txt" target="_new">[Text for cut and paste]</a>
</p>
<p>The source for these examples may be found in the org.eclipse.ocl.ecore.tests plugin in model/parsingDocumentsExample.ocl and in src/org/eclipse/ocl/ecore/tests/DocumentationExamples.java.</p>
</div>
</div>
</body>
</html>