• No results found

A Simple Implementation of UML Sequence Diagram to Java Code Generation through XMI Representation

N/A
N/A
Protected

Academic year: 2020

Share "A Simple Implementation of UML Sequence Diagram to Java Code Generation through XMI Representation"

Copied!
5
0
0

Loading.... (view fulltext now)

Full text

(1)

International Journal of Emerging Technology and Advanced Engineering

Website: www.ijetae.com (ISSN 2250-2459,ISO 9001:2008 Certified Journal, Volume 3, Issue 12, December 2013)

A Simple Implementation of UML Sequence Diagram to Java

Code Generation through XMI Representation

George. T. Vadakkumcheril

1

, M. Mythily

2

, M. L.Valarmathi

3

1

Post Graduate Student, 2Assistant Professor, Department of CSE, Karunya Institute of Technology & Science, Coimbatore, India

3Associate Professor, Department of CSE, Govt. College of Technology, Coimbatore, India

Abstract—UML is widely used in the software

development, there consists of the designing and coding of the software. Designing phase is done with the help of the UML models, in which consists of the sequence diagrams, activity diagrams, usecase diagrams etc. Since the software development is time and human resource consuming, the reduction of consumption is done with the help of the code generation automatically without the coding in the development phase. This work mainly focus on the UML sequence diagram as the model and the transformation of UML to XMI is done with help of BOUML tool. The meta-elements are extracted from the XMI file with the help of the methods explained in the work. The output obtained will be the java files having the equivalent code of the sequence diagram.

KeywordsBOUML, Code Generation, Java, Sequence

Diagram, Superstructure Specification, UML, XMI

I. INTRODUCTION

Software engineering is the one which consists of design, development, operation, and maintenance of software, and the study of these approaches; that is what the application of the engineering to the software. Modern day programs are much large and complex. Further, maintainability of these programs is frequent. Unified Modeling Language (UML) [1]-[2], which is a visual modeling language used for the purpose of support of the modeling of different views of the software. That is the main reason why, it is widely used by the software practitioners.

Even though UML is being widely popular among the software practitioners, its potential in helping the software development activities is not fully known. One potential use of Sequence Diagram (SD) is code generation with which the human errors during manual translation of the SDs to equivalent code [3] can be avoided and also improve communication between design team and coding team [4] which results in reduction of coding effort [3]. Even if the different diagrams are used, each diagram has their own elements specification which may results the generated code be structural or behavioural in nature. So that, based on the UML diagrams used the code generated

II. OVERVIEW

In the field of the software development, there consists of the designing and also coding of the software, which is more or less time consuming based on the complexity of the project or the designing strategy. Coding of the software with respect to the designed component of the project is what happening in the current scenario, which may create the overhead in the development phase. Also this type of conversion of the design component to the corresponding code component is time and human resource consuming too. Consider the situation of software development there consists of the design and coding. Here the human resource will be divided among design and coding team, in which the coding will consume the larger amount of it. If the coding human resource can be reduced then explicitly the time consumption also gets reduced. So in order to achieve this the automatic code generation from design model diagrams is introduced. Thus the development phase is integrated with the design phase and coding for each of the application is reduced. UML diagrams are used for the designing of the software concept and the flow of the data and control in the software. UML has different versions, but mainly UML 1.x and UML 2.x. UML 2.x is used, since it supports the superstructure specification [5]. UML diagrams are broadly classified into two:

 Structure diagrams

 Behavior diagrams

The structure diagrams mainly focus on the static structural design of the system, so that they are used exclusively in documenting the software architectural design. Structure diagrams contain diagrams like class, component, deployment etc.

The Behavior diagrams are the diagrams which are having the dynamic structure, so that they are dynamic in nature and also it consists of diagrams like sequence, usecase, activity etc.

(2)

International Journal of Emerging Technology and Advanced Engineering

Website: www.ijetae.com (ISSN 2250-2459,ISO 9001:2008 Certified Journal, Volume 3, Issue 12, December 2013)

405 In which Sequence diagram describes an interaction by focusing on the sequence of messages that are exchanged, along with their corresponding occurrence specifications on the lifelines.

[image:2.612.392.489.135.257.2]

Here, in this work the code generation happens based on the sequence diagram, in which focuses on the message interchange between a numbers of lifelines. Each lifeline represent the participant in the interaction, here it is the object of the class. The message passed between the objects is the sequence flow of the program. Message can be defined as a named element, one specific kind of communication between lifelines of an interaction. Each message reflects either an operation call or sending and reception of a signal, so that message could be of actions like: synchronous call, asynchronous call and asynchronous signal [6].

