<!DOCTYPE article PUBLIC "-//NLM//DTD JATS (Z39.96) Journal Archiving and Interchange DTD v1.0 20120330//EN" "JATS-archivearticle1.dtd">
<article xmlns:xlink="http://www.w3.org/1999/xlink">
  <front>
    <journal-meta />
    <article-meta>
      <contrib-group>
        <aff id="aff0">
          <label>0</label>
          <institution>Institute of Applied Informatics, Department of Computer Scicncc and Managcmcnt, Wroclaw Univcrsity of Technology</institution>
          ,
          <country>Poland zbigniew</country>
        </aff>
      </contrib-group>
      <fpage>73</fpage>
      <lpage>80</lpage>
      <abstract>
        <p>Executable prototypcs generatcd on early stages of software development bring many benefits, first of all they help to develop and validate systcm's spccification. The paper prcsents an approach to automatic systcm prototype generation based on a collection of UML 2.0 scquerrce diagrams. In thc approach a set of sequcnce diagrams rcpresenting behavior of a specified systenr is transforrned into a state machirre and next a Java code is generated for the state machine. Thc trarrsformatiorm arc described inforrnally by presentation of simplc examples. Architecture of the system implementing the transformation is briefly describcd.</p>
      </abstract>
      <kwd-group>
        <kwd>Sequence diagram</kwd>
        <kwd>statc machine</kwd>
        <kwd>prototype</kwd>
        <kwd>code gcncration</kwd>
      </kwd-group>
    </article-meta>
  </front>
  <body>
    <sec id="sec-1">
      <title>Introduction</title>
      <p>Sequencediagrams are verv often used as behaviour specification of developed
systcrrs. Thcy becorne very popular with advcnt of the UML specification
languagc. UML scquencediagrams were adopted from messagesequencecharts that
wcre known already in other visual languages developed long ago by the
International Telecommunication Union. UML 2.0 also uses other diagrams to specify
bchaviour, e.g. communication and collaboration diagrams. All those diagrams
express similar all,hough not, identical information and show il, in a way dillerent
from thc sequencediagrams. Sequcnce diagrams arc used to specify scenarios as
sequencesof messagespassing betwcen objects. A sequence diagram represents
an interaction - a sct of communications among objects arranged visually in time
order. They can exist in a descriptor form (describing all possible scenarios)and
in an instance form (describing onc actual scenario). In thc paper wc deal with
an instancc form only.</p>
      <p>Scquencediagrams have some practical limitations. Neverthclcss,they are used
at vcry early stage of softwarc development for rapid but usually partial
specification of systern's bchaviour. For devclopersthe most important factor should
be quick validation of systetn's behaviour defined by a given set of
sequencediagrams. Scquencc diagrams still have an informal scmantics, therefore the most
effective way of such a validation is generabingsystem prototype and next its
intensive testing.</p>
      <p>
        The aim of the paper is prcsentation of an approach [
        <xref ref-type="bibr" rid="ref3">3</xref>
        ] to generating the system
prototype on the basis of a set of sequence diagrams. The paper is organized
as follows. Section 2 explains our definition of software systcm specification. In
Section 3 the algoribhm transforming such a specification into a state machine is
described. Scction 4 outlincs the structure of a programming system generating
prototypes, and describesgeneration of Java code. Thc last Section 5 evaluatcs
the obtained results and points out some future works.
      </p>
      <sec id="sec-1-1">
        <title>2 Systems specification</title>
      </sec>
      <sec id="sec-1-2">
        <title>Spccification of a system consistsof two parts I7lt8]</title>
        <p>The first one representing static aspect of the system, consists of two elements:
a classdiagram and an object diagram. The classdiagram reflects the set of
potential configuratioru of thc system - a sct of linked objects. The object diagraur
ref'ersto an initial configuration of the system.</p>
        <p>The second one represents dynamic aspect of the system and includes a set SD
