• Non ci sono risultati.

5.2 Generic Sequence Diagram

5.2.2 Branch construct

A branch construct in a SD is shown by multiple arrows leaving a single point, each arrow is possibly labeled by a condition clause representing a conditional message. Depending on whether the condition clauses of the mes-sages belonging to the same branch are mutually exclusive or not, the branch construct may represent condition and/or concurrency. An example of branching representing both condition and concurrency is depicted in Figure 5.4, upper part: messages m1, m2and m3 belong to a branch construct; they are all characterized by a condition clause, in particular, m1 and m2 have mutually exclusive condition clauses, while message m3 has a condition clause that is not mutually exclusive with neither the condition clause of m1nor the condition clause of m2.

With reference to the partial Collaborations metamodel depicted in Figure 4.11, we can then interpret a branch construct as follows:

Interpretation 4 Let sdibe a generic SD representing an interaction i∈ Interaction, then a branch construct is a set of messages B⊂ i.Message such that for all m, m0∈ B m.predecessor = m0.predecessor. In case of initial branch construct we have that m.predecessor = m0.predecessor = /0.

UML specification does not exclude the presence of non-conditional messages in a branch construct: it is reasonable to consider a non-conditional message belonging to a branch as a conditional message in which the condition clause is a tautology. We can formalize the mutual exclusion relation between two messages as follows:

Interpretation 5 Let m, m0∈ i.message be two conditional messages, then they are mutually exclusive (mRMEm0) if their corresponding condition clauses <cond> and <cond0> are mutually exclusive, i.e., the boolean expres-sion cond AND cond0 is a contradiction, otherwise the messages are concurrent.

In a generic SD, the predecessor association defined between messages of a generic SD, allows to derive only a partial order relation among the messages: in particular, in presence of branching there are messages with more than one predecessor and/or successor, e.g., message mpof Figure 5.4 is characterized by the set of successors

CHAPTER 5. TRANSLATION OF SEQUENCE DIAGRAMS 115

[x>0]m1 /rj:cj /rl:cl

...

:ck

[x<=0]m2

:cy

...

[y=0]m3 mp

<mp specification>

mp_m3 mp_m1, mp_m2

p_12 p_3

<m1 specification>

mp_m1 p_1

<m2 specification>

mp_m2 p_2

<m3 specification>

mp_m3 p_3

Figure 5.4: Branch construct in a SD.

{m1, m2, m3}, and there may exist “concurrent” messages such as the pair of messages (m1, m3) and (m2, m3) in Figure 5.4.

The presence of a branch construct requires a modification of the translation of those messages that are either predecessors or successors of the messages belonging to the branch. When the branch consists of all concurrent messages, then the modification is limited to the number of sink places or source places characterizing the net representing either the predecessors or the successors, respectively, of the branch, but the translation still results in a labeled GSPN model. When, instead, the branch contains mutually exclusive messages the translation of the predecessors/ successors of the branch results in a multi-labeled GSPN (MLGSPN), in particular, there exist sink or source places characterized by more than one label. For example, as depicted in Figure 5.4, bottom part, the translation of the predecessor message mpresults in multi-labeled GSPN (MLGSPN); the set of sink places is characterized by places p3, p12and, moreover, two labels mp m1 and mp m2 have been assigned to the sink place p12.

Concerning messages belonging to a branch construct B, we can assume, for simplicity, that among the

mes-sages mutually exclusive with a given message of the branch, eventually at least one of them will be sent:

Interpretation 6 Let B⊂ i.Message be a branch construct and MEm={mj: mjRMEm} be the set of |MEm| = K messages in mutual exclusion relation with a message m∈ B. Then, denoting as condj the condition associated to the conditional message mj, the boolean expression:

cond OR cond1OR cond2OR ... OR condK

is a tautology.

Then, according to the above interpretation, we make the following distinction for the translation of the mes-sages belonging to a branch B:

• messages that are mutually exclusive with at least a message of branch B are considered as non-conditional messages and their GSPN translation is carried out by applying the Definition 5. For example, this is the case of messages m1and m2of Figure 5.4, upper part;

