• Non ci sono risultati.

5.2 Generic Sequence Diagram

5.2.3 Iteration construct

: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

5.2.3 Iteration construct

In a generic SD an iteration of a set of messages indicates that the sending of these messages can occur multiple times depending whether a given condition clause is satisfied or not. The connected set of arrows, representing the iterated set of messages, may be enclosed and marked as an iteration, as depicted in Figure 5.5(A) for messages {m1, m3, m4} that are enclosed and marked with 1..n.

Note that the condition clause of the iteration is assigned to a message belonging to the iteration, e.g., in Figure 5.5(A) the message m1, but with respect to the iteration-clause of a conditional message that, if satisfied, provokes the repetition of the action that causes the sending of the message, when the iteration condition is satisfied all the messages belonging to the iteration will be sent according to the precedence relation defined between them. As for branch construct, there is not a formal definition of the iteration of a set of messages in a SD, so that we interpret the iteration as an extension of a conditional message with iteration clause. For example, the condition clause of the iteration of the set of messages{m1, m3, m4} of Figure 5.5(A) associated to message m1is derived from a recurrence expression of type:

W HILE <cond> <m1 specification><m3 specification><m4 specification>

CHAPTER 5. TRANSLATION OF SEQUENCE DIAGRAMS 119 where < cond > is the condition clause of the iteration and < m1 specification >< m3 specification > <

m4 specification> represents the execution of actions act1= m1.action, act3= m3.action, act4= m4.action that cause the messages m1, m3, m4 to be sent. The messages belonging to an iteration are characterized by having among their predecessors at least a message that is also an indirect successor: e.g., in Figure 5.5(A) message m1 is characterized by two predecessors mpand m4, the latter being an indirect successor also, messages m3and m4 have m1and m3, respectively, as both predecessor and indirect successor. The indirect successor relation can be derived from the association successor defined between messages (see Figure 4.11 showing part of the Collabo-rations metamodel) by transitive closure: we can define this relation allSuccessors, by using the OCL syntax, in a similar way as done for the indirect predecessor relation allPredecessors, that is:

context Message inv:

allSuccessors : Set(Message);

allSuccessors = self.successor->union (self.successor.allSuccessors)

An iteration construct should be characterized by (at least) a branching consisting of two mutually exclusive messages: one message with its condition-clause equal to the iteration clause, and hence belonging to the itera-tion, and the other conditional message representing the exit from the iteration. For example, the iteration shown in Figure 5.5(A) is characterized by one branch construct consisting of two mutually exclusive messages m1and m4. After these considerations, we can give a formal interpretation of the iteration construct of a SD:

Interpretation 7 Let sdi be a SD with iterations, then an iteration construct is a set of messages It⊆ i.Message, with |It| > 1, such that: 1) for all m ∈ It, denoting as PRSm= m.predecessor ∩ m.allSuccessors the set of messages both predecessors and (indirect) successors of m, we have PRSm6=/0; 2) there exists at least a branch construct B ={m1, m2} ⊂ i.message, where m1∈ It, m26∈ It and m1RME m2.

The presence of an iteration construct requires a modification of the GSPN translation of the messages belong-ing to the iteration: in particular, the modification concerns the definition of the source places, along with their labeling, of the GSPNs corresponding to the iterated messages m for which the set PRSm, defined above, is a proper subset of the predecessor-set PRm. Indeed, to establish the number of the source places of those GSPNs it is necessary to identify the predecessors of the corresponding message that are not indirect successors of the message, i.e. to identify the set PRm\ PRSm: since in a generic SD there may exist more than one predecessor, this number depends whether the predecessors in PRm\ PRSmare in mutual exclusion relation or not. Once fixed the number of source places, the assignment of their labels is carried out taking in account of the messages be-longing to the set PRSmalso. For simplicity, we restrict to the case in which either the set PRSmcontains a single message or all the pairs of messages in PRSmare mutually exclusive.

For example, in Figure 5.5(B) are emphasized the source places of the MLGSPN models representing the messages of the iteration depicted in Figure 5.5(A). Observe that while the translation of messages m3and m4is not modified with respect to Definition 5, the translation of message m1is changed: the message m1characterized

by the sets PRm={mp, m4} and PRSm={m4}. Being |PRm\PRSm| = 1 its translation corresponds to a MLGSPN in which there is a unique source place p1 with two labels {mp m1, m4 m1} that take into account also the predecessor m4which is an indirect successor of m1.

We can formally define the translation of a message m belonging to an iteration construct as follows:

Definition 9 Let m be a message belonging to an iteration construct It⊆ i.message of a SD sdi and let PRm and PRSmbe its predecessor-set and the set of its predecessors that are also its indirect successors, respectively.

Moreover, let us denote as MEPRm\PRSm the set of messages belonging to the set PRm\ PRSmthat are in mutual exclusion relation and as MEPRm\PRSm the set of pairs of mutually exclusive messages belonging to the set PRm\ PRSm. in Definition 8 but considering the re-definition of the set of source places SOU RCEmgiven above. The functions F˜m={ ˜Πm, ˜Im, ˜Om, ˜Hm, ˜Wm, ˜Mm0, ˜Λm} are equal to the corresponding functions ˆFm={ ˆΠm, ˆIm, ˆOm, ˆHm, ˆWm, ˆM0m, ˆΛm} specified in Definition 8. The place labeling function is defined as:

Ψ˜m(p) =

CHAPTER 5. TRANSLATION OF SEQUENCE DIAGRAMS 121

• ” ” is a constant character;

• m = m.name, mp = pr.name with pr ∈ PRm\MEPRm, mp0= pr0.name and mp00= pr00.name with (pr0, pr00)∈ MEPRm and mps = prs.name with prs∈ PRSm;

• ˆΨm(p) is the place labeling function defined in Definition 8.