of sequencediagrams. The set is partially ordered by relation (, which is dcfirred
as follows: for sd1,sd2 € SD, sd1 1sd2 mcans that interaction representedby
sd1 should occur beforc interaction rcpresentedby sd2.</p>
        <p>The dynamic part strould be consisteut with static part of the specification. It
entails that each scquencediagram should bc consistent with class diagram, i.c.
the objccts that appcar in the scquencediagram are to be elemcnts of an object
diagram bcing an instance of the class diagram. At least one sequcnce diagram
should act in accordanccwith the initial object diagram.</p>
        <p>Wc use UML 2.0 sequencediagrams [6] with the following restrictions:
- only asynchronous messagesare allowed,
- combined fragments only with three main operator typcs: alt, loop and
s t r i c t .</p>
        <p>Additionally, to rnaintain consistencyof the specificationthe following conditions
should be hold:
- objects belonging to the initial object diagram are not crcated on nonc of
scquencediagrams,
- othcr objects may be created only once via create operation and on one of
the sequencedia,grarrtso,therwise they a,reconsideredto be different objects,
- objects and their messagcscan not cause inconsistencies,e.g. they have to
keep thc time ordering resulting from objects creations and destructions
times,
- at lcast one guard condition in a combined fragmcnt should always be
fulfilled,
- conditions in ncstcd combined fragmcnts should not be contradictory.</p>
        <p>Spccification exa,mplc is presented in Fig. 1. The oval areas on thc figure
that reprcscnt some objects' activities will be used further to explain the idea of
scquence diagrams transformations.
7 5
l - , *
- l
l - - e</p>
        <p>I
l[.iil.. t- !u|!c9 rr9nt.3e!oioii'r.-lir :I ..</p>
        <p>l:'-:l*:*-:::"J
- -
tc=f .
o1--</p>
        <p>t l ' '
Deriving of system prototype consists of two phases: first a state machine is
crcatcd and next Java codc is generatcd. The transformation of a set of scquence
diagrams into a single state machine should prescrve determinism as well as
consistency. The transformation works in the following steps:
- F-oreach sequencediagram from the given specification and for each object,
on this diagram a state machine is gencrated. Thc machine represents a
fragmcnt of behaviour of thc classto which the object belongs.The machines
arc rcpresentcd in form of UML statecharts.
- Thc state machines gcnerated for the same class instances appearing on
different scquence diagrams are rnerged into a single, global state machinc.
The merging has to maintain transitions bctween statcs located on each of
compositc machinc. States of the whole system are reprcsented by states of
the global state machine.
- The sct of states of thc resulting state machine is minimized.</p>
        <p>The idea,of the first step of the tra,nsforma,tionis expla,inedfbr the
specification example from the previous section. Messageson the sequencediagram
which can change the object statc are recognized. It is assumed that only
receiving evcnts on the object lifeline may causc changing of its state. The areas
between marked messages (oval areas in Fig. 1.) are distinguished and states
from these arcas are derived.</p>
        <p>Incoming mcssagesbecome cvents triggering transitions between states, whereas
the outcoming messagesbecome actions cxecuted as entry actions of a particular
state. There are also other sequencc diagram elements that produce new states
like statc invariant (e-transition, i.c. internal transition, with state invariant
conditionr), and combined fragment (for object that begins the interaction within
Tt"t" t"""ttarrt condition - an interaction may be continued by thc object provided
if the state satisfiesthe invariantcondition
Statc mchine</p>
        <p>for olrject ,/A"
O</p>
        <p>I
a'----goI-'--'1)
t..;t;;;ii;i
.{corldftiorIn.'-.t-r.u-e...g.-n..l/f..tr..y.9-.r./.er--.4...-.,.2i*.....t-..\f{..-..1e..1.-ic.i.oi-l^.t1d;...i.t7..i.o."qn-:-lf'als.e:l
. " 1l e G . . /
[ ' . -"-t - \ ) ,//.t'
e-( \ t t
ti.,s a " i
_l
State lmchlne</p>
        <p>for object ,.C"
O</p>
        <p>I
r***5-d-\
i;;-f-fi-;-;-t;Tthe fragment c-transition with opcrand condition for other objects taking part
in thc combined fragment interaction new statcs triggercd by a proper events).
Statecharts created by thc algorithm possessonly simple states (simple - in sense
of UML statecharts), and therefbre they are called flat statecharts. Example of
state machines generated out of a given scenario from Fig. f . is shown in Fig. 2.</p>
        <p>Thc sccond step of the transformation merges state machines representing
behaviour of the same class. The transformation has to maintain partial ordering
between statc machines which results from sequcnce diagrams.</p>
        <p>The state machine for a given class is constructed as follows. First, the state
machine derived from a scenario which posscsscsobjects in their default states
(i.e. objects belonging to the initial object diagram) is taken as an initial state
machine. Second, othcr state machines are attachcd to the initial one. The
synthcsis proceeds as follows. At the beginning equivalence betwccn initial states of
the initial state machine and the joining state machine is examined.
If state machines can not bc joined by their initial statcs system looks for other
states in thc initial state machine that arc similar to the initial state of the
mcrgcd machine. If there are two cquivalent states2 and joining thcm will not
cause indetcrminist situation a synthcsis decision can be taken.</p>
        <p>Howcvcr, a situation whcn no merging state has bccn found might occur. In
such a casc a new transition betwccn the initial state of the initial state
machine and thc initial state of the merging state machine is addcd and marked
as )-transition3. This sort of transition can be cxccuted if no other transitions
are triggered and user will decide to continue the prototype execution with the
)-transition path. Two state machincs merging procedures of aforementioned
description are shown on simple examples in Fig. 3.
2 states described by equal attributes valucs of the corresponding class and equal set
of executirrg actions
" )-transition - transitiorr triggered only by the user decision about execution path
no othcr transitions are possiblc
l'i1
M2</p>
        <p>. e l - .sr , e ?
1..,r.T;--i
hi s0''-'C-l-&gt;i t ."--s^-_'\I: , l--|a-al'
7 7
c)</p>
        <p>|i]1UId?
ti4lU|'1?
f'll'l_l-f-.-'g-rI - -5,-1 t--e.{r a*, ',.....\et z ? z</p>
        <p>S0 l--&gt;iS''1S0-'j \
,i..iir)-i e1'\;-l:_:q,'
fti1U|'42</p>
        <p>*l''l sr .5
f-'i s0.l</p>
        <p>-*l' el " - --',-.9!,
i t l-l-i--*'i-u,</p>
        <p>The third step of transformation is thc minimization process.State machines
generated fbr objects on the base of different sequence diagrarns may possess
similar states. Such states are derived from identical interactions which wcre
located on different sequencediagrams. For that reason applying the concept
of iritera,ction use is recornmended.When creating system specification sirnilar.
interactions can be dcsigned on a separate scquenccdiagram. Synthesis proccss
docs not dcal with removing similar states. To improve the state machinc
efficiency rcdundant statcs should be removed but still maintaing the statc machinc
deterministic.
4</p>
      </sec>
      <sec id="sec-1-3">
        <title>Code generation and system design</title>
        <p>Codc generation out of statechart diagrams is based on the following schema:
- state is transformcd to a class wherc its behaviour consists of methods
derived from actions that state activity consists of,
- cvents and rcspectivc actions are transformed into method calls,
- for each class a statc variable indicating current state of its instances is
implemcnted; assignments of that statc variable corrcspond to transitions
from a statc machine,
- transitions conditions are convertcd into if-else statemcnts in gcneratcd event
methods, etc.</p>
        <p>
          Gathering of a bchaviour associated with a single state and its encapsulation in
one class is an idea taken from state design pattern [
          <xref ref-type="bibr" rid="ref5">5</xref>
          ] of which created system
makes use. It gives flexibility while performing some changes in specification
(st,at,esact,ivities)which result,sin code modifications. State dcsign patt,ern also
provides the architccture of Java classcs.
        </p>
        <p>UML state machines and Java programming language are basedon different
concepts. For that reason code gcneration is not an casy, straightforward mapping
of statc machine elements into thc codc. Howcver, object-oriented programming
and dcsign patterns enable gencration the code skeletonof executableprototype.
. sta!.9- . - ,,c.).rsln-te-x!t3!c-oent-e.".ti................................</p>
        <p>|: + ab.s..tract .v:olid entry(): l</p>
        <p>Ir I... . . . . . . . . . 1 . . . . . . . . .
t,st o_ - . - . . , I t - - 5- -i*-------' -- ---- 1-ll S i ' . - . 1 - . _ ,t i
_s-aIIIItLl*"+lisuvoooiiod':ee;rn(t)r:yO: iII |l|I|t"."r.-.s-vv-"too--tii,dd)d-:ee:4n- 90tr;1y1Oi. IIlI| l *i|tfIs-:-+.t---vv'*-Do-t1-r-)i-1dd'--:ee-:-7no--0t,-r:!y1--0--,."- -' ,lii: ||It1l.s++.l..2vvs.r.oo2..ii(.dd).;.ee..ng.r.(.ri.y:.0..t.......JIII....lii..+..vso3id0;entry(j
I
l
Testing condition in if-else statement is derivcd from a transition condition.
If satisfied the transition is executed, otherwisc an exception arises.</p>
        <p>On the basis of above mcntioned code generation and transformations rules,
systcm for prototypes automatic gcneration was created[S].It gets as an input
system specification and produces executablc Java code a^san output.
Functioning of the system described by UML activity diagram is presented in Fig. 5.
Each action from the activity diagram corresponds to a system modulc. These
modulcs work in a cascadc each of which taking as its input the output of the
previous module demonstrates the data flow on demonstrated acbivity diagram.
The system includes also a graphical user interface for sequencc diagrams
creating and cditing.
iad Systdan
worktlow
\ iiI/tdxsl!MaqgLu_r.o-nm,cr,r.s_.hrliriollhta/- I
All the neccssary data present during its transformation process is storcd in XMI
format. This enablcs exchanging the specification information with other UML
modclline tools.</p>
        <p>D</p>
      </sec>
    </sec>
    <sec id="sec-2">
      <title>Summarv</title>
      <p>Thc main motivation for automatic prototype generation is constructing a
system that supports developing proccss in software. First of all, cxecutablc
prototvpe enables validal,ion of a specificat,ionon a preliminary st;ageof the project.
Additionally, it provides the first vision of the developedsystern that can bc
further expanded and modified. It can also help project managers in project time
estimations.</p>
      <p>The systetr presented in the paper was tested by a set of simple specification
examples. It appears that current version of the system may be effectively used
onlv for non-complex specifical,ions.This is not causcd bv the transformat,ion
algorithm that may cope with the system complexity but by clarity of generatcd
codc skeleton. The skeletons in prcsent forms are not easy for extension or
modification as their stmcture reflccts final, rninirnally intcgrated state machine but
thcre is not clear tracing to sequence diagrams or component state machines
machines rcpresenting individual classes.Solution of this discrepancy seemsto
be possible by another structuring of state machine intergration.</p>
      <p>
        In addition it seems that within future works thc system may be cnhanccd by
new functionalities. Hcre arc cxamplcs of issuesworth to be considercd:
- Providing systern input not only with behavioural specification but also wittr
prototype structurc skeleton. Applied in created system state pattern for
structuralizing the implementation is clear to understand but lack of readable
class structure leads to illegibility of gencrated code. Providing the systcm
with additional information about prototype architecturc can facilitate its
furthcr expansion or rrrodification.
- Such systcm should havc a testing module which aftcr generation of the
final state machine will test its correctnessregarding all the execution paths
located on the scenarios provided as system input. On thc basis of that
module Java unit testing proccdures can be created in order to ensure that
generating based on statc machines code executes properly as designed on
sequence diagrams.
- Thc idea of expanding the system with gencrating graphical user interfacc
can be taken into account. In [
        <xref ref-type="bibr" rid="ref1 ref10">1</xref>
        ] exists an approach of describing GUI by
sequcnce diagrams. That work shows the power of UML sequence diagrams
in describing systems complete specificaLions.
- Other idea is taking into consideration synchronous messagesin the system
specification. This approach allows only asynchronousmessageswirich uncler
certain assumptions facilitates thc algorithm of constructing state machines.
Objects synchronization is not necessary assuming that all objects are in
proper states to receive messagesfrom other objects (cspecially important
when entering combined fragments).
'Ihere are also other mebhods that use sequencediagrams fbr specification of
devcloped systcms. Within them construction of state machine and further code
generation often rely either on specification of additional assumptions or on a
dialog with thc system uscr providing ad hoc decisions. Such complctc system
(SCtrD) is prcsented in [
        <xref ref-type="bibr" rid="ref2">2</xref>
        ]. Morcover, to facilitate thc process ccrtain notation
bcsides thc UML standard is frequently used.
      </p>
      <p>
        Whittlc and Schumann in their work [
        <xref ref-type="bibr" rid="ref9">9</xref>
        ] make the most of OCL for messages
pre- aud post-conditions which makes thc specification creation process rnuch
morc intricatc. An algcbraic approach prcscnted by Ziadi, Helouct and Jezcquel
in [10] cxpects that not only particular scenarios are dcscribed, but also one
scquence diagram that collects and shows the connections between all other
scenarios provided. In fact the final state machine is transformed from one sequence
diagram. This is again the kind of user limitation to be applicd when prcparing
system specifica,tion.Arrothcr statechart gencra,tionbasing on sequencediagrams
is presentcd by Makinen and Systa in MAS project [a]. This approach proposcs
intcraction with user in accepting or rcjecting generated state machines.
One of the aims of this work was making the system as self-reliant as possible
which is to effect in limiting the system interaction with the user to the
minimum, at the same timc being in full compliance with the UML 2.0 notation
standard.
      </p>
    </sec>
  </body>
  <back>
    <ref-list>
      <ref id="ref1">
        <mixed-citation>
          1.
          <string-name>
            <given-names>P.</given-names>
            <surname>Biecek</surname>
          </string-name>
          and
          <string-name>
            <given-names>Z.</given-names>
            <surname>Htnar</surname>
          </string-name>
          .
          <article-title>Graphical user interface and sequencc diagrarns in prototypc gerreration</article-title>
          . In Z. Hrzar and
          <string-name>
            <surname>Z</surname>
          </string-name>
          . Maztr, editors,
          <source>Problemy i ,metody inynieri.i. opr-ogT'arrlo'wanzaW. NT</source>
          ,
          <year>2003</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref2">
        <mixed-citation>
          2.
          <string-name>
            <given-names>K.</given-names>
            <surname>Koskirnies</surname>
          </string-name>
          , T. Md,nnisto, T. Systd, and J. T\omi. SCED:
          <article-title>A tool for dynamic rnodclling of object systcms</article-title>
          .
          <source>Technical Rcport 4-1996-4</source>
          ,
          <year>1996</year>
          . Available frorn:
          <source>citeseer'i.st.psu.edu/koskimicsg6sced.html.</source>
        </mixed-citation>
      </ref>
      <ref id="ref3">
        <mixed-citation>
          3.
          <string-name>
            <given-names>G.</given-names>
            <surname>Loniewski</surname>
          </string-name>
          .
          <article-title>State machirre prototype gcneration on the basis of urrrl 2.0 scquence diagrarns</article-title>
          .
          <source>Master's thcsis, Wroclaw Univcrsity of Techrrology</source>
          , Poland,
          <year>September 2006</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref4">
        <mixed-citation>
          4.
          <string-name>
            <given-names>E.</given-names>
            <surname>Makinen</surname>
          </string-name>
          and
          <string-name>
            <given-names>T.</given-names>
            <surname>Systa</surname>
          </string-name>
          .
          <article-title>Mas - an interactivc synthesizcr to support behavioral nrodcling in uml</article-title>
          .
          <source>In 23rd Internat'iortal Conference on Software Engineering (ICSE'}I)</source>
          , pages
          <fpage>0</fpage>
          -
          <lpage>15</lpage>
          ,
          <year>2001</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref5">
        <mixed-citation>
          5.
          <string-name>
            <given-names>L A.</given-names>
            <surname>Niaz</surname>
          </string-name>
          and
          <string-name>
            <given-names>J.</given-names>
            <surname>Tanaka</surname>
          </string-name>
          . Mapping uml statccharts to java code,
          <year>2004</year>
          . Available fronr: citcseer.
          <source>ist.psu. eduI 635242</source>
          .
          <year>htm1</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref6">
        <mixed-citation>
          o .
          <source>object Managcment Group. UML 2</source>
          .
          <article-title>0 oMG STteci,li</article-title>
          ,cati,
          <year>on2</year>
          ,
          <fpage>0</fpage>
          ,0b. Available from: www. omg. org/technology/documents/formal/uml. htm.
        </mixed-citation>
      </ref>
      <ref id="ref7">
        <mixed-citation>
          7
          <string-name>
            <given-names>T.</given-names>
            <surname>Pcnder</surname>
          </string-name>
          .
          <source>UML Bible</source>
          . John Wiley &amp; Sons,
          <year>2003</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref8">
        <mixed-citation>
          8 .
          <string-name>
            <given-names>P.</given-names>
            <surname>Roques</surname>
          </string-name>
          .
          <source>UML i.n Practice</source>
          .
          <source>John Wilcy &amp; Sons</source>
          ,
          <year>2005</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref9">
        <mixed-citation>
          9 .
          <string-name>
            <given-names>J.</given-names>
            <surname>Whittlc</surname>
          </string-name>
          and
          <string-name>
            <given-names>J.</given-names>
            <surname>Schumann</surname>
          </string-name>
          .
          <article-title>Gencrating statechart designs from scenarios</article-title>
          .
          <source>In Internati,onul Conference on Software Eng'ineering, pages 3r4 828</source>
          ,
          <year>2000</year>
          . Availablc from: citcseer.ist.psu.edu/whittle0Ogenerating.lrtrnl.
        </mixed-citation>
      </ref>
      <ref id="ref10">
        <mixed-citation>
          1 0 .
          <string-name>
            <given-names>T.</given-names>
            <surname>Ziadi</surname>
          </string-name>
          ,
          <string-name>
            <given-names>L.</given-names>
            <surname>Hclouet</surname>
          </string-name>
          , and J.
          <string-name>
            <surname>-M. Jezequel</surname>
          </string-name>
          .
          <article-title>Revisiting statechart synthcsis with an algebraic approach. rn 26th Internat'iono</article-title>
          ,l Conference on Software E,
          <string-name>
            <surname>ngineering</surname>
            <given-names>ICSE</given-names>
          </string-name>
          0l), Edi,nburgh, (JK, pagc
          <volume>242251</volume>
          ,
          <year>2004</year>
          .
        </mixed-citation>
      </ref>
    </ref-list>
  </back>
</article>