Synthesizing UML Concurrent Protocol Entities Tool

Jehad Al Dallal and AmroKhattab

April 2012

Introduction

The purpose of this program to implement a UML-based synthesismethod that automatically derives protocol specifications from a service specification, where both the service and the protocol specifications are modeled by UML state machines, as described in the paper. First the user will draw the UML state machine diagram using the UML diagram Tool. The tool should output two XML files representing the UML diagram. Then, the java program will take those XML files as input and follow the steps discussed in the paper to produce the new UML diagrams as XML files. Finally, the user may open the new XML files generated by the program to see the result UML diagram. The following figure shows the high-level design of the whole process.

Used Tools

1-Java JDK:

2-Eclipse IDE for Java Developer 3.7.1 :

3-UML2 Tools plugin 0.10.0:

Installation Steps

First install Java jdk and the Eclipse IDE. Then, install the UML2 Tools plugin as indicated in the following steps:

1-

In the Eclipse IDE go to: Help -> Install New software

2-

Click on "Add" button

3-

Click on "Archive" and navigate to the zip file downloaded.

4-

Choose the" UML2 Tools Diagramming " item

5-

UML Diagram Tool Usage:

1-You have to create a java project, or you may open a previously created project.

2-Select New->Other->UML2.1 Diagrams -> State Machine Diagram

3-Select Next, then select the project name mentioned in step 1, and type a file name that will contain the diagram model.

4-Select Next, then again select the project name, and type the file name that will contain the domain model.

5-Press Finish.

6-To add a diagram, make sure you open the Palette window, from Window->Show View -> Palette.

7-Just select the proper diagram tool from the palette and add it to the state machine.

8-Once you add a diagram you could change its properties from the Properties Window. The most important property is name.

9-Save the file.

10-If you want to open the diagram file, you have to open the file with extension .umlstm.

UML File Structure:

When a diagram is created two files are generated. Both files contain xml code. The first file with extension .uml contains the main UML shapes in the diagram. The second file with extension .umlstm contains the size and coordinated of the UML shapes of the diagram. The UML shapes are written as XML tags. For example the following simple state UML diagram:

The first file contains the xml:

<?xml version="1.0" encoding="UTF-8"?>

<uml:Packagexmi:version="2.1" xmlns:xmi=" xmlns:uml=" xmi:id="_Mz7t4HZXEeGz3b24vpm9Qg">

<elementImportxmi:id="_M0gVoHZXEeGz3b24vpm9Qg">

<importedElementxmi:type="uml:PrimitiveType" href="pathmap://UML_LIBRARIES/UMLPrimitiveTypes.library.uml#Boolean"/>

</elementImport>

<elementImportxmi:id="_M0vmMHZXEeGz3b24vpm9Qg">

<importedElementxmi:type="uml:PrimitiveType" href="pathmap://UML_LIBRARIES/UMLPrimitiveTypes.library.uml#String"/>

</elementImport>

<elementImportxmi:id="_M0vmMXZXEeGz3b24vpm9Qg">

<importedElementxmi:type="uml:PrimitiveType" href="pathmap://UML_LIBRARIES/UMLPrimitiveTypes.library.uml#UnlimitedNatural"/>

</elementImport>

<elementImportxmi:id="_M0vmMnZXEeGz3b24vpm9Qg">

<importedElementxmi:type="uml:PrimitiveType" href="pathmap://UML_LIBRARIES/UMLPrimitiveTypes.library.uml#Integer"/>

</elementImport>

<packagedElementxmi:type="uml:StateMachine" xmi:id="_OFnYMHZXEeGz3b24vpm9Qg" name="StateMachine">

<region xmi:id="_OGPDQHZXEeGz3b24vpm9Qg" name="Region">

<subvertexxmi:type="uml:State" xmi:id="_Pm3IgHZXEeGz3b24vpm9Qg" name="state0"/>

</region>

</packagedElement>

</uml:Package>

Look at the last XML tag packagedElement:

<packagedElementxmi:type="uml:StateMachine" xmi:id="_OFnYMHZXEeGz3b24vpm9Qg" name="StateMachine">

<region xmi:id="_OGPDQHZXEeGz3b24vpm9Qg" name="Region">

<subvertexxmi:type="uml:State" xmi:id="_Pm3IgHZXEeGz3b24vpm9Qg" name="state0"/>

</region>

</packagedElement>

It contains the xml tag subvertex with attribute xmi:type with tells that this is a state, and attribute name. Also note that each xml tag has an xmi:id attribute that uniquely identifies it.

The second file contains:

<?xml version="1.0" encoding="UTF-8"?>

<notation:Diagramxmi:version="2.0" xmlns:xmi=" xmlns:notation=" xmlns:uml=" xmi:id="_M0wNQHZXEeGz3b24vpm9Qg" type="UMLStateMachine" name="simple.umlstm" measurementUnit="Pixel">

<children xmi:type="notation:Shape" xmi:id="_OGlokHZXEeGz3b24vpm9Qg" type="2005" fontName="Segoe UI">

<children xmi:type="notation:DecorationNode" xmi:id="_OGmPoHZXEeGz3b24vpm9Qg" type="5011"/>