Figure 1: Sequence diagram

[image:2.612.63.274.323.447.2]

Also each message specification have the sender and the receiver in which the sender will be calling or passing a message which is reside in the receiver side, which sends back the necessary message to the sender. In this sequence diagram, each message can be considered as the sequence flow from each of the class object in the timeline. The

Figure 1 shows a sample sequence diagram in which consists of two objects object A and object B. Message m1 and m2 are passed between the object A and B. Here object A is the sender of m1 and object B is the receiver of m1. Like that for m2 object B is the sender and object A is the receiver. The flow of the message shows the order of execution of the code. As in sample figure, the message m1 is happening before m2, so that the sequence flow is m1 after that m2.

Figure 2: Input-Output flow model

UML diagram itself is a model which has to be converted into a textual form. In order to do that XML Metadata Interchange (XMI) is used. XMI is a metadata representation of the model, which is used for the conversion of the model to text and wise versa. Figure 2

represents the Input Output flow model which shows the flow of data, that is the conversion of the sequence diagram to the corresponding XMI format and this XMI to the Generated Code. So, the UML sequence diagram will be the input to the system and the output will be the generated code.

XMI format will be the combination of the XML tags and the UML elements. Since the XMI representation of the UML sequence diagram is in the textual format the code generation process will be using this textual information for the extraction of the design model information. As the work [7], which describes the automatic code generation from sequence diagrams, they used the XMI file as the input to the code generation and output as java code. Here used the equivalent XMI format as the input for the generation of the java code.

III. IMPLEMENTATION METHODOLOGY

The UML sequence diagram is the input to the system, as the model itself is not textual format an intermediate representation of the diagram is needed. For this XMI format is used, which is having the metadata information of the design model. The XMI representation of the UML sequence diagram is generated with the help of a tool called BOUML [8], in which the XMI generated for java [9].

:object A :object B

m1

(3)

International Journal of Emerging Technology and Advanced Engineering

Website: www.ijetae.com (ISSN 2250-2459,ISO 9001:2008 Certified Journal, Volume 3, Issue 12, December 2013)

Since this tool have the capability of supporting UML 2.x version and also XMI exporting feature, it is choose for the UML modeling. Figure 3 shows a sample XMI file generated from the BOUML tool, in which consists of the tags like packed Element, ownedBehavior etc.

<?xml version="1.0" encoding="UTF-8"?> <xmi:XMI xmi:version="2.1"

xmlns:uml="http://schema.omg.org/spec/UML/2.1" xmlns:xmi= "http://schema.omg.org/spec/XMI/2.1"> <xmi:Documentation exporter="Bouml"

exporterVersion="1.14.1"/>

<uml:Model xmi:type="uml:Model" xmi:id="themodel" name="trail4">

<packagedElement xmi:type="uml:Package" xmi:id="BOUML_0x81_22" name ="trail4">

<packagedElement xmi:type="uml:Collaboration" xmi:id= "BOUML_COLLABORATION_0x1f412_12"

name="sequence">

<ownedBehavior xmi:type="uml:Interaction" xmi:id="BOUML_INTERACTION_0x1f412_12" name="sequence">

</ownedBehavior> </packagedElement>

<packagedElement xmi:type="uml:Class" name="A" xmi:id="BOUML_0x1f412_4" visibility="public"> </packagedElement>

<packagedElement xmi:type="uml:Class" name="B" xmi:id="BOUML_0x1f492_4" visibility="public"> </packagedElement>

</packagedElement> </uml:Model> </xmi:XMI>

Figure 3: Sample XMI code Implementation Steps:

1. UML sequence diagram is modeled in BOUML.

2. Export the XMI representation of the sequence diagram from the tool for java language.

3. Extract the metadata from the XMI file.

Implementation step 1 and 2 can be done with the help of the BOUML tool, which is available in the internet freely. But for the step 3, the following procedure has to follow.

