Home » Modeling » EMF » New version of Groovy EMFBuilder supports UML2 models
New version of Groovy EMFBuilder supports UML2 models [message #415035] |
Wed, 28 November 2007 09:32  |
Eclipse User |
|
|
|
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/Getti ng_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
--
Dipl.-Inform. Jörn Dinkla
Freelancer - http://www.dinkla.net
Dorotheenstrasse 133, 22299 Hamburg, Germany
|
|
|
Re: New version of Groovy EMFBuilder supports UML2 models [message #415038 is a reply to message #415035] |
Wed, 28 November 2007 09:53   |
Eclipse User |
|
|
|
Joern,
This sounds too cool. I wish I had time to explore. I wonder if this
might make an interesting EMFT component? Are you interested in that?
There's a proposal for a C#-based version of EMF so this seems kind of
like a similar thing...
Joern Dinkla wrote:
> 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/Getti ng_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
>
|
|
|
Re: New version of Groovy EMFBuilder supports UML2 models [message #415044 is a reply to message #415038] |
Wed, 28 November 2007 10:41  |
Eclipse User |
|
|
|
Yes Ed,
I am interested, but I think the EMFBuilder is too small in scope for a regular EMFT
component. The EMFBuilder basically is just a wrapper around the createXXX() methods of an
EFactory.
I will add a reference to the Modeling Corner.
Best regards,
Joern
Ed Merks wrote:
> Joern,
>
> This sounds too cool. I wish I had time to explore. I wonder if this
> might make an interesting EMFT component? Are you interested in that?
> There's a proposal for a C#-based version of EMF so this seems kind of
> like a similar thing...
>
>
> Joern Dinkla wrote:
>> 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/Getti ng_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
>>
--
Dipl.-Inform. Jörn Dinkla
Freelancer - http://www.dinkla.net
Dorotheenstrasse 133, 22299 Hamburg, Germany
|
|
|
Goto Forum:
Current Time: Thu Apr 24 06:16:10 EDT 2025
Powered by FUDForum. Page generated in 0.02991 seconds
|