<children xmi:type="notation:DecorationNode" xmi:id="_OGmPoXZXEeGz3b24vpm9Qg" type="5012"/>

<children xmi:type="notation:Shape" xmi:id="_OGpS8HZXEeGz3b24vpm9Qg" type="3013" fontName="Segoe UI">

<children xmi:type="notation:DecorationNode" xmi:id="_OGp6AHZXEeGz3b24vpm9Qg" type="5027"/>

<children xmi:type="notation:DecorationNode" xmi:id="_OGp6AXZXEeGz3b24vpm9Qg" type="7004">

<children xmi:type="notation:Shape" xmi:id="_PnaiIHZXEeGz3b24vpm9Qg" type="3001" fontName="Segoe UI">

<children xmi:type="notation:DecorationNode" xmi:id="_PnbJMHZXEeGz3b24vpm9Qg" type="5001"/>

<children xmi:type="notation:DecorationNode" xmi:id="_PnbJMXZXEeGz3b24vpm9Qg" type="5015"/>

<children xmi:type="notation:BasicCompartment" xmi:id="_PnbJMnZXEeGz3b24vpm9Qg" type="7005">

<styles xmi:type="notation:TitleStyle" xmi:id="_PnbJM3ZXEeGz3b24vpm9Qg" showTitle="true"/>

<styles xmi:type="notation:SortingStyle" xmi:id="_PnbJNHZXEeGz3b24vpm9Qg"/>

<styles xmi:type="notation:FilteringStyle" xmi:id="_PnbJNXZXEeGz3b24vpm9Qg"/>

</children>

<element xmi:type="uml:State" href="simple.uml#_Pm3IgHZXEeGz3b24vpm9Qg"/>

<layoutConstraintxmi:type="notation:Bounds" xmi:id="_PnaiIXZXEeGz3b24vpm9Qg" x="260" y="44"/>

</children>

</children>

<element xmi:type="uml:Region" href="simple.uml#_OGPDQHZXEeGz3b24vpm9Qg"/>

<layoutConstraintxmi:type="notation:Bounds" xmi:id="_OGpS8XZXEeGz3b24vpm9Qg"/>

</children>

<element xmi:type="uml:StateMachine" href="simple.uml#_OFnYMHZXEeGz3b24vpm9Qg"/>

<layoutConstraintxmi:type="notation:Bounds" xmi:id="_OGlokXZXEeGz3b24vpm9Qg" x="221" y="120"/>

</children>

<styles xmi:type="notation:DiagramStyle" xmi:id="_M0wNQXZXEeGz3b24vpm9Qg"/>

<element xmi:type="uml:Package" href="simple.uml#_Mz7t4HZXEeGz3b24vpm9Qg"/>

</notation:Diagram>

You will notice that the element xml tag is referring to the first file, with xmi:id attribute used there:

<element xmi:type="uml:State" href="simple.uml#_Pm3IgHZXEeGz3b24vpm9Qg"/>

Also, there is another xml tag to specify the coordinates of the shape, like:

<layoutConstraintxmi:type="notation:Bounds" xmi:id="_OGlokXZXEeGz3b24vpm9Qg" x="221" y="120"/>

Java DOM

Java was the language used to process the UML state machine diagrams. Since the UML state machine diagrams are saved in xml format, Java has an API interface for processing such formats called the Document Object Model parsing interface or DOM interface.This is based on the specification introduced by w3c. The main idea is that it parses an entire XML document and constructs a complete in-memory representation of the document using the classes modeling the concepts found in the Document Object Model(DOM) Level 2 Core Specification.

The DOM parser is called a DocumentBuilder, as it builds an in-memory Documentrepresentation. The javax.xml.parsers.DocumentBuilder is created by the javax.xml.parsers.DocumentBuilderFactory. The DocumentBuilder creates an org.w3c.dom.Document instance, which is a tree structure containing nodes in the XML Document. Each tree node in the structure implements the org.w3c.dom.Node interface. There are many different types of tree nodes, representing the type of data found in an XML document. The most important node types are:

element nodes that may have attributes

So, the Java program will search the element nodes and return an elementList object, which represents an array of all element nodes queried in the xml DOM tree. Then the program could extract the node attributes for specific values.

Paper Algorithm Implementation

Let us take the example given in the paper. First, the state machine is drawn manually. The following is the result of the drawing:

The following assumptions were used:

1-Do not put UML components with empty “name” attribute values. Best to put 3 spaces instead.

2-The service was encoded at the “name” attribute of the transition.

3-The ↑ arrow is replaced by ^ and ↓ arrow is replaced by _ , and ε is replaced by EPS

4-SAP ID is restricted between 1-9

5-No ε-cycles

6-Reduction techniques were skipped

Second, run the java program. You have to make sure the paths of the two files are correct in the source code, compile and run the Java program. Next, the program will follow the steps of state machine conversion. The java program will build the DOM tree for the xml file, and apply the steps of the algorithm.

Step 1: Constructing PR-SPECs

