blob: 4cf8526240ce61a927e0457f9aaecd94972e9367 [file] [log] [blame]
<html>
<head>
<META http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Delegates</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="ImpactAnalyzer.html" title="Incrementally Re-Evaluating OCL Expressions Using the Impact Analyzer">
<link rel="next" href="Standalone.html" title="Ecore/UML Standalone Configuration">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<h1 xmlns:l="http://docbook.sourceforge.net/xmlns/l10n/1.0">Delegates</h1>
<div class="section" title="Delegates">
<div class="titlepage">
<div>
<div>
<h2 class="title" style="clear: both">
<a name="Delegates"></a>Delegates</h2>
</div>
</div>
</div>
<p>EMF provides three delegation mechanisms that enable functionality not directly supported by EMF to be delegated to a technology that can support it.</p>
<div class="itemizedlist">
<ul class="itemizedlist" type="disc">
<li class="listitem">
<p>a
<a class="link" href="Delegates.html#ValidationDelegate" title="Validation Delegates">Validation Delegate</a> supports checking additional invariants on an EClassifier
</p>
</li>
<li class="listitem">
<p>a
<a class="link" href="Delegates.html#SettingDelegate" title="Setting Delegates">Setting Delegate</a> supports getting an initial or derived computed value for an EStructuralFeature
</p>
</li>
<li class="listitem">
<p>an
<a class="link" href="Delegates.html#InvocationDelegate" title="Invocation Delegates">Invocation Delegate</a> supports the execution of a function defined by an EOperation
</p>
</li>
</ul>
</div>
<p>and also</p>
<div class="itemizedlist">
<ul class="itemizedlist" type="disc">
<li class="listitem">
<p>a
<a class="link" href="Delegates.html#QueryDelegate" title="Query Delegates">Query Delegate</a> supports the execution of a function not defined by an EOperation
</p>
</li>
</ul>
</div>
<p>When you use the
<a class="link" href="OCLinEcore.html" title="The OCLinEcore Language">OCLinEcore</a> editor, the required EAnnotations to support delegation are provided automatically. This section provides sufficient detail to allow them to be maintained manually using the Sample Ecore Editor or Java code.
</p>
<p>These EAnnotations ensure that delegates can be used for both genmodeled and reflective models. The use of genmodel to generate Java classes for your metamodel has significant performance benefits for modeling, but currently makes little difference for OCL execution. The use of genmodel has the disadvantage that you must install the Java classes and so the user of the Java classes must run in a different Eclipse or standalone session to the developer. Conversely, using reflective models allows both developer and user to share the same Eclipse session.</p>
<div class="section" title="GenModel Settings">
<div class="titlepage">
<div>
<div>
<h3 class="title">
<a name="GenModelSettings"></a>GenModel Settings</h3>
</div>
</div>
</div>
<p>There is one GenModel setting that needs to be correctly set to ensure that OCL within generated Java classes can successfully be invoked by itself. Make sure that support for reflective operation invocation is generated by setting the
<code class="code">Operation Reflection</code> option to
<code class="code">true</code>.
</p>
</div>
<div class="section" title="OCL Delegate URIs">
<div class="titlepage">
<div>
<div>
<h3 class="title">
<a name="OCLDelegateURI"></a>OCL Delegate URIs</h3>
</div>
</div>
</div>
<p>Each application implementing delegation has an associated Delegate URI, which is</p>
<div class="itemizedlist">
<ul class="itemizedlist" type="disc">
<li class="listitem">
<p>
<code class="code">http://www.eclipse.org/emf/2002/Ecore/OCL</code> for the classic evaluator
</p>
</li>
<li class="listitem">
<p>
<code class="code">http://www.eclipse.org/emf/2002/Ecore/OCL/Pivot</code> for the Pivot evaluator
</p>
</li>
</ul>
</div>
<p>Only the
<code class="code">http://www.eclipse.org/emf/2002/Ecore/OCL</code> was available in the Helios release and so the Helios release of the OCLinEcore editor used that URI.
</p>
<p>The OCLinEcore editor uses the Pivot metamodel which is more accurate and OMG compliant and so in the Indigo release, the OCLinEcore editor uses the
<code class="code">http://www.eclipse.org/emf/2002/Ecore/OCL/Pivot</code> URI and converts all incoming usage of
<code class="code">http://www.eclipse.org/emf/2002/Ecore/OCL</code> URI to
<code class="code">http://www.eclipse.org/emf/2002/Ecore/OCL/Pivot</code>.
</p>
<p>As described in
<a class="link" href="UsersGuide.html#EclipseOCLs" title="The two Eclipse OCLs">The two Eclipse OCLs</a> the Pivot evaluator uses an intermediate Pivot model to hide Ecore and UML2 and so allow full OMG-compliance. The Pivot evaluator is only available when the OCL Examples and Editors feature has been installed as described in
<a class="link" href="Installation.html" title="Installing the Eclipse OCL Examples and Editors">Installation</a>.
</p>
<p>The OCL Delegate URIs are registered using the</p>
<div class="itemizedlist">
<ul class="itemizedlist" type="disc">
<li class="listitem">
<p>org.eclipse.emf.ecore.invocation_delegate</p>
</li>
<li class="listitem">
<p>org.eclipse.emf.ecore.setting_delegate</p>
</li>
<li class="listitem">
<p>org.eclipse.emf.ecore.query_delegate</p>
</li>
<li class="listitem">
<p>org.eclipse.emf.ecore.validation_delegate</p>
</li>
</ul>
</div>
<p>extension points. </p>
</div>
<div class="section" title="Standalone Initialization">
<div class="titlepage">
<div>
<div>
<h3 class="title">
<a name="StandaloneInitialization"></a>Standalone Initialization</h3>
</div>
</div>
</div>
<p>The initialization code for standalone usage of EMF delegates is given in the
<a class="link" href="Standalone.html" title="Ecore/UML Standalone Configuration">Standalone</a> section.
</p>
</div>
<div class="section" title="Invocation Delegates">
<div class="titlepage">
<div>
<div>
<h3 class="title">
<a name="InvocationDelegate"></a>Invocation Delegates </h3>
</div>
</div>
</div>
<p>An invocation delegate is invoked to execute the body of an EOperation. An invocation delegate must be registered for the EPackage of the EClassifier of the EOperation.</p>
<p>The EPackage registration is provided by an EAnnotation on the EPackage</p>
<div class="itemizedlist">
<ul class="itemizedlist" type="disc">
<li class="listitem">
<p>
<code class="code">source</code> =
<code class="code">http://www.eclipse.org/emf/2002/Ecore</code>
</p>
<div class="itemizedlist">
<ul class="itemizedlist" type="circle">
<li class="listitem">
<p>
<code class="code">key</code> =
<code class="code">invocationDelegates</code>
</p>
</li>
<li class="listitem">
<p>
<code class="code">value</code> =
<span class="emphasis"><em>
<code class="code">OCL-Delegate-URI</code>
</em></span>
</p>
</li>
</ul>
</div>
</li>
</ul>
</div>
<p>The invocation delegate is provided by an EAnnotation on the EOperation</p>
<div class="itemizedlist">
<ul class="itemizedlist" type="disc">
<li class="listitem">
<p>
<code class="code">source</code> =
<span class="emphasis"><em>
<code class="code">OCL-Delegate-URI</code>
</em></span>
</p>
<div class="itemizedlist">
<ul class="itemizedlist" type="circle">
<li class="listitem">
<p>
<code class="code">key</code> =
<code class="code">body</code>
</p>
</li>
<li class="listitem">
<p>
<code class="code">value</code> =
<span class="emphasis"><em>
<code class="code">OCL-expression</code>
</em></span>
</p>
</li>
</ul>
</div>
</li>
</ul>
</div>
<p>The
<span class="emphasis"><em>
<code class="code">OCL-expression</code>
</em></span> is evaluated to provide the EOperation value with the containing EClassifier as the
<code class="code">self</code> context object and the EParameters accessible as parameters from OCL. The return type of the
<span class="emphasis"><em>
<code class="code">OCL-expression</code>
</em></span> must conform to the return type of the EOperation.
</p>
</div>
<div class="section" title="Setting Delegates">
<div class="titlepage">
<div>
<div>
<h3 class="title">
<a name="SettingDelegate"></a>Setting Delegates </h3>
</div>
</div>
</div>
<p>A setting delegate is invoked to provide the initial or derived value of an EStructuralFeature. A setting delegate must be been registered for the EPackage of the EClassifier of the EStructuralFeature.</p>
<p>The EPackage registration is provided by an EAnnotation on the EPackage</p>
<div class="itemizedlist">
<ul class="itemizedlist" type="disc">
<li class="listitem">
<p>
<code class="code">source</code> =
<code class="code">http://www.eclipse.org/emf/2002/Ecore</code>
</p>
<div class="itemizedlist">
<ul class="itemizedlist" type="circle">
<li class="listitem">
<p>
<code class="code">key</code> =
<code class="code">settingDelegates</code>
</p>
</li>
<li class="listitem">
<p>
<code class="code">value</code> =
<span class="emphasis"><em>
<code class="code">OCL-Delegate-URI</code>
</em></span>
</p>
</li>
</ul>
</div>
</li>
</ul>
</div>
<p>The setting delegate is provided by an EAnnotation on the EStructuralFeature</p>
<div class="itemizedlist">
<ul class="itemizedlist" type="disc">
<li class="listitem">
<p>
<code class="code">source</code> =
<span class="emphasis"><em>
<code class="code">OCL-Delegate-URI</code>
</em></span>
</p>
<div class="itemizedlist">
<ul class="itemizedlist" type="circle">
<li class="listitem">
<p>
<code class="code">key</code> =
<code class="code">derivation</code>
</p>
</li>
<li class="listitem">
<p>
<code class="code">value</code> =
<span class="emphasis"><em>
<code class="code">OCL-expression</code>
</em></span>
</p>
</li>
</ul>
</div>
</li>
</ul>
</div>
<p>The
<span class="emphasis"><em>
<code class="code">OCL-expression</code>
</em></span> is evaluated to provide the EStructuralFeature value with the containing EClassifier as the
<code class="code">self</code> context object. The result type of the
<span class="emphasis"><em>
<code class="code">OCL-expression</code>
</em></span> must conform to the type of the EStructuralFeature.
</p>
<p>An
<code class="code">initial</code> rather than
<code class="code">derivation</code> value may be specified. The
<code class="code">initial</code> is ignored if a
<code class="code">derivation</code> is also specified.
</p>
</div>
<div class="section" title="Validation Delegates">
<div class="titlepage">
<div>
<div>
<h3 class="title">
<a name="ValidationDelegate"></a>Validation Delegates</h3>
</div>
</div>
</div>
<p>A validation delegate is invoked to provide additional validation of an EClassifier. A validation delegate must be registered for the EPackage of the EClassifier for which the EClassifier provides any Ecore invariants or Ecore constraints. Both Ecore constraints and invariants constrain an EClassifier, the difference is that an Ecore invariant is realised by an EOperation and so an Ecore invariant may be re-used by modeling environments that may wish to selectively check or re-check constraints.</p>
<p>The EPackage registration is provided by an EAnnotation on the EPackage</p>
<div class="itemizedlist">
<ul class="itemizedlist" type="disc">
<li class="listitem">
<p>
<code class="code">source</code> =
<code class="code">http://www.eclipse.org/emf/2002/Ecore</code>
</p>
<div class="itemizedlist">
<ul class="itemizedlist" type="circle">
<li class="listitem">
<p>
<code class="code">key</code> =
<code class="code">validationDelegates</code>
</p>
</li>
<li class="listitem">
<p>
<code class="code">value</code> =
<span class="emphasis"><em>
<code class="code">OCL-Delegate-URI</code>
</em></span>
</p>
</li>
</ul>
</div>
</li>
</ul>
</div>
<p>All Ecore constraints must be listed in an EAnnotation on the EClassifier</p>
<div class="itemizedlist">
<ul class="itemizedlist" type="disc">
<li class="listitem">
<p>
<code class="code">source</code> =
<code class="code">http://www.eclipse.org/emf/2002/Ecore</code>
</p>
<div class="itemizedlist">
<ul class="itemizedlist" type="circle">
<li class="listitem">
<p>
<code class="code">key</code> =
<code class="code">constraints</code>
</p>
</li>
<li class="listitem">
<p>
<code class="code">value</code> =
<span class="emphasis"><em>
<code class="code">constraintName1 constraintName2 constraintName3</code>
</em></span>
</p>
</li>
</ul>
</div>
</li>
</ul>
</div>
<p>The validation delegate for each Ecore constraint is provided by a further EAnnotation on the EClassifier</p>
<div class="itemizedlist">
<ul class="itemizedlist" type="disc">
<li class="listitem">
<p>
<code class="code">source</code> =
<span class="emphasis"><em>
<code class="code">OCL-Delegate-URI</code>
</em></span>
</p>
<div class="itemizedlist">
<ul class="itemizedlist" type="circle">
<li class="listitem">
<p>
<code class="code">key</code> =
<span class="emphasis"><em>
<code class="code">constraintName</code>
</em></span>
</p>
</li>
<li class="listitem">
<p>
<code class="code">value</code> =
<span class="emphasis"><em>
<code class="code">OCL-expression</code>
</em></span>
</p>
</li>
</ul>
</div>
</li>
</ul>
</div>
<p>The validation delegate for each Ecore invariant is provided by an EAnnotation on the EOperation</p>
<div class="itemizedlist">
<ul class="itemizedlist" type="disc">
<li class="listitem">
<p>
<code class="code">source</code> =
<span class="emphasis"><em>
<code class="code">OCL-Delegate-URI</code>
</em></span>
</p>
<div class="itemizedlist">
<ul class="itemizedlist" type="circle">
<li class="listitem">
<p>
<code class="code">key</code> =
<code class="code">body</code>
</p>
</li>
<li class="listitem">
<p>
<code class="code">value</code> =
<span class="emphasis"><em>
<code class="code">OCL-expression</code>
</em></span>
</p>
</li>
</ul>
</div>
</li>
</ul>
</div>
<p>The
<span class="emphasis"><em>
<code class="code">OCL-expression</code>
</em></span> is evaluated to validate the EClassifier with the EClassifier as the
<code class="code">self</code> context object. The result type of the
<span class="emphasis"><em>
<code class="code">OCL-expression</code>
</em></span> must be Boolean.
</p>
</div>
<div class="section" title="Validation Messages">
<div class="titlepage">
<div>
<div>
<h3 class="title">
<a name="ValidationMessages"></a>Validation Messages</h3>
</div>
</div>
</div>
<p>When a validation fails EMF generates a default diagnostic of the form
<code class="code">The</code>
<span class="emphasis"><em>
<code class="code">'constraintName'</code>
</em></span>
<code class="code">is violated on</code>
<span class="emphasis"><em>
<code class="code">'constrainedObject'</code>
</em></span>.
</p>
<p>If the
<a class="link" href="Validators.html#OCLinEcoreEObjectValidator" title="OCLinEcoreEObjectValidator">OCLinEcoreEObjectValidator</a> or
<a class="link" href="Validators.html#CompleteOCLEObjectValidator" title="CompleteOCLEObjectValidator">CompleteOCLEObjectValidator</a> are used a custom message may be supplied using an additional EAnnotation on the EClassifier.
</p>
<div class="itemizedlist">
<ul class="itemizedlist" type="disc">
<li class="listitem">
<p>
<code class="code">source</code> =
<span class="emphasis"><em>
<code class="code">OCL-Delegate-URI</code>
</em></span>
</p>
<div class="itemizedlist">
<ul class="itemizedlist" type="circle">
<li class="listitem">
<p>
<code class="code">key</code> =
<span class="emphasis"><em>
<code class="code">constraintName</code>
</em></span>
<code class="code">$message</code>
</p>
</li>
<li class="listitem">
<p>
<code class="code">value</code> =
<span class="emphasis"><em>
<code class="code">OCL-expression</code>
</em></span>
</p>
</li>
</ul>
</div>
</li>
</ul>
</div>
<p>The
<span class="emphasis"><em>
<code class="code">OCL-expression</code>
</em></span> is evaluated to produce the custom message with the EClassifier as the
<code class="code">self</code> context object. The result type of the
<span class="emphasis"><em>
<code class="code">OCL-expression</code>
</em></span> must be String.
</p>
<p>The severity of the diagnostic can also be customized by exploiting the four values of the Boolean value of the constraint evaluation.</p>
<div class="itemizedlist">
<ul class="itemizedlist" type="disc">
<li class="listitem">
<p>
<code class="code">true</code> indicates successful validation
</p>
</li>
<li class="listitem">
<p>
<code class="code">false</code> indicates unsuccessful validation with warning severity
</p>
</li>
<li class="listitem">
<p>
<code class="code">null</code> indicates unsuccessful validation with error severity
</p>
</li>
<li class="listitem">
<p>
<code class="code">invalid</code> indicates a failure to perform validation (error severity)
</p>
</li>
</ul>
</div>
</div>
<div class="section" title="Query Delegates">
<div class="titlepage">
<div>
<div>
<h3 class="title">
<a name="QueryDelegate"></a>Query Delegates </h3>
</div>
</div>
</div>
<p>A query delegate is invoked to evaluate a parameterized query on a EObject for which there is no corresponding EOperation. A query delegate is registered to install this query and allow its compiled form to be cached. The delegate may then be invoked as many times as required for compatible context objects and parameters.</p>
<p>This facility enables an EMF application to execute OCL without declaring or instantiating any OCL classes.</p>
<p>The query delegate registration is analogous to direct use of
<code class="code">OCL.newInstance().createHelper().createQuery()</code>
</p>
<p>The query delegate execution is analogous to
<code class="code">OCL.evaluate()</code>
</p>
</div>
</div>
</body>
</html>