pyswarm Documentation (http://pyswarm.sourceforge.net/)

3.3.  pyswarm SDK

3.3.1. Standards Related to Model Driven Architecture
3.3.2. Generation of the Business Logic Components
3.3.3. Generation of Web User Interfaces
3.3.4. Generation of Native GUI Clients
3.3.5. More Integration

The so-called Model Driven Architecture (MDA) is a standardized model-driven development approach that uses business models notified in Unified Modeling Language (UML) to generate a platform specific implementation of a custom application.

The UML model is usually represented in the XML format XMI which is meant to ease interchange of model data between different tools - at least in theory. In practice many CASE tools do not support newer XMI versions like the most recent 2.1 or have differences in XMI formats of the same version. However, the situation has improved over the last years and is still getting better.

MDA, UML and XMI are vendor-independent standards of the Object Management Group OMG. The OMG covers additional software standards which are related to the topic of MDA.

The following example shows the differences between MDA's terms of Platform Independent Model (PIM) and Platform Specific Model (PSM) in the context of pyswarm. This example and the models therein of course are incomplete but should be sufficient to provide an overview of the differences and what pyswarm SDK is doing.

pyswarm can import a PIM which specifies a custom pyswarm application. Using an UML CASE tool this PIM could have been created by a modeler or developer, e.g. yourself.

Partial PIM of an pyswarm application.

Partial PIM of an pyswarm application.

The PIM defines two business classes in the application, Foo and Bar. Classes stereotyped as «pyswarm.entity» represent persistent business classes. A class in a logic component stereotyped as «pyswarm.zone» is also a business class but has some additional features (they are covered in other parts of the documentation). As you can see both classes have public attributes of the Text datatype.

Both classes are associated where the composition defines a life-time concept and ownership aspect, so each Bar object is owned by one Foo object while each Foo object may own multiple Bar objects (see 0..*). The names of each role in the association are unique in the component and should be meaningful. Deletion of a Foo object will cascade delete all its owned Bar objects.

Foo has also an operation (a business operation since it is defined in the PIM of the custom application) which will create a new object of the Bar, associate it with the self object of Foo and makes the self object the owner and zone object of the recently created Bar. The operation's stereotype and tag define that this operation is generated 100% automatically (no programming) and that it is used to create a new business object of the class defined as return-type. The parameters given in such an operation are related to the class of which a new object is going to be created.

Currently the PIM is notated in UML serialized as XMI file which then is imported by the pyswarm SDK. The SDK transforms the PIM into a PSM. The PSM represents the code that will be generated in the next step of generation. Below you see a simplified incomplete PSM how the generator would create one from the PIM example earlier.

[Note] Note

The PSM is only shown for information purpose. Please note that the SDK currently does not create an UML representation of the PSM. Indeed the generator directly writes the source code represented by the PSM to hard drive with-out saving the PSM. This is one reason why pyswarm SDK can be considered as a light-weight MDA, while some other MDA tools deliver the PSM which can be fine-tuned by the developer before it is finally generated as source code implementation.

Partial PSM of an pyswarm application.

Partial PSM of an pyswarm application.

In the upper left area you can see the two business classes that will be generated. The lower left area has collection-like classes that are generated by pyswarm SDK due to convenience. They represent collections of the corresponding business classes, global and association-specific. The right frame contains classes that are base-classes in the runtime environment of pyswarm. They are in the serve library package and has no custom features for any applications.

First let me describe the serve classes. Entity is the top base-class for all persistent business classes. It has some convenient features, e.g. EID and strEID methods to retrieve the entityID attribute value of any business object. Zone is sub-class of Entity and any zone plays a special role in its logic component - in our example this zone is the Foo class.

Now let us have a view on the generated business classes. The SDK added some operations: there are getter and setter methods for each attribute of the class, but also getter methods for each association of the class to retrieve the opposite elements whatever they are. As you know Bar's opposite role is FooOfBar which represents exactly one Foo object. So you can call on any Bar object the generated getFooOfBar method to retrieve the owning Foo object. Note that the returntype of the method is Foo. With setFooOfBar you can associate the Bar object to the Foo object given as parameter value.

The Foo class has the opposite association-role BarsOfFoo with the multiplicity 0..*, thus each Foo object may have no, one or many Bar objects associated. Since they can be many objects returned for convenience reasons pyswarm uses collection classes. In principal pyswarm adds one collection sub-class for each business class, representing a collection of business objects of this class. You can count all objects in the collections (or only objects filtered by classifiers and criteria) and you can get pages of all the objects ordered by a specific attribute, where you can define if you want to get one single page with all objects inside or page-wise with providing page size and page number. getPage does like count support classifiers and criteria to restrict the operation to a sub-set of the collection's objects.

[Note] Note

Note the automatically generated collection sub-class names: many Foo objects are Foos (a plural s is appended), many Country objects are Countries (trailing y become ies, and many Address objects are Addresses (trailing ss become sses). There are no lingual exceptions supported, e.g. in the case of Child the name Children would be lingually correct, but it will become Childs.

In order to retrieve the opposite collection of objects (which probably is empty, contains only a single object or plenty of them) you can call on any Foo object the generated getBarsOfFoo method which will return a BarsOfFoo object which itself is a sub-class of Bars.

[Tip] Tip

Association-specific collection classes have additional methods to operate on the association, e.g. inserting new objects (insert) or removing associated objects (remove).

The pyswarm SDK uses the UML model represented as XMI file to generate the Python packages which are to be deployed to the hosts. It creates also set-up files to get the PostgreSQL databases ready to run.

Probably ORM layer will be replaced and/or added by one of these candidates: SQLAlchemy, SQLObjects

WebUI components in the UML model will make the (future) generator creating additional web layers with views and controllers accessing models that are wrapping the original business objects (MVC). Only a small part of the Web layer is available in the public directory of the Apache server.

Web layer should be able to detect capabilities of a browser to switch between traditional XHTML processing (one page rendered per HTTP request) and rich Web clients with AJAX (asynchronous JavaScript and XML) . Remaining task for a developer would be to customize CSS files and the templates.

Framework or library candidates: mod_python, WebHelpers, Zope, Django, Twisted, CherryPy (?), TurboGears, Pylons, script.aculo.us, MochiKit

Native GUI clients, based on wxWidgets/wxPython, will provide end-users a rich human/machine interface and are vastly stubs are created automatically by pyswarm SDK.

Integration with OpenOffice.org, printers, and other typical office periphery devices should follow.

(?)
This document was created using the >e-novative> DocBook Environment (eDE)