Skip to content
Skip to breadcrumbs
Skip to header menu
Skip to action menu
Skip to quick search
Quick Search
Browse
Pages
Blog
Labels
Attachments
Mail
Advanced
What’s New
Space Directory
Feed Builder
Keyboard Shortcuts
Confluence Gadgets
Log In
Sign Up
Dashboard
Groovy
Copy Page
You are not logged in. Any changes you make will be marked as
anonymous
. You may want to
Log In
if you already have an account. You can also
Sign Up
for a new account.
This page is being edited by
.
Paragraph
Paragraph
Heading 1
Heading 2
Heading 3
Heading 4
Heading 5
Heading 6
Preformatted
Quote
Bold
Italic
Underline
More colours
Strikethrough
Subscript
Superscript
Monospace
Clear Formatting
Bullet list
Numbered list
Outdent
Indent
Align left
Align center
Align right
Link
Table
Insert
Insert Content
Image
Link
Attachment
Symbol
Emoticon
Wiki Markup
Horizontal rule
tinymce.confluence.insert_menu.macro_desc
Info
JIRA Issue
Status
Gallery
Tasklist
Table of Contents
Other Macros
Page Layout
No Layout
Two column (simple)
Two column (simple, left sidebar)
Two column (simple, right sidebar)
Three column (simple)
Two column
Two column (left sidebar)
Two column (right sidebar)
Three column
Three column (left and right sidebars)
Undo
Redo
Find/Replace
Keyboard Shortcuts Help
<p>The <a href="http://wiki.eclipse.org/MDT-UML2">Eclipse UML2</a> project provides an implementation of the <a href="http://en.wikipedia.org/wiki/Unified_Modeling_Language">Unified Modeling Language (UML) 2.1</a> metamodel in Java. The fact that the underlying technology is the <a href="http://www.eclipse.org/modeling/emf/">Eclipse Modeling Framework (EMF)</a> makes it possible to use the <a href="http://www.dinkla.net/groovy/emf.html">EMFBuilder</a> with the UML2 metamodel.</p> <p>The <a href="http://www.eclipse.org/modeling/mdt/uml2/docs/articles/Getting_Started_with_UML2/article.html">introductory article</a> by Ken Hussey explains how to create UML2 models with the Eclipse editor and how to create them programmatically with Java code. Here we will use Groovy and the <a href="http://www.dinkla.net/groovy/emf.html">EMFBuilder</a>.</p> <p>We use the UMLFactory for the EMFBuilder.</p> <table class="wysiwyg-macro" data-macro-name="code" style="background-image: url(/plugins/servlet/confluence/placeholder/macro-heading?definition=e2NvZGV9&locale=en_GB&version=2); background-repeat: no-repeat;" data-macro-body-type="PLAIN_TEXT"><tr><td class="wysiwyg-macro-body"><pre> def builder = new EMFBuilder(UMLFactory) </pre></td></tr></table> <p>We create a model as the root node and then we create two primitive types and store them in Groovy variables because we have to reference them later on.</p> <table class="wysiwyg-macro" data-macro-name="code" style="background-image: url(/plugins/servlet/confluence/placeholder/macro-heading?definition=e2NvZGV9&locale=en_GB&version=2); background-repeat: no-repeat;" data-macro-body-type="PLAIN_TEXT"><tr><td class="wysiwyg-macro-body"><pre> def epo2Model = builder.Model(name: 'epo2') { packagedElement { def intPrimitiveType = PrimitiveType(name: 'int') def stringPrimitiveType = PrimitiveType(name: 'String') </pre></td></tr></table> <p>We define an enumeration OrderStatus with three literals.</p> <table class="wysiwyg-macro" data-macro-name="code" style="background-image: url(/plugins/servlet/confluence/placeholder/macro-heading?definition=e2NvZGV9&locale=en_GB&version=2); background-repeat: no-repeat;" data-macro-body-type="PLAIN_TEXT"><tr><td class="wysiwyg-macro-body"><pre> def orderStatusEnumeration = Enumeration(name: 'OrderStatus') { ownedLiteral { EnumerationLiteral(name: 'Pending') EnumerationLiteral(name: 'Back Order') EnumerationLiteral(name: 'Complete') } } </pre></td></tr></table> <p>The following code snippet shows the definition of the classes Address and USAddress. All the attributes are defined as a Property. The primitive types stringPrimitiveType and intPrimitiveType defined above are used. The class USAddress is a subclass of the abstract class Address. This is expressed with the Generalization object.</p> <table class="wysiwyg-macro" data-macro-name="code" style="background-image: url(/plugins/servlet/confluence/placeholder/macro-heading?definition=e2NvZGV9&locale=en_GB&version=2); background-repeat: no-repeat;" data-macro-body-type="PLAIN_TEXT"><tr><td class="wysiwyg-macro-body"><pre> def addressClass = Class(name: 'Address' ,isAbstract: true) { ownedAttribute { Property(name: 'name', type: stringPrimitiveType, lower: 0, upper: 1) Property(name: 'country', type: stringPrimitiveType, lower: 0, upper: 1) } } def usAddressClass = Class(name: 'USAddress') { generalization { Generalization(general: addressClass) } ownedAttribute { Property(name: 'street', type: stringPrimitiveType, lower: 0, upper: 1) Property(name: 'city', type: stringPrimitiveType, lower: 0, upper: 1) Property(name: 'state', type: stringPrimitiveType, lower: 0, upper: 1) Property(name: 'zip', type: intPrimitiveType, lower: 0, upper: 1) } } </pre></td></tr></table> <p>Compare this code to the original code in the article! The code is much more concise and is a direct representation of the UML2 diagram. No auxiliary methods are needed.</p> <p>See the homepage of the <a href="http://www.dinkla.net/groovy/uml2.html">UML2 Builder</a> for further details.</p>
Please type the word appearing in the picture.
Attachments
Labels
Location
Watch this page
< Edit
Preview >
Loading…
Save
Cancel
Next hint
search
attachments
weblink
advanced