Extracting the metadata from the XMI file is the key step in this paper. The XMI file contains the class information, its visibility and the methods and attributes. Each of the class has its own messages passed between the objects.

 The class name, methods and its visibility is extracted first. For this first the XMI file is opened for class extraction, from that ‗<packagedElement‘ tag is checking, if found get the property of that element ‗xmi:type= "uml:Class"‘, this have the field ‗name=‖ ‖‘, which give the class name and the ‗visibility=‖ ―‘, give the visibility of that class.

 Each class has their own operation and each operation have their own parameter. For extracting this, get inside the ‗xmi:type= "uml:Class"‘ tag, from their go to the ‗<ownedOperation‘ tag, which is having the ‗xmi:type="uml:Operation"‘ element, this element have the ‗name=‖ ‖‘ and ‗visbility=‖ ―‘ field, from this the operation name and visibility is found.

 Also for each operations there will be having the ‗<type‘ tag which contain the ‗xmi:type= "uml:Class"‘ element and ‗xmi:idref= "BOUML_ datatype_0"/>‘ field, this field have the datatype of each parameter, which is got from another tag

‗<packagedElement‘ having

‗xmi:type="uml:DataType"‘ as element. From this tag the ‗name=‖ ―‘ field is extracting, by checking the ‗xmi:id‘ of each parameter type with the ‗xmi:type="uml:DataType"‘. Thus the operation name, visbility, return type, parameter and its datatype is extracted. This is done for all the classes available in the XMI file.

 Now the sequence flow of the project is extracting.

For that from the ‗<packagedElement

xmi:type="uml:Class"‘ tag, the ‗xmi:id=‖ ‖‘ is

extracted and from the ‗<ownedAttribute

xmi:type="uml:Property"‘ tag, the ‗xmi:id=‖ ‖‘ is extracted if the xmi:id of previous tag is equal to the type in this tag. If xmi:id is got then, from the ‗<lifeline xmi:type="uml:Lifeline"‘ tag, the ‗xmi:id=‖ ‖‘ is extracted if the xmi:id of previous tag is equal to the ‗represents‘ in this tag. Again if xmi:id is got then,

from the ‗<fragment xmi:type=

"uml:MessageOccurrenceSpecification"‘ tag, the ‗xmi:id=‖ ‖‘ is extracted if the xmi:id of previous tag is equal to the ‗covered‘ in this tag.

(4)

International Journal of Emerging Technology and Advanced Engineering

Website: www.ijetae.com (ISSN 2250-2459,ISO 9001:2008 Certified Journal, Volume 3, Issue 12, December 2013)

407 The extraction process can be explained with a simple example of XMI file given below in Figure 4.

For the extraction of the class and its properties consider the below XMI code, in which consist of the ‗uml:Class‘, class name and its visibility.

<packagedElement xmi:type="uml:Class" name="A" xmi:id="BOUML_0x1f412_4" visibility="public">

Figure 4: Generated XMI file From this code, the class name is extracted from the

‗name=‖A‖‘, which is ‗A‘, like that the visibility is extracted from the visibility=‖public‖, as ‗public. This is how the class and visibility is extracted and the corresponding code generated is:

public class A {

}

The operations in the class can be extracted from the owned operation tag, which consists of the ‗uml:Operation‘ element. From this the operation name and visibility is extracted.

<ownedOperation xmi:type = "uml:Operation" name ="sum" xmi:id= "BOUML_0x1f412_2" visibility ="public" isAbstract="false"

The name=‖sum‖ is the operation name as ‘sum‘ and the visibility=‖public‖, as the public visibility. Like that the below code shows the parameter name and its data type.

<ownedParameter xmi:type= "uml:Parameter" name ="num1" xmi:id ="BOUML_op_param_1" direction ="in">

<type xmi:type= "uml:Class" xmi:idref= "BOUML_ datatype_1"/>

<packagedElement xmi:type= "uml:DataType" xmi:id ="BOUML_datatype_1" name="int"/>

From this code the parameter name is extracted from the name=‖num1‖, so that one parameter is ‗num1‘. Also the data type is extracted from the ―uml:DataType‖ tag in which the name represent the data type name as ‗int‘. So the corresponding code generated is:

public sum (int num1) {

}

Consider the following code in which the sequence flow is analyzing:

Code 1: <packagedElement xmi:type="uml:Class" name ="A" xmi:id="BOUML_0x1f412_4 visibility ="public">

(5)

International Journal of Emerging Technology and Advanced Engineering

Website: www.ijetae.com (ISSN 2250-2459,ISO 9001:2008 Certified Journal, Volume 3, Issue 12, December 2013)

Code 3: <lifeline xmi:type="uml:Lifeline" xmi:id= "BOUML_LIFELINE1_0x1f412_12" name= "" represents = "BOUML_COLLATTR1_0x1f412_1 2"/>

