Login | Register
My pages Projects Community openCollabNet

Wiki: UML2, Profiles and XMI

Revision 1 as of 2010-12-14 12:27:18 -0800

Edit this page | Links to this page | Page information | Attachments | Refresh page


This pages explains how profiles are persisted in eclipse UML2 and EMF. A sample profile and a model are developed to demonstrate how the XMI representation evolves. The key topic of this article is the work with changing profiles and how the model uses them. Everything here can be done using ArgoUML (in fact lot's of development is done along the writing of this article).

Profile creation

In UML 2.x, a profile is a separate metamodel element. Both metamodel elements "Model" and "Profile" are packages. In ArgoUML, they are top level packages. You can see this in the XMI files created by ArgoUML: a model begins with a <uml:Model ...> node, while a profile begins with a <uml:Profile ...> node (after the XMI header).

Such a profile object is created in ArgoUML via the "New Profile" functionality. It is then displayed in the explorer pane, and elements like stereotypes or datatypes can be added to it. Since ArgoUML saves this in a project file (.zargo), even diagrams can be added to the profile project.

Elements in a profile can only be applied to model elements, when the profile is "deployed" as an XMI file. This is performed via the "Deploy" menu item when you right-click on a profile in the explorer, which then does three things:

  1. In eUML, a method define() is called on the profile package, which adds (nonstandard) Ecore extensions to it.

  2. Export the defined profile as a (to be chosen) XMI file.
  3. Load it as a read-only profile so that it's available in the "Profile Configuration".

Let's create a sample profile with one stereotype 'myStereotype', which can be applied to a class. The XMI representation is (xmi:id values made more readable, some parts omitted):

<uml:Profile ... xmi:id="ID_myProfile" name="myProfile" metaclassReference="ID_ElementImport"> 
  <elementImport xmi:type="uml:ElementImport" xmi:id="ID_ElementImport" importingNamespace="ID_myProfile">
    <importedElement xmi:type="uml:Class" href="http://schema.omg.org/spec/UML/2.2/uml.xml#Class"/>
  <packagedElement xmi:type="uml:Stereotype" xmi:id="ID_myStereotype" name="myStereotype">
    <ownedAttribute xmi:type="uml:Property" xmi:id="ID_base_Class" name="base_Class" association="ID_Extension">
      <type xmi:type="uml:Class" href="http://schema.omg.org/spec/UML/2.2/uml.xml#Class"/>
  <packagedElement xmi:type="uml:Extension" xmi:id="ID_Extension" name="Class_myStereotype"
      memberEnd="ID_ExtensionEnd ID_base_Class">
    <ownedEnd xmi:type="uml:ExtensionEnd" xmi:id="ID_ExtensionEnd" name="extension_myStereotype"
        type="ID_myStereotype" aggregation="composite" owningAssociation="ID_Extension"

This cannot be applied to a model, because in eclipse UML2 the profile needs to be "defined" first. This step introduces an Ecore package in the profile, that represents the whole profile. (Without that Ecore package, ArgoUML cannot use any profile element of the profile!) In XMI, only that Ecore package is added in comparison to the previous listing:

<uml:Profile ... xmi:id="ID_myProfile" name="myProfile" metaclassReference="ID_ElementImport"> 
  <xmi:Extension extender="http://www.eclipse.org/emf/2002/Ecore">
    <eAnnotations xmi:type="ecore:EAnnotation" xmi:id="_0X4jIPNCEd-9Y50SrfMS2A" ...>
      <contents xmi:type="ecore:EPackage" xmi:id="_0X4jIfNCEd-9Y50SrfMS2A" name="myProfile" ...>
        <eClassifiers xmi:type="ecore:EClass" xmi:id="_0X4jIvNCEd-9Y50SrfMS2A" name="myStereotype">
          <xmi:Extension extender="http://www.eclipse.org/emf/2002/Ecore">
            <eAnnotations xmi:type="ecore:EAnnotation" xmi:id="_0X4jI_NCEd-9Y50SrfMS2A" ...
          <eStructuralFeatures xmi:type="ecore:EReference" xmi:id="_0X4jJPNCEd-9Y50SrfMS2A" name="base_Class"
              ordered="false" lowerBound="1">
            <eType xmi:type="ecore:EClass" .../>
          <eStructuralFeatures xmi:type="ecore:EAttribute" xmi:id="_0X4jJvNCEd-9Y50SrfMS2A" name="myProperty"
              ordered="false" lowerBound="1"/>
<-------------- from here it's exactly the same as in the previous listing

Such a defined profile can then be used, which is presented next.

Profile application

In ArgoUML, a profile is applied via the "Profile Configuration". Applying a profile basically means referring it in the model. As an example, we create a very simple model with just one minimalistic class, here are it's main XMI parts (simplyfied again):

<uml:Model ... xmi:id="ID_myModel" name="myModel"> 
  <packagedElement xmi:type="uml:Class" xmi:id="ID_myClass" name="myClass"/>

Applying the profile and stereotyping the class with myStereotype yields the following:

<?xml version="1.0" encoding="UTF-8"?> 
<xmi:XMI ...>
  <uml:Model xmi:id="ID_myModel" name="myModel">
    <packagedElement xmi:type="uml:Class" xmi:id="ID_myClass" name="myClass"/>
    <profileApplication xmi:type="uml:ProfileApplication" xmi:id="ID_profileApplication" applyingPackage="ID_myModel">
      <xmi:Extension extender="http://www.eclipse.org/emf/2002/Ecore">
        <eAnnotations xmi:type="ecore:EAnnotation" xmi:id="_k-TQ8PO5Ed-p9Nu3qLl7Zw" source="http://www.eclipse.org/uml2/2.0.0/UML">
          <references xmi:type="ecore:EPackage" href="http://argouml.org/user-profiles/myProfile_defined_once.xmi#_vOqHcPOuEd-ZR_t966HNrQ"/>
      <appliedProfile xmi:type="uml:Profile" href="http://argouml.org/user-profiles/myProfile_defined_once.xmi#ID_myProfile"/>
  <myProfile:myStereotype xmi:id="_phd6IPO5Ed-p9Nu3qLl7Zw" base_Class="ID_myClass"/>

To be continued...

TODO: changing the profile and apply it again, watching what happens to the old stereotype application