Stephan Herrmann | 0166441 | 2010-04-01 20:28:43 +0000 | [diff] [blame] | 1 | <!DOCTYPE html |
| 2 | PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "../xhtml1-strict.dtd"> |
| 3 | <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> |
| 4 | <head> |
| 5 | <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> |
Stephan Herrmann | 0166441 | 2010-04-01 20:28:43 +0000 | [diff] [blame] | 6 | <link rel="stylesheet" type="text/css" href="../css/ot.css" /> |
| 7 | <link rel="stylesheet" type="text/css" href="../css/otjld.css" /> |
| 8 | <title>OT/J Language Definition v1.3</title> |
| 9 | </head> |
| 10 | <body class="otdt"> |
| 11 | <div id="content"> |
| 12 | <table class="nav"> |
| 13 | <tr> |
| 14 | <td class="back"><a id="top"></a><a href="s6.1.html" rel="prev"><< §6.1 Reflection</a></td> |
| 15 | <td class="top"><a href="index.html" rel="contents">↑ Table of Contents ↑</a></td> |
Stephan Herrmann | 8a9f3c3 | 2011-03-10 17:49:59 +0000 | [diff] [blame] | 16 | <td class="next"><a href="s6.3.html" rel="next">§6.3 Annotations >></a></td> |
Stephan Herrmann | 0166441 | 2010-04-01 20:28:43 +0000 | [diff] [blame] | 17 | </tr> |
| 18 | </table> |
| 19 | <div class="breadcrumb"><a class="nav" href="s6.html" rel="section">§6 Object Teams API</a></div> |
| 20 | <div class="sect depth2" id="s6.2"> |
Stephan Herrmann | 109893e | 2010-05-18 22:02:53 +0000 | [diff] [blame] | 21 | <h2 class="sect">§6.2 Other API Elements<a class="img" href="s6.2.html" |
| 22 | title="PermaLink to §6.2 Other API Elements"><img style="vertical-align:text-top;margin-left:5px;" src="../images/permalink.png" |
| 23 | alt="" /></a></h2> |
Stephan Herrmann | 0166441 | 2010-04-01 20:28:43 +0000 | [diff] [blame] | 24 | <div class="subsect depth3" id="s6.2.a"> |
Stephan Herrmann | 109893e | 2010-05-18 22:02:53 +0000 | [diff] [blame] | 25 | <h4 class="subsect">(a) <span class="title">Interfaces for role encapsulation</span><a class="img" href="s6.2.a.html" |
| 26 | title="PermaLink to (a) Interfaces for role encapsulation"><img style="vertical-align:text-top;margin-left:5px;" src="../images/permalink.png" |
| 27 | alt="" /></a></h4> |
Stephan Herrmann | 0166441 | 2010-04-01 20:28:43 +0000 | [diff] [blame] | 28 | <p>A set of pre-defined types exist that do <span class="underline">not</span> extend <code>java.lang.Object</code> |
| 29 | and have <span class="underline">no</span> features except the operators <code>==</code> and <code>!=</code>. |
| 30 | |
| 31 | </p> |
| 32 | <div class="note"> |
| 33 | <h5>Note:</h5> |
| 34 | The JLS defines that each interface declares all methods defined in <code>java.lang.Object</code> |
| 35 | (<a href="http://java.sun.com/docs/books/jls/second_edition/html/interfaces.doc.html#32392" |
| 36 | class="ext">JLS §9.2</a>) |
| 37 | and also each object referenced by an interface type can be widened to <code>java.lang.Object</code>. |
| 38 | Compilers commonly implement this by declaring <code>java.lang.Object</code> the super-type of all interfaces. |
| 39 | Such implementation has no visible difference with respect to the more complex definition in the JLS. |
| 40 | |
| 41 | </div> |
| 42 | <p>These predefined types are |
| 43 | |
| 44 | </p> |
| 45 | <dl> |
| 46 | <dt><code>org.objectteams.IConfined</code></dt> |
| 47 | <dd>regular interface</dd> |
| 48 | <dt><code>org.objectteams.ITeam.IConfined</code></dt> |
| 49 | <dd>role interface</dd> |
| 50 | <dt><code>org.objectteams.Team.Confined</code></dt> |
| 51 | <dd>role class</dd> |
| 52 | </dl> |
| 53 | <p>These types provide no new functionality but inheriting from these types influences the semantics with respect to encapsulation. |
| 54 | |
| 55 | The purpose and usage of these types is described in <a href="s7.html" title="§7 Role Encapsulation" class="sect">§7</a>. |
| 56 | |
| 57 | </p> |
| 58 | </div> |
| 59 | <div class="subsect depth3" id="s6.2.b"> |
Stephan Herrmann | 109893e | 2010-05-18 22:02:53 +0000 | [diff] [blame] | 60 | <h4 class="subsect">(b) <span class="title">Interface for explicit lowering</span><a class="img" href="s6.2.b.html" |
| 61 | title="PermaLink to (b) Interface for explicit lowering"><img style="vertical-align:text-top;margin-left:5px;" src="../images/permalink.png" |
| 62 | alt="" /></a></h4> |
Stephan Herrmann | 0166441 | 2010-04-01 20:28:43 +0000 | [diff] [blame] | 63 | <p>The following role interface exists for the purpose of allowing explicit lowering: |
| 64 | |
| 65 | </p> |
| 66 | <dl> |
| 67 | <dt><code>org.objectteams.ITeam.ILowerable</code></dt> |
| 68 | <dd>role interface</dd> |
| 69 | </dl> |
| 70 | <p>This interface was introduced in detail in <a href="s2.2.d.html" title="§2.2.(d) Explicit lowering" |
| 71 | class="sect">§2.2.(d)</a>. |
| 72 | |
| 73 | </p> |
| 74 | </div> |
| 75 | <div class="subsect depth3" id="s6.2.c"> |
Stephan Herrmann | 109893e | 2010-05-18 22:02:53 +0000 | [diff] [blame] | 76 | <h4 class="subsect">(c) <span class="title">Team activation methods</span><a class="img" href="s6.2.c.html" |
| 77 | title="PermaLink to (c) Team activation methods"><img style="vertical-align:text-top;margin-left:5px;" src="../images/permalink.png" |
| 78 | alt="" /></a></h4> |
Stephan Herrmann | 0166441 | 2010-04-01 20:28:43 +0000 | [diff] [blame] | 79 | <p>Every team can be activated and deactivated by predefined methods of the interface <code>org.objectteams.ITeam</code>. |
| 80 | |
| 81 | </p> |
| 82 | <dl> |
| 83 | <dt><code>activate()</code> and <code>activate(Thread th)</code></dt> |
| 84 | <dd>Methods for activation of a team</dd> |
| 85 | <dt><code>deactivate()</code> and <code>deactivate(Thread th)</code></dt> |
| 86 | <dd>Methods for deactivation of a team</dd> |
| 87 | </dl> |
| 88 | <p>The usage of these Methods is described in <a href="s5.2.b.html" title="§5.2.(b) Imperative activation" |
| 89 | class="sect">§5.2.(b)</a>. |
| 90 | |
| 91 | </p> |
| 92 | </div> |
| 93 | <div class="subsect depth3" id="s6.2.d"> |
Stephan Herrmann | 109893e | 2010-05-18 22:02:53 +0000 | [diff] [blame] | 94 | <h4 class="subsect">(d) <span class="title">Exceptions</span><a class="img" href="s6.2.d.html" title="PermaLink to (d) Exceptions"><img style="vertical-align:text-top;margin-left:5px;" src="../images/permalink.png" |
| 95 | alt="" /></a></h4> |
Stephan Herrmann | 0166441 | 2010-04-01 20:28:43 +0000 | [diff] [blame] | 96 | <p>The following <code>Exceptions</code> can be thrown during the execution of an ObjectTeam/Java program: |
| 97 | |
| 98 | </p> |
| 99 | <dl> |
| 100 | <dt><code>ResultNotProvidedException</code></dt> |
| 101 | <dd>Thrown if a replace callin without a base call does not provide the necessary (primitive type) base result |
| 102 | (see <a href="s4.3.e.html" title="§4.3.(e) Fragile callin binding" |
| 103 | class="sect">§4.3.(e)</a>). |
| 104 | </dd> |
| 105 | <dt><code>LiftingFailedException</code></dt> |
| 106 | <dd>Thrown if an actual ambiguity occurs during lifting (see <a href="s2.3.4.c.html" title="§2.3.4.(c) Actual ambiguity" |
Stephan Herrmann | 76c2ca9 | 2011-05-12 15:50:01 +0000 | [diff] [blame] | 107 | class="sect">§2.3.4.(c)</a>) |
| 108 | or if lifting would need to instantiate an abstract role class (see <a href="s2.5.b.html" title="§2.5.(b) Relevant roles" class="sect">§2.5.(b)</a>). |
| 109 | This is a checked exception. |
| 110 | See <a href="s2.3.5.html" |
| 111 | title="§2.3.5 Consequences of lifting problems" |
| 112 | class="sect">§2.3.5</a> for more information. |
Stephan Herrmann | 0166441 | 2010-04-01 20:28:43 +0000 | [diff] [blame] | 113 | </dd> |
| 114 | <dt><code>WrongRoleException</code></dt> |
| 115 | <dd>Thrown during lifting if the base object has, with respect to the same team instance, previously been lifted |
| 116 | to a role type that is not conform to the currently requested type |
| 117 | (see <a href="s2.3.4.d.html" title="§2.3.4.(d) Mismatching role" |
| 118 | class="sect">§2.3.4.(d)</a> and <a href="s2.4.3.html" |
| 119 | title="§2.4.3 Role creation in the presence of smart lifting" |
| 120 | class="sect">§2.4.3</a>). |
| 121 | </dd> |
| 122 | <dt><code>DuplicateRoleException</code></dt> |
| 123 | <dd>Thrown during explicit role creation, if a new role is created for a base object, which already has a role |
| 124 | of the required type in the given team (see <a href="s2.4.1.c.html" |
| 125 | title="§2.4.1.(c) Duplicate role runtime check" |
| 126 | class="sect">§2.4.1.(c)</a>). |
| 127 | </dd> |
| 128 | <dt><code>RoleCastException</code></dt> |
| 129 | <dd>Thrown during cast of an externalized role, if the casted expression is anchored to a different team instance |
| 130 | than the cast type (see <a href="s1.2.4.b.html" title="§1.2.4.(b) Casting" class="sect">§1.2.4.(b)</a>). |
| 131 | </dd> |
| 132 | <dt><code>LiftingVetoException</code></dt> |
| 133 | <dd>This exception is used internally to abort the process of lifting when a relevant guard predicate (<a href="s5.4.html" title="§5.4 Guard predicates" class="sect">§5.4</a>) evaluated to false. |
| 134 | Such exceptions thrown from generated code will never appear in client code, so there is usually no need to catch a <code>LiftingVetoException</code>. |
| 135 | However, in some situations it is useful to explicitly <em>throw</em> a <code>LiftingVetoException</code> from a lifting constructor (<a href="s2.3.1.b.html" |
| 136 | title="§2.3.1.(b) Default lifting constructor" |
| 137 | class="sect">§2.3.1.(b)</a>) of a role. |
| 138 | This style allows to abort lifting even after the lifting constructor has started to work and also for method parameters |
| 139 | requiring lifting. |
| 140 | If lifting was triggered due to a callin method binding, this binding will simply not trigger if a <code>LiftingVetoException</code> is thrown |
| 141 | while preparing the call to the role method. |
| 142 | </dd> |
| 143 | </dl> |
| 144 | </div> |
| 145 | <div class="subsect depth3" id="s6.2.e"> |
Stephan Herrmann | 109893e | 2010-05-18 22:02:53 +0000 | [diff] [blame] | 146 | <h4 class="subsect">(e) <span class="title">Role migration</span><a class="img" href="s6.2.e.html" title="PermaLink to (e) Role migration"><img style="vertical-align:text-top;margin-left:5px;" src="../images/permalink.png" |
| 147 | alt="" /></a></h4> |
Stephan Herrmann | 0166441 | 2010-04-01 20:28:43 +0000 | [diff] [blame] | 148 | <p>The following interfaces can be used to enable role migration:</p> |
| 149 | <dl> |
| 150 | <dt><code>IBaseMigratable</code></dt> |
| 151 | <dd>This interface declares a method |
| 152 | <div class="listing plain"><pre> |
| 153 | <code><B> <b>void</b> migrateToBase(B otherBase)</code> </pre></div> |
| 154 | and instructs the compiler to generate an implementation of this method |
| 155 | for any bound role declaring <code>IBaseMigratable</code> as its super-interface.<br /> |
| 156 | The effect of calling <code>migrateToBase</code> on a role instance is to re-bind this role to a new base instance. |
| 157 | The base instance must be compatible to the role's base class (in order to avoid problems during lifting the |
| 158 | compiler may require the base to be of the exact type of the role's base class). |
| 159 | Passing <code>null</code> to this method causes an <code>NullPointerException</code> to be thrown. |
| 160 | </dd> |
| 161 | <dt><code>ITeamMigratable</code></dt> |
| 162 | <dd>This interface declares a method |
| 163 | <div class="listing plain"><pre> |
| 164 | <code><R> R<@otherTeam> migrateToTeam(<b>final</b> ITeam otherTeam)</code></pre></div> |
| 165 | and instructs the compiler to |
| 166 | generate an implementation of this method for any role declaring <code>ITeamMigratable</code> as its super-interface.<br /> |
| 167 | The effect of calling <code>migrateToTeam</code> on a role instance is to re-bind this role to become a contained part of a new team instance. |
| 168 | The team instance must be of the exact type of the role's enclosing team. |
| 169 | Passing <code>null</code> to this method causes a <code>NullPointerException</code> to be thrown.<br /><div class="note"> |
| 170 | <h5>Caveat:</h5> |
| 171 | This method intentionally breaks the rules of family polymorphism: any reference <code>R<@previousTeam> r</code> |
| 172 | which was established before migration will incorrectly imply that the role's enclosing team still is <code>previousTeam</code>, |
| 173 | which is no longer true after migration. |
| 174 | While this does not effect any method lookup (which is still safe), further assumptions based on a role's dependent type |
| 175 | are invalidated by team migration. The same holds for references from the migrating role to any sibling role instances.<br /> |
| 176 | If the rules of family polymorphism should be maintained one should just refrain from declaring <code>ITeamMigratable</code> |
| 177 | as a role's super-interface. |
| 178 | </div> |
| 179 | </dd> |
| 180 | </dl> |
| 181 | <p>For both methods the signature declared in the interface is over-generalized, yet the compiler performs the necessary checks |
| 182 | to |
| 183 | ensure that role, base and team instances are indeed compatible and additionally the return type of <code>migrateToTeam</code> |
| 184 | is checked as a self-type, i.e., it reflects the exact type of the call target. |
| 185 | </p> |
| 186 | </div> |
| 187 | </div> |
| 188 | <table class="nav"> |
| 189 | <tr> |
| 190 | <td class="back"><a href="s6.1.html" rel="prev"><< §6.1 Reflection</a></td> |
| 191 | <td class="top"><a href="index.html" rel="contents">↑ Table of Contents ↑</a></td> |
Stephan Herrmann | 8a9f3c3 | 2011-03-10 17:49:59 +0000 | [diff] [blame] | 192 | <td class="next"><a href="s6.3.html" rel="next">§6.3 Annotations >></a></td> |
Stephan Herrmann | 0166441 | 2010-04-01 20:28:43 +0000 | [diff] [blame] | 193 | </tr> |
| 194 | </table> |
| 195 | <div class="breadcrumb"><a class="nav" href="s6.html" rel="section">§6 Object Teams API</a></div> |
| 196 | </div> |
| 197 | <div id="footer"> |
Stephan Herrmann | 109893e | 2010-05-18 22:02:53 +0000 | [diff] [blame] | 198 | <hr /><a class="w3c img" href="http://jigsaw.w3.org/css-validator/check/referer" |
| 199 | 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" |
| 200 | width="88" /></a><address>© Stephan Herrmann, Christine Hundt, Marco Mosconi</address> |
Stephan Herrmann | b7085ef | 2011-05-15 14:59:15 +0000 | [diff] [blame] | 201 | OT/J version 1.3 — last modified: 2011-05-15 |
Stephan Herrmann | 0166441 | 2010-04-01 20:28:43 +0000 | [diff] [blame] | 202 | </div> |
| 203 | </body> |
| 204 | </html> |