| <!DOCTYPE html |
| PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "../xhtml1-strict.dtd"> |
| <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> |
| <head> |
| <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> |
| <link rel="stylesheet" type="text/css" href="../css/ot.css" /> |
| <link rel="stylesheet" type="text/css" href="../css/otjld.css" /> |
| <title>OT/J Language Definition v1.3</title> |
| </head> |
| <body class="otdt"> |
| <div id="content"> |
| <table class="nav"> |
| <tr> |
| <td class="back"><a id="top"></a><a href="s4.7.html" rel="prev"><< §4.7 Callin binding with static methods</a></td> |
| <td class="top"><a href="index.html" rel="contents">↑ Table of Contents ↑</a></td> |
| <td class="next"><a href="s4.9.html" rel="next">§4.9 Callin inheritance >></a></td> |
| </tr> |
| </table> |
| <div class="breadcrumb"><a class="nav" href="s4.html" rel="section">§4 Callin Binding</a></div> |
| <div class="sect depth2" id="s4.8"> |
| <h2 class="sect">§4.8 Callin precedence<a class="img" href="s4.8.html" |
| title="PermaLink to §4.8 Callin precedence"><img style="vertical-align:text-top;margin-left:5px;" src="../images/permalink.png" |
| alt="" /></a></h2> |
| <div class="syntaxlink"><a href="sA.8.html" title="§A.8 Precedence declaration" |
| class="syntax">→ Syntax §A.8</a></div> |
| <p>If multiple callins from the same team refer to the same base method and also have the same |
| callin modifier (<code>before</code>, <code>after</code> or <code>replace</code>), the order in which |
| the callin bindings shall be triggered has to be declared using a precedence declaration. |
| |
| </p> |
| <div class="subsect depth3" id="s4.8.a"> |
| <h4 class="subsect">(a) <span class="title">Precedence declaration</span><a class="img" href="s4.8.a.html" |
| title="PermaLink to (a) Precedence declaration"><img style="vertical-align:text-top;margin-left:5px;" src="../images/permalink.png" |
| alt="" /></a></h4> |
| <p>A precedence declaration consists of the keyword <code>precedence</code> followed by |
| a list of names referring to callin bindings (see <a href="s4.1.e.html" title="§4.1.(e) Named callin binding" |
| class="sect">§4.1.(e)</a> for named callin bindings). |
| |
| </p> |
| <div class="listing plain"><pre><b>precedence</b> callinBinding1, callinBinding2;</pre></div> |
| <p> |
| A precedence declaration is only legal within a role or team class.<br /> |
| The order of elements in a precedence declaration determines their <strong>priority</strong> during dispatch, |
| similar to priorities based on activation of several team instances (<a href="s5.1.html" title="§5.1 Effect of team activation" |
| class="sect">§5.1</a>). |
| This means that <code>before</code> and <code>replace</code> binding with highest priority trigger first, |
| whereas <code>after</code> bindings with highest priority trigger last. |
| For binding precedences (as opposed to class based precedence, see <a href="#s4.8.c" title="§4.8.(c) Class based precedence" |
| class="sect">§4.8.(c)</a> below) |
| which refer to <code>after</code> bindings, the precedence declaration must also use the <code>after</code> keyword |
| to remind the programmer that the execution order is inverse to the textual order. |
| |
| </p> |
| <div class="listing plain"><pre><b>precedence</b> <b>after</b> importantExecuteLast, lessImportantExecuteEarlier;</pre></div> |
| </div> |
| <div class="subsect depth3" id="s4.8.b"> |
| <h4 class="subsect">(b) <span class="title">Qualified and unqualified names</span><a class="img" href="s4.8.b.html" |
| title="PermaLink to (b) Qualified and unqualified names"><img style="vertical-align:text-top;margin-left:5px;" src="../images/permalink.png" |
| alt="" /></a></h4> |
| <p>Within a role class a callin binding may be referenced by its unqualified name. |
| A precedence declaration in a team class must qualify the callin name with the name of the declaring |
| role class. A team with nested teams may concat role class names. |
| Elements of a qualified callin name are separated by ".". |
| <br /> |
| The callin binding must be found in the role specified by the qualifying prefix or |
| in the enclosing role for unqualified names, or any super class of this role |
| (including implicit super classes <a href="s1.3.1.html" |
| title="§1.3.1 Acquisition and implicit inheritance of role classes" |
| class="sect">§1.3.1</a>). |
| |
| </p> |
| </div> |
| <div class="subsect depth3" id="s4.8.c"> |
| <h4 class="subsect">(c) <span class="title">Class based precedence</span><a class="img" href="s4.8.c.html" |
| title="PermaLink to (c) Class based precedence"><img style="vertical-align:text-top;margin-left:5px;" src="../images/permalink.png" |
| alt="" /></a></h4> |
| <p>At the team level a precedence declaration may contain role class names without |
| explicitly mentioning callin bindings in order to refer to all callin bindings of the role. |
| |
| </p> |
| </div> |
| <div class="subsect depth3" id="s4.8.d"> |
| <h4 class="subsect">(d) <span class="title">Multiple precedence statements</span><a class="img" href="s4.8.d.html" |
| title="PermaLink to (d) Multiple precedence statements"><img style="vertical-align:text-top;margin-left:5px;" src="../images/permalink.png" |
| alt="" /></a></h4> |
| <p>All precedence statements are collected at the outer-most team. At that level all |
| precedence declarations involving the same base method are merged using the |
| C3 algorithm <a href="s4.html#fn3-c3-algorithm" class="int">[3]</a>. It is an error to declare |
| incompatible precedence lists that cannot be merged by the C3 algorithm. |
| |
| </p> |
| </div> |
| <div class="subsect depth3" id="s4.8.e"> |
| <h4 class="subsect">(e) <span class="title">Binding overriding</span><a class="img" href="s4.8.e.html" |
| title="PermaLink to (e) Binding overriding"><img style="vertical-align:text-top;margin-left:5px;" src="../images/permalink.png" |
| alt="" /></a></h4> |
| <p>Precedence declarations may conflict with overriding of callin bindings |
| (see <a href="s4.1.e.html" title="§4.1.(e) Named callin binding" |
| class="sect">§4.1.(e)</a>): For each pair of callin bindings of which one |
| callin binding overrides the other one, precedence declarations are not applicable, |
| since dynamic binding will already select exactly one callin binding. |
| <br /> |
| It is an error to <i>explicitly mention</i> such a pair of overriding callin bindings in a precedence declaration. |
| <br /> |
| When a class-based precedence declaration <i>implicitly refers to</i> a callin binding that is overridden by, |
| or overrides any other callin binding within the same precedence declaration, this does not affect the fact, |
| that the most specific callin binding overrides less specific ones. |
| |
| </p> |
| </div> |
| <h5 class="listing">Callin binding example</h5> |
| <div class="listing example frame"> |
| <table class="listing"> |
| <tr class="line odd"> |
| <td class="ln">1</td> |
| <td><pre><b>public</b> <b>class</b> LogLog<b>in</b> <b>playedBy</b> Data<b>base</b> {</pre></td> |
| </tr> |
| <tr class="line even"> |
| <td class="ln">2</td> |
| <td><pre> <b>callin</b> <b>void</b> log (String what) {</pre></td> |
| </tr> |
| <tr class="line odd"> |
| <td class="ln">3</td> |
| <td><pre> System.out.println("enter " + what);</pre></td> |
| </tr> |
| <tr class="line even"> |
| <td class="ln">4</td> |
| <td><pre> base.log(what.toLowerCase());</pre></td> |
| </tr> |
| <tr class="line odd"> |
| <td class="ln">5</td> |
| <td><pre> System.out.println("leave " + what);</pre></td> |
| </tr> |
| <tr class="line even"> |
| <td class="ln">6</td> |
| <td><pre> }</pre></td> |
| </tr> |
| <tr class="line odd"> |
| <td class="ln">7</td> |
| <td><pre> <b>void</b> log(String what) <b><-</b> <b>replace</b> <b>void</b> login(String uid, String passwd) </pre></td> |
| </tr> |
| <tr class="line even"> |
| <td class="ln">8</td> |
| <td><pre> <b>with</b> { what <b><-</b> uid }</pre></td> |
| </tr> |
| <tr class="line odd"> |
| <td class="ln">9</td> |
| <td><pre>}</pre></td> |
| </tr> |
| <tr class="line even"> |
| <td class="ln">10</td> |
| <td><pre>(<b>new</b> Database()).login("Admin", "Passwd");</pre></td> |
| </tr> |
| </table> |
| </div> |
| <div class="codecomment"> |
| <h5>Effects:</h5> |
| <p>Provided the callin bindings are active (cf. <a href="s5.html" title="§5 Team Activation" class="sect">§5</a>) then: |
| |
| </p> |
| <ul> |
| <li>the call in line 10 is intercepted by method <code>log</code> |
| of role <code>LogLogin</code>. |
| </li> |
| <li>the call target of <code>log</code> is a role of type |
| <code>LogLogin</code> which is created by lifting the |
| original call target (of type <code>Database</code>) to |
| <code>LogLogin</code>. |
| </li> |
| <li>only parameter <code>uid</code> is passed to <code>log</code> |
| (bound to formal parameter <code>what</code>). |
| </li> |
| <li>within method <code>log</code> the base call (line 4) invokes |
| the original method passing a modified uid (converted to lower case, cf. line 4) |
| and the unmodified password, which is hidden from the callin method due to the |
| parameter mapping in line 8. |
| </li> |
| </ul> |
| </div> |
| </div> |
| <table class="nav"> |
| <tr> |
| <td class="back"><a href="s4.7.html" rel="prev"><< §4.7 Callin binding with static methods</a></td> |
| <td class="top"><a href="index.html" rel="contents">↑ Table of Contents ↑</a></td> |
| <td class="next"><a href="s4.9.html" rel="next">§4.9 Callin inheritance >></a></td> |
| </tr> |
| </table> |
| <div class="breadcrumb"><a class="nav" href="s4.html" rel="section">§4 Callin Binding</a></div> |
| </div> |
| <div id="footer"> |
| <hr /><a class="w3c img" href="http://jigsaw.w3.org/css-validator/check/referer" |
| shape="rect"><img src="../images/valid-css2-blue.png" alt="Valid CSS!" height="31" width="88" /></a><a class="w3c img" href="http://validator.w3.org/check?uri=referer" shape="rect"><img src="../images/valid-xhtml10-blue.png" alt="Valid XHTML 1.0 Strict" height="31" |
| width="88" /></a><address>© Stephan Herrmann, Christine Hundt, Marco Mosconi</address> |
| OT/J version 1.3 — last modified: 2010-05-18 |
| </div> |
| </body> |
| </html> |