Friday, October 31, 2008

Using the Gaphor UML model

The Gaphor UML modeling tool is is written in Python and has has an easily accessible UML model API. This API can be used by other applications as well. The source code for the current Gaphor release can be found here.

Here is an example of how we can initialize an ElementFactory instance.

from gaphor.UML.elementfactory import ElementFactory
from gaphor.UML import Class

if __name__=='__main__':
factory_obj=ElementFactory()
print 'Factory initialized with %s elements.'%(factory_obj.size())

We can then use this ElementFactory instance to create new UML elements as illustrated below.

    class_obj=factory_obj.create(Class)
print 'Class object created with ID: %s'%(class_obj.id)

In the future, I'll go into more detail about the ElementFactory class in future posts because it is a useful tool for Python applications.

No comments :

Post a Comment