blob: 5c6bf4bf6d3e93135b6f2d21a33dcfb393e161a9 [file] [log] [blame]
<html>
<head>
<title>Check</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="Xpand Documentation"/>
<link rel="up" href="core_reference.html" title="Xpand / Xtend / Check Reference"/>
<link rel="prev" href="r10_expressions_language.html" title="Expressions"/>
<link rel="next" href="Xtend_language.html" title="Xtend"/>
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<h1 xmlns:l="http://docbook.sourceforge.net/xmlns/l10n/1.0">Check</h1>
<div class="section" title="Check">
<div class="titlepage">
<div>
<div>
<h2 class="title" style="clear: both">
<a name="Check_language"/>
<span class="emphasis">
<em>Check</em>
</span>
</h2>
</div>
</div>
</div>
<div class="section" title="Description of the Check language">
<div class="titlepage">
<div>
<div>
<h3 class="title">
<a name="Check_language_description"/>Description of the <span class="emphasis">
<em>Check</em>
</span> language</h3>
</div>
</div>
</div>
<p>
<span class="emphasis">
<em>Xpand</em>
</span> also provides a language to specify
constraints <a name="N10CFF" class="indexterm"/> that the model has to fulfill in order to be correct.
This language is very easy to understand and use. Basically, it is built
around the expression syntax that has been discussed in detail in the
previous section. Constraints specified in the
<span class="emphasis">
<em>Check</em>
</span> <a name="N10D06" class="indexterm"/> language have to be stored in files with the file
extension <code class="filename">.chk</code> <a name="N10D0F" class="indexterm"/>
<a name="N10D12" class="indexterm"/>. Furthermore, these files have to be on the Java
classpath, of course, in order to be found. Let us look at an example,
in order to understand what these constraints look like and what they
do:</p>
<pre class="programlisting">import data;
context Attribute ERROR
"Names have to be more than one character long." :
name.length &gt; 1;</pre>
<p>Now, let us look at the example line by
line:</p>
<div class="orderedlist">
<ol class="orderedlist" type="1">
<li class="listitem">
<p>First, the metamodel has to be imported.</p>
</li>
<li class="listitem">
<p>Then, the context is specified for which the constraint
applies. In other words, after the <code class="code">context</code> keyword,
we put the name of the metaclass that is going to be checked by
the constraint. Then, there follows either <code class="code">ERROR</code> or
<code class="code">WARNING</code>, These keywords specify what kind of action
will be taken in case the constraint fails:</p>
<div class="table">
<a name="N10D2C"/>
<p class="title">
<b>Table 7. Types of action for <span class="emphasis">
<em>Check</em>
</span>
constraints</b>
</p>
<div class="table-contents">
<table summary="Types of action for Check&#10; constraints" cellspacing="0" cellpadding="10" style="border-collapse: collapse;border-top: 0.5pt solid ; border-bottom: 0.5pt solid ; border-left: 0.5pt solid ; border-right: 0.5pt solid ; ">
<colgroup>
<col/>
<col/>
</colgroup>
<tbody>
<tr>
<td style="border-right: 2 solid #000000; border-bottom: 2 solid #000000; ">
<code class="code">WARNING</code>
</td>
<td style="border-bottom: 2 solid #000000; ">If the constraint fails, the specified message is
printed, but the workflow execution is not
stopped.</td>
</tr>
<tr>
<td style="border-right: 2 solid #000000; ">
<code class="code">ERROR</code>
</td>
<td style="">If the constraint fails, the specified message is
printed and all further processing is stopped.</td>
</tr>
</tbody>
</table>
</div>
</div>
<p>
<br class="table-break"/>
</p>
</li>
<li class="listitem">
<p>Now, the message that is put in case that the constraint
fails is specified as a string. It is possible to include the
value of attributes or the return value of functions into the
message in order to make the message more clear. For example, it
would be possible to improve the above example by rewriting it
like this:</p>
<pre class="programlisting">import data;
context Attribute ERROR
"Name of '" + name + "too short. Names have to be more than one character long." :
name.length &gt; 1;</pre>
</li>
<li class="listitem">
<p>Finally, there is the condition itself, which is specified
by an expression, which has been discussed in detail in the
previous section. If this expression is <code class="varname">true</code>,
the constraint is fulfilled.</p>
</li>
</ol>
</div>
<div class="important" title="Important" style="margin-left: 0.5in; margin-right: 0.5in;">
<h3 class="title">Important</h3>
<p>Please always keep in mind that the message that is associated
with the constraint is printed, if the condition of the constraint
is <code class="varname">false</code>! Thus, if the specified constraint
condition is <code class="varname">true</code>, nothing will be printed out
and the constraint will be fulfilled.</p>
</div>
<div class="section" title="Guard Conditions">
<div class="titlepage">
<div>
<div>
<h4 class="title">
<a name="Guard_conditions"/>Guard Conditions</h4>
</div>
</div>
</div>
<p>The <span class="emphasis">
<em>Check</em>
</span> language of
<span class="emphasis">
<em>Xpand</em>
</span> also provides so called <a name="N10D6A" class="indexterm"/>. These conditions allow to apply a check constraint
only to model elements that meet certain criteria. Specifying such a
guard condition is done by adding an <span class="emphasis">
<em>if</em>
</span> clause to
the check constraint. The <span class="emphasis">
<em>if</em>
</span> clause has to be
added after the <span class="emphasis">
<em>context</em>
</span> clause as demonstrated by
the following example: </p>
<pre class="programlisting">import data;
context Attribute if name.length &gt; 1 ERROR
"Attribute names have to start with an 'a'" :
name.startsWith("a");</pre>
</div>
</div>
<div class="section" title="The workflow component CheckComponent">
<div class="titlepage">
<div>
<div>
<h3 class="title">
<a name="check_checkcomponent"/>The workflow component
<span class="emphasis">
<em>CheckComponent</em>
</span>
</h3>
</div>
</div>
</div>
<p>The workflow component
<code class="classname">org.eclipse.xtend.check.CheckComponent</code> allows to
integrate model validation constraints using the
<span class="emphasis">
<em>Check</em>
</span> into a modeling workflow using MWE.</p>
<p>This component provides the following configuration
properties:</p>
<div class="table">
<a name="properties_checkcomponent"/>
<p class="title">
<b>Table 8. Properties</b>
</p>
<div class="table-contents">
<table summary="Properties" cellspacing="0" cellpadding="10" style="border-collapse: collapse;border-top: 0.5pt solid ; border-bottom: 0.5pt solid ; border-left: 0.5pt solid ; border-right: 0.5pt solid ; ">
<colgroup>
<col align="left"/>
<col align="left"/>
</colgroup>
<thead>
<tr>
<th style="border-right: 2 solid #000000; border-bottom: 2 solid #000000; " align="left">Name of property</th>
<th style="border-bottom: 2 solid #000000; " align="left">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td style="border-right: 2 solid #000000; border-bottom: 2 solid #000000; " align="left">
<code class="varname">checkFile</code>
</td>
<td style="border-bottom: 2 solid #000000; " align="left">This property allows to add files containing constraints
written in the <span class="emphasis">
<em>Check</em>
</span> language to the
validation component.</td>
</tr>
<tr>
<td style="border-right: 2 solid #000000; border-bottom: 2 solid #000000; " align="left">
<code class="varname">emfAllChildrenSlot</code>
</td>
<td style="border-bottom: 2 solid #000000; " align="left">Name of a workflow slot that contains an EMF object,
which has to be validated including all child elements that it
contains. <span class="emphasis">
<em>This property only works in conjunction with
EMF based models.</em>
</span>
</td>
</tr>
<tr>
<td style="border-right: 2 solid #000000; border-bottom: 2 solid #000000; " align="left">
<code class="varname">expression</code>
</td>
<td style="border-bottom: 2 solid #000000; " align="left">This property allows to set a check expression for the
validation component. <span class="strong">
<strong>This property only
works in conjunction with non-EMF based
models.</strong>
</span>
</td>
</tr>
<tr>
<td style="border-right: 2 solid #000000; border-bottom: 2 solid #000000; " align="left">
<code class="varname">abortOnError</code>
</td>
<td style="border-bottom: 2 solid #000000; " align="left">This boolean property determines if the workflow will be
aborted or not if one of the validation constraints
fails.</td>
</tr>
<tr>
<td style="border-right: 2 solid #000000; " align="left">
<code class="varname">warnIfNothingChecked</code>
</td>
<td style="" align="left">If this boolean property will be set to
<span class="emphasis">
<em>true</em>
</span>, a warning will be generated if there
were no validation checks. Otherwise, no warning will be
issued.</td>
</tr>
</tbody>
</table>
</div>
</div>
<br class="table-break"/>
</div>
</div>
</body>
</html>