Hi all,
The new version of the Groovy EMFBuilder (see
http://www.dinkla.net/groovy/emf.html) now supports UML2 models.
The Groovy programming language allows the creation of domain specific
languages with its "BuilderSupport" class. This is used by EMFBuilder
to create a language defined by an Ecore EFactory. Because UML2 uses
EMF, UML2 models can be created using the EMFBuilder.
See the following examples and compare with the "Getting Started with
UML2" article at
http://www.eclipse.org/modeling/mdt/uml2/docs/articles/Getting_Started_with_UML2/article.html.
We use the UMLFactory for the EMFBuilder.
def builder = new EMFBuilder(UMLFactory)
We create a model as the root node and we create primitive types and
store them in Groovy variables because we have to reference them later
on.
def epo2Model = builder.Model(name: 'epo2') {
packagedElement {
def intPrimType = PrimitiveType(name: 'int')
def stringPrimType = PrimitiveType(name: 'String')
We define an enumeration OrderStatus with three literals.
def orderStatusEnumeration = Enumeration(name: 'OrderStatus') {
ownedLiteral {
EnumerationLiteral(name: 'Pending')
EnumerationLiteral(name: 'Back Order')
EnumerationLiteral(name: 'Complete')
}
}
The following code snippet shows the definition of the classes Address
and USAddress. All the attributes are defined as a Property. The
primitive types stringPrimType and intPrimType defined above are used.
The class USAddress is a subclass of the abstract class Address. This
is expressed with the Generalization object.
def addressClass = Class(name: 'Address' ,isAbstract: true) {
ownedAttribute {
Property(name: 'name', type: stringPrimType, lower: 0, upper: 1)
Property(name: 'country', type: stringPrimType, lower: 0,upper: 1)
}
}
def usAddressClass = Class(name: 'USAddress') {
generalization {
Generalization(general: addressClass)
}
ownedAttribute {
Property(name: 'street', type: stringPrimType, lower: 0, upper: 1)
Property(name: 'city', type: stringPrimType, lower: 0, upper: 1)
Property(name: 'state', type: stringPrimType, lower: 0, upper: 1)
Property(name: 'zip', type: intPrimType, lower: 0, upper: 1)
}
}
The code is a direct representation of the UML2 diagram.
See the homepage of the UML2 Builder for further details at
http://www.dinkla.net/groovy/uml2.html.
Best regards,
Joern Dinkla