• messages that are not mutually exclusive with any other message of branch B are considered conditional messages with condition clause and their GSPN translation is carried out by applying the Definition 6. For example, this is the case of message m3of Figure 5.4, upper part.

Observe that also messages belonging to a branch construct can have more than one predecessor or successor so that the translations given in Definition 5 and in Definition 6 need to be updated in order to consider a set of source and/or sink places instead of a unique source (sink) place. We can formally define the translation of a message m∈ i.message in a SD characterized by branching as follows:

Definition 8 Let sdi be a SD with branching and let PRmand Smbe the sets of predecessors and of successors of a message m. Moreover, let us denote as:

MEPRm ={m0∈ PRm| ∃m00∈ PRmm0RME m00} and MESm={m0∈ Sm| ∃m00∈ Smm0RME m00} the set of its predecessors and of its successors, respectively, that are in mutual exclusion relation, and as:

MEPRm ={(m0, m00)∈ PRm× PRm| m0RME m00} and MESm={(m0, m00)∈ Sm× Sm| m0RME m00} the set of pairs of mutually exclusive successor and predecessor messages, respectively.

Then, message m is translated into a MLGSPNMLSm= ( ˆSm, ˆΨm, ˆΛm) where the sets of its sink and source places is defined as follows:

SINKm = χ(Sm){p5} ∪ χ(Sm)h [

s∈Sm\MESm

{ps} ∪ [

s∈MESm: s≡(s0,s00) or s≡(s00,s0)

{ps}i ,

SOU RCEm = χ(PRm){p1} ∪ χ(PRm)

h [

pr∈PRm\MEPRm

{ppr} ∪ [

pr∈MEPRm: pr≡(pr0,pr00) or pr≡(pr00,pr0)

{ppr}i .

CHAPTER 5. TRANSLATION OF SEQUENCE DIAGRAMS 117

The set of places ˆPmand the functions ˆFm={ ˆHm, ˆΠm, ˆMm0} are equal to Pmand Fm={Hmm, Mm0}, respec-tively, the latter being defined in Definition 5 forLSm, but considering the redefinition of the sets SINKm and SOU RCEmgiven above. The set of transitions ˆTmand the functions Gm={ ˆIm, ˆOm, ˆWm} are equal to:

- Tmand Gm={Im, Om,Wm}, respectively, the latter being defined in definition 5 forLSm, if m is a mutual exclusive message belonging to a branch,

- Tm0 and G0m={Im0 , O0m,Wm0}, respectively, the latter being defined in Definition 6 forLS0m, otherwise.

To assign labels to the places we need to introduce the following notation:

• the set of messages belonging to an initial branch construct, i.e., B = {mb : PRmb= /0}, and the set of messages mutually exclusive with m in case the latter belongs to B, i.e., BMEm={e ∈ B | eRME m};

• φ: B−→ {1,..., |B|} a bijection that assigns a total order to the messages in B;

• the operator cat(mb.name, mb0.name) that concatenates two strings mb.name and mb0.name, being mb, mb0B and mb6= mb0, defined as follows:

cat(mb.name, mb0.name) =





mb.name mb0.name ifφ(mb) <φ(mb0) mb0.name mb.name ifφ(mb0) <φ(mb)

• the constant character ” ”;

• m = m.name, me = e.name where e ∈ BMEm, mp = pr.name where pr∈ PRm\ MEPRm, mp0= pr0.name and mp00= pr00.name where (pr0, pr00)∈ MEPRm, ms0= s0.name and ms00= s00.name where (s0, s00)∈ MESm. Then the place labeling function is defined as:

Ψˆm(p) =

<m1 specification>

mp_m1, m4_m1 p_1

<m3 specification>

m1_m3 p_2

<m4 specification>

m3_m4 p_3 [cond]m1

/rj:cj /rl:cl

...

:ck :cy

...

[not(cond)]m2 mp

m4 1..n

m3

(A) (B)

Figure 5.5: Iteration of a set of messages in a SD.

Finally, the transition labeling function is defined as follows:

Λˆm(t) =

m(t)} if t ∈ ˆTmand ˆTm≡ Tm

0m(t)} if t ∈ ˆTmand ˆTm≡ Tm0