编辑: QQ215851406 2017-10-07

3 Textual Syntaxes Textual modeling has many advantages over editing models in graphics [7]. Most importantly, model storage, version control, compare and merge functionalities can be provided by o?-the-shelf, reliable tools. Text editors are more advanced and stable compared to currently available open source graphical model editors, and it is often faster to input text than graphics. The txtUML tool provides two textual syntaxes for modeling: C X txtUML: Standalone syntax designed to be short and clean. It is supported by an Xtext-based editor [18]. C JtxtUML: In this case, the model is a standard Java program, which uses the txtUML Java API. Therefore this is an embedded language in Java. The standalone syntax is easier to use, especially for users not familiar with Java. On the other hand, the Java syntax can be used in any Java development environment so that a project using this syntax will not depend on a new editor and a new language. The two syntactic variants are closely related: In fact, XtxtUML models are on-the-?y translated to JtxtUML models while they are edited in Eclipse. This is the basis for model execution. signal ButtonPress;

class Machine { initial Init;

state Off;

state On;

transition Initialize { from Init;

to Off;

} transition SwitchOn { from Off;

to On;

trigger ButtonPress;

} transition SwitchOff { from On;

to Off;

trigger ButtonPress;

} } class ButtonPress extends Signal {} class Machine extends ModelClass { class Init extends Initial {} class Off extends State {} class On extends State {} @From(Init.class) @To(Off.class) class Initialize extends Transition {} @From(Off.class) @To(On.class) @Trigger(ButtonPress.class) class SwitchOn extends Transition {} @From(On.class) @To(Off.class) @Trigger(ButtonPress.class) class SwitchOff extends Transition {} } Fig. 1. Two syntactic variants of the txtUML language (Left: Standalone syntax, Right: Embedded language in Java) Figure

1 shows an example model both in standalone and Java syntax. The model de?nes one signal (ButtonPress) which will trigger transitions in the state machine of the class Machine. Inside the class, its states and transitions are de?ned. For example, the ButtonPress signal triggers a transition from the O? state to the On state. The design of the two language variants follows a pattern: Kinds of the model elements are shown by keywords (signal, class, transition) in the standalone syntax, while the Java version uses inheritance from Signal, ModelClass and Transition. These classes are provided by the txtUML Java API. Properties of the transitions are expressed by Java annotations (e.g. @From) in Java, while attribute-like syntax with keywords (e.g. from) is used in the standalone version. The txtUML language covers a subset of UML. We summarize the supported elements below: C Component modeling: Interfaces containing signals;

ports;

connectors C Class modeling: Classes with attributes and operations;

simple binary asso- ciations;

compositions;

(single) inheritance C State modeling: Simple and composite states;

transitions triggered by signals;

guards;

choice states C Behavior modeling: Action code can be written in operations of classes, en- try and exit actions of states and e?ects of transitions. Supported base types are int, double, boolean and String with the usual arithmetic and logic ex- pressions, variables and assignment. Control structures (loops, branches), attribute access and operation calls are supported. UML-speci?c actions: creation and deletion of objects;

linkage and unlinkage via associations and connectors;

下载(注:源文件不在本站服务器,都将跳转到源网站下载)
备用下载
发帖评论
相关话题
发布一个新话题
大家都在看的话题