Code 4: <fragment xmi:type ="uml:MessageOccur rence

Specification" xmi:id= "BOUML_MSGOCCS PEC

SEND3_0x1f412_12" covered="BOUML_LIFE LINE1 _0x1f412_12"/>

Code 5: <message xmi:type="uml:Message" xmi:id ="BOUML_MSG3_0x1f412_12" name="minus" message Sort="synchCall" messageKind="complete" sendEvent= "BOUML_MSGO CCSPECSEND3 _0x1f412_12"/>

Here the code 1, which belongs to the class A, the xmi:id points to the code 2 type, thus obtained the xmi:id of the code 2. From this code 2, which point to another code, thus code 3 represents got matched. This code 3 xmi:id got match from the code 4 covered field. Thus the code 4 xmi:id is obtained, which is points to the code 5. From code 5 the corresponding message is extracted and also the message sender is that class. Thus the sequence flow of the message is obtained and code is generated based on the order of the flow of messages.

public class A {

public sum(int num1) {

} Sum(); }

Above code is the generated code for the given example of the XMI file, as explained above. The code generated is the simplex form, since the conditional and the looping statements are not considered as the input to the sequence diagram

.

IV. CONCLUSION

As the demand of the new software increase in the current field of software engineering, new technics and methods are needed for fulfilling the needs of the market. In order to make this possible in the case of design model, in which the models are converted to the corresponding code, the code generation approach is used. The work, deals with the generation of the code for the UML sequence diagram, with the help of the XMI file of the corresponding sequence diagram using the BOUML tool. Simple sequence flow can be extracted from the XMI file efficiently, but the conditional and looping statements are avoided. But these statements can be included into the sequence by complex programing methods with the help of this XMI file generated

.

REFERENCES

[1] Booch, G., Rumbaugh, J., Jacobson, I.: ‗Object-oriented analysis and design‘ (Addison-Wesley, 2002).

[2] Pilone, D., Pitman, N.: ‗UML 2.0 in a nutshell‘ (O‘Reilly, 2005). [3] Usman, M., Nadeem, A.: ‗Automatic generation of Java code from

UML diagrams using UJECTOR‘, Int. J. Softw. Eng. Appl., 2009, 3, (2), pp. 21–38.

[4] Jakimi, A., El Koutbi, M.: ‗An object-oriented approach to UML scenarios engineering and code generation‘, Int. J. Comput. Theory Eng., 2009, 1, (1), pp. 35–41.

[5] ‗http://www.omg.org/spec/uml/2.2/superstructure‘, 2 November 2013.

[6] ‗http://www.uml-diagrams.org/sequence-diagrams.html, 17 November 2013.

[7] Debasish Kundu1, Debasis Samanta, Rajib Mall.: ‗Automatic code generation from unified modeling language sequence diagrams‘, IET Softw., 2013, Vol. 7, Iss. 1, pp. 12–28.Brown, L. D., Hua, H., and Gao, C. 2003. A widget framework for augmented interaction in SCAPE.

[8] BOUML tool release 4.22.2 ‗http://www.bouml.fr/ index.html‘, 8 September 2013.

Figure

Figure 2: Input-Output flow model

References

Related documents

Third, we will show that even under the optimistic baseline scenario assumptions a purely parametric reform of pay-as-you-go systems will not suffice to balance

By using Zoom Away by Tim Wynne-Jones, the works of Michael Kusugak, The Inukshuk Book , the two stories about polar bears, and the Nunavut workbook, your students will know all

Our main idea consists in using a prediction algorithm applied to received signal strengths to estimate future values of the metrics in order to compensate the delay involved by

We added this question to the survey during the period of firm interviews, because firms often spontaneously gave this as a reason for why they engage in barter. The later

Congratulations to Lisa Rosenthal (advisor Sheri Levy) for being awarded a 2009 Society for the Psychological Study of Social Issues Grants-in-Aid Dissertation Award with

hypertension is a validated tool for the diagnosis and follow-up of patients. Baveno VI recommended the combination of transient elastography and platelet count for ruling out

It can be seen in figure 1 that data of three clays along with the flow paths of cement paste, 1:1 and 1:2 cement mortars can also be normalized by water content

In this study, we investigated the effect of thalidomide on the alveolar epithelial cell in the lung fibrosis induced by bleomycin in mice by morphometric