Pauware presentation PauWare is a tool enabling to execute UML state machines in plain Java programs. It is composed of two elements: ● An API defining a set of classes for building/programming a UML state machine associated with business operations ● An execution engine that carries on events and executes the business operations Pauware can be used with any Java platform. There exists a version for Java ME and Java EE, both compatible with Java SE, as well as a boilerplate code for Android or the NAO robot. Even if there exists a Pauware plugin for Netbeans, programing with the Pauware API can be done with any Java IDE as it requires only to import a JAR file. This file has a size of only 100 kB. This document makes a quick presentation of Pauware and shows its main features through concrete examples. Guidelines Programming with Pauware requires to think your code in a different way as the application execution will be event-driven. It is thus well-suited for reactive programming. The ultimate goal of an application is to execute business operations. The behavior of the application consists in defining when and why calling such business operations at a given point in time during the execution of the application. With Pauware, all this behavior is defined through a state machine and business operations are associated with states and transitions. To make the application evolving, i.e. executing it, there is a single thing to do: asking the state machine to process an event. This is simply done in this way: stateMachine. run_to_completion ( "myEventName" ); If, starting from the current active states, there exists transitions associated with this event, then the Pauware engine triggers the transitions and executes the business operations associated with the transitions and the target states. This way of programming has some consequences: ● In your code, you never directly call business operations: they will be called by the Pauware execution engine. ● It is not possible to get the returned value of a business operation. You have to modify the content of a shared object to get the result of the operation. ● If your business operations are taking parameters, there is a special (and not very intuitive) way to specify them when calling business operations. 1
Apart from these points, there is nothing particular to respect or follow for implementing your application with Pauware: no naming convention, no interface to implement or class to extend. You can organize your code and your classes as you want. That is why Pauware is considered as an API rather than a framework. Creation of the state machine Java methods Business operations or guards of transitions are implemented in standard Java methods. The Pauware engine will call them through reflection. The way to associate methods to states or transitions then follows the way the reflection mechanism of Java is running. It requires to set 3 values: ● The object on which the method has to be called ● The name of the method (a String value) ● The set of parameters under the form of an object array (Object[]) For instance, if you have a method with the signature public void doSomething ( int val) and you want that this method to be the activity of a state, you need to write: myState. doActivity (myObject, "doSomething" , new Object[]{ 45 }); In the following, it will be explained how to manage changing parameters. States The Pauware API enables to define states that can be primitive or composite, have parallel regions and history states (deep or shallow). Three business operations can be associated with a state: as entry, as its activity and as exit. The above state machine defines the behavior of a microwave oven. The two composite states specify if the door of the oven is open or closed. Here are some lines of code for building a part of the hierarchy of states: // The state off (of open) executes the "stop" method and // is the input state of its composite offOpen = new Statechart( "Off" ); offOpen. set_entryAction (mwb, "stop" ); offOpen. inputState (); 2
// The closed state is a composite containing the off and // baking states,has a deep history pseudo state and is // the input state of its composite (the state machine) closed = offClosed. xor (baking). name ( "Closed" ); closed. deep_history (); closed. inputState (); A composite state is built with the “xor” operator between several states. The “and” operator will build parallel regions. Please note that here the business operations are called on an object named “mwb” and have no parameter so the argument for the set of objects is optional. Creating the global state machine is made in the same way: stateMachine = new Statechart_monitor (closed. xor (open), "Microwave" , true ); The last parameter “true” aks the Pauware engine to write on the console information on what has appenning when processing an event (what are the active states, which transition has been triggered…). Put a “false” value to not get execution information on the console. Transitions If creating a hierarchy of states is easy and straightforward, adding transitions is a bit more complex. It consists in calling the “fires” method on a state machine instance but there are 12 variants (overloads) of this method depending on the information on the transition. It can be a bit confusing for the beginners and you can for instance think that you have associated a business operation with a transition but actually it is processed as a guard. There are 3 mandatory elements to set: ● The source state of the transition ● The target state of the transition ● The name of the event associated with the transition Then, there are optional elements: ● A guard ● A business operation Guards and business operations are implemented with standard Java methods. Methods for guards must return a boolean. The methods are set by: ● The object on which it will be called ● The name of the method ● An optional set of parameters (array of Object) Here are for instance some lines for adding some transitions between states: // From closed to open for the "DoorOpen" event with call // of the "openDoor" method 3
More recommend