A new file is generatedfor each SAP that contains the PR-SPEC. The file name will be the same input file appended with “1” for step1, and i for the SAP value. Each SAP will also be associated with its own copy of DOM tree. The user has to open the diagram manually to see the UML state machine graphically. These were the resulted UML diagrams:

SAP1:

SAP2:

SAP3

Step 2: Applying transition synthesis rules

The four rules are applied on each DOM tree independently, and new DOM trees are generated for each SAP. Also uml files are generated after applying the rules. The file name will be the same input file appended with “2” for step2, and i for the SAP value. These were the resulted UML diagrams:

SAP1:

SAP2:

SAP3:

Step 3: Removing -transitions

At this step the program search the DOM tree for the node elements with name attribute EPS. Then, it removes the target state that the transition is going to, and replaces it with all the next target states. Again new files are generated with each SAP. Take a look on the new diagrams:

SAP1

SAP2:

SAP3:

Steps 4 and 5: Remodeling composite states and applying optimization techniques

This is the most difficult part, where you have to replace the regions with new composite state. The idea was to make template of the composite state as shown:

Then use the xml code generated to replace the original regions. Each time the template xml code is duplicated you have to regenerate new xmi:id’s for the xml element nodes. But the challenging part is changing the coordinates of the shapes, and resizing the shapes. Till now this step was done manually and not fully automated.

The final UML diagram should look like this:

There is another example of the call establishment service of the H.323 standard. First the S-SPEC UML state machine diagram:

The generated UML state machine diagrams generated by the java program representing the synthesized PE-SPECs are the following:

SAP1:

SAP2:

SAP3:

Program Specification:

The java program is added to the same project created for the UML plugin. So the java class will be in the same directory as the xml files. The program is around 850 lines including the comments and debugging output. The java program includes two classes: iset and umltool.

iset class:

The iset class implements the set of integers main operations. Here is a look on the class methods:

It contains the attribute “set” which is the internal representation of the set inside the class. Also, it contains the following methods:

  • length: returns number of elements in the set.
  • is_empty: test whether the set is empty or not.
  • insert: takes an integer number as input, to be inserted in the set.
  • remove: takes an integer number as input, to be removed from the set.
  • member: takes an integer number as input, to be tested as member in the set.
  • union: takes another set as input, and returns their union.
  • intersection: takes another set as input, and returns their intersection.
  • differ: takes another set as input, and returns their difference.
  • str_set: takes another set as input, and returns the set members as a string.

Class umtool:

Take a look on the methods of the umltool class:

The methods are:

  • num_SAP: takes the list of xml transition nodes of the uml diagram as input, and returns number of SAPS available.
  • build_pr_spec: For input it takes the SAP number i, and the list of xml transition nodes of the uml diagram. Then, it builds the PR_SPEC for the current i SAP by modifying the input list of xml transition nodes.
  • source: takes the transition xml node, and the list of xml state nodes of the uml diagram as input, and returns the source state xml node.
  • target: takes the transition xml node, and the list of xml state nodes of the uml diagram as input, and returns the source state xml node.
  • is_final_state: takes the state xml node as input, and test whether it is final state or not.
  • cs_substate: takes the state xml node as input, and test whether it is substate in some composite state or not.
  • is_cs: takes the state xml node as input, and test whether it is a composite state or not.
  • is_stable_state: takes the state xml node as input, and test whether it is a stable state or not.
  • out: For input it takes the state xml node, the list of xml transition nodes of the uml diagram, and the list of xml state nodes of the uml diagram. Then, it returns the output set x of OUT(s).
  • outr: takes the state xml node, and the list of xml nodes of the uml diagram as input, and returns the output set x of OUT(r).
  • inc: takes the state xml node, and the list of xml nodes of the uml diagram as input, and returns the output set x of InC(s).
  • rule1,rule2,rule3,rule4: Implements the rules of the paper. Each take for input: SAP number i, the list of xml state nodes of the uml diagram, the array of xml nodes of the uml of PR_SPEC and PPE_SPEC. At the beginning PPE_SPEC is an input copy of PR_SPEC, then the applying the rule will modify on the PPE_SPEC.
  • update_spec: For input it takes, and the list of xml nodes of the uml diagram, the old filename, and new filename. Then, it just replaces the old string by the new string of the umlstm file.
  • remove_EPS: takes the list of xml nodes of the uml diagram as input, and removes the  transitions by modifying the list of xml nodes.
  • chng_id: takes the xml node of the uml diagram as input, and generate a new id for it.
  • step4: It takes for input the xml nodes of the uml diagram of both .uml and umlstm file, and both for the template uml and umlstm files. Then, it applies steps 4 and 5. This one is still not fully working.

Conclusion

This research development work is a direct implementation of the paper “Synthesizing Distributed Protocol Specifications from a UML State Machine Modeled Service Specification”. It used a UML diagram tool to draw the state machine models, then run a java program to apply the steps mentioned in the paper. At the end a UML diagram should represent the synthesized modeled service specification. The main challenge was to interpret the XML tags and attributes to program them. The real obstacle is produce the UML components positions at run-time. In the future one could look for simpler UML file format to give better results.

1