Book a Demo

Author Topic: UML profile and packages  (Read 4676 times)

xhanness

  • EA User
  • **
  • Posts: 32
  • Karma: +0/-0
    • View Profile
UML profile and packages
« on: February 28, 2009, 02:00:11 am »
Hi,

I have created a UML profile, which contains quite a lot elements. Then I put them into a subpackages (so the profile had several packages with elements), but the import of this profile load no elements
When I put all elements from packages back directly into the profile package, the import proceeded.
The problem is, that I have many elements belonging to to different scopes (logically) and I would like to separate them.

Do you have any suggestions how to achieve this?


thanks
« Last Edit: February 28, 2009, 08:07:11 am by xhanness »

KP

  • EA Administrator
  • EA Expert
  • *****
  • Posts: 2919
  • Karma: +55/-3
    • View Profile
Re: UML profile and packages
« Reply #1 on: March 02, 2009, 09:04:25 am »
How about... have a single «profile» package with several diagrams, each diagram containing a related set of stereotypes. When you want to save the profile, right-click the package in the Project Browser, and all stereotypes on all diagrams will be included.
The Sparx Team
[email protected]

Frank Horn

  • EA User
  • **
  • Posts: 535
  • Karma: +1/-0
    • View Profile
Re: UML profile and packages
« Reply #2 on: March 03, 2009, 09:25:07 pm »
Quote
How about... have a single «profile» package with several diagrams, each diagram containing a related set of stereotypes. When you want to save the profile, right-click the package in the Project Browser, and all stereotypes on all diagrams will be included.

This still leaves you with one package containing all the metaclasses and stereotypes for the profile, which can be quite ugly for a huge profile. The natural thing would be to structure it with the help of a package hierarchy like other models, but unfortunately EA's profile export only considers the stereotypes from the top level package.

This may not be a bug in the strict sense of the word, but it's a nuisance all the same.

«Midnight»

  • EA Guru
  • *****
  • Posts: 5651
  • Karma: +0/-0
  • That nice Mister Grey
    • View Profile
Re: UML profile and packages
« Reply #3 on: March 04, 2009, 12:53:02 am »
Actually, this seems to be how things should work.

Think of your profile as a namespace for stereotypes. [As far as UML is concerned, this is pretty much accurate.] In effect all the stereotypes in your profile are qualified names, along the lines of MyProfile::AStereotype.

EA uses the profile package to represent the namespace (which is one of the things packages do). If you were to use a package hierarchy you would end up with something like PartOf::MyProfile::AStereotype. Two problems with this are that the stereotype is no longer part of your profile (i.e. the complete qualifier is different, even though the root is the same), and that EA does not recognize a namespace path (i.e. more than one step) for profiles. [I am not sure whether UML recognizes such a thing, or even allows for the possibility.]

I can imagine several ways in which this might be resolved. None of them are 'clean' though, in the sense that they all require breaking the normal paradigm of how EA works; perhaps they violate the intent of UML as well. Even if one of these were to be considered, I suspect that thinking it through would surface additional hurdles.

Sigh...

Perhaps someone can contribute a usable workaround.

David
No, you can't have it!

xhanness

  • EA User
  • **
  • Posts: 32
  • Karma: +0/-0
    • View Profile
Re: UML profile and packages
« Reply #4 on: March 04, 2009, 01:05:22 am »
Thank you guys for your sugestions and comments.
I did not know, that profile package serves as a "namespace" for stereotypes.
On the the other hand, why could not namespace be considered as a "nested namespace". I think of Java's packages as a nested namespaces... it works there fine and I can create perfect logical structure for my Classes.
However, it seems that there is no way in EA how to achieve this. I will use the idea with grouping stereotypes into several diagrams ....

thanks again !

«Midnight»

  • EA Guru
  • *****
  • Posts: 5651
  • Karma: +0/-0
  • That nice Mister Grey
    • View Profile
Re: UML profile and packages
« Reply #5 on: March 04, 2009, 01:11:29 am »
This is the UML stuff I referred to (more specifically, I mentioned that I did not know the details of).

The concepts behind namespaces in programming (Java, .Net, and other namespace-aware languages) are not necessarily the same for UML profiles. In particular, I am not sure that hierarchies are supported at all. In fact, I do not know for sure if UML specifies how they are kept distinct, beyond the fact that they somehow are.

You'll have to look into this yourself. Of or course, wait for someone to post the details here.

David
No, you can't have it!

Frank Horn

  • EA User
  • **
  • Posts: 535
  • Karma: +1/-0
    • View Profile
Re: UML profile and packages
« Reply #6 on: March 04, 2009, 01:32:02 am »
Actually I once tried to set up a workaround but didn't achieve full automation, as the EA API is sadly lacking a method for profile export. All I came up was a half automatic thing like this:

1. Export top profile package to XMI;
2. transform via XSL such that all contents of subpackages are lifted to the top package;
3. import transformed package (different EA project, or with stripped GUIDs);
4. save imported package as profile;
5. discard imported package.

For what it's worth, here's the transformation (on XMI 2.1):

Code: [Select]
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.1" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"  xmlns:uml = 'http://schema.omg.org/spec/UML/2.1'  xmlns:xmi = 'http://schema.omg.org/spec/XMI/2.1'>

  <xsl:output method="xml" media-type="text/xml" indent="yes" />

  <xsl:template match="/xmi:XMI" xmlns:xs="http://www.w3.org/2001/XMLSchema">

    <xmi:XMI xmi:version="2.1">

      <!--
      Copy everything before and after uml:Model.
      For uml:Model copy only attributes and consolidate contents.
      -->

      <xsl:copy-of select = "xmi:Documentation" />

      <xsl:for-each select="uml:Model">

        <uml:Model xmi:type="uml:Model" name="EA_Model" visibility="public">

          <!--Copy attributes-->
          <xsl:copy-of select = "@*" />

          <!--Use recursive template to copy all profile contents to top level-->
          <xsl:call-template name="CopyProfileContents" />

        </uml:Model>

      </xsl:for-each>

      <xsl:copy-of select = "xmi:Extension" />

    </xmi:XMI >

  </xsl:template>

  <xsl:template name="CopyProfileContents" xmlns:xs="http://www.w3.org/2001/XMLSchema">

    <xsl:for-each select="*">

      <!--Copy all elements except those called packagedElement.-->

      <xsl:choose>

        <xsl:when test="name(.)='packagedElement'">

          <xsl:choose>

            <!--
            Copy all elements called packagedElement except some of
            those of type uml:Package or uml:Profile.
            -->

            <xsl:when test="@xmi:type='uml:Profile'">

              <!--
              For top level profiles, copy node and attributes and recursively copy contents.
              For profiles under top level, just recursively copy contents.
              -->

              <xsl:choose>

                <xsl:when test="count(ancestor::packagedElement[@xmi:type='uml:Profile'])=0">

                  <packagedElement>

                    <xsl:copy-of select = "@*" />
                    <xsl:call-template name="CopyProfileContents" />

                  </packagedElement>

                </xsl:when>

                <xsl:otherwise>
                  <xsl:call-template name="CopyProfileContents" />
                </xsl:otherwise>

              </xsl:choose>

            </xsl:when>

            <xsl:when test="@xmi:type='uml:Package'">

              <!--For packages, just recursively copy contents-->
              <xsl:call-template name="CopyProfileContents" />

            </xsl:when>

            <xsl:otherwise>
              <xsl:copy-of select = "." />
            </xsl:otherwise>

          </xsl:choose>

        </xsl:when>

        <xsl:otherwise>
          <xsl:copy-of select = "." />
        </xsl:otherwise>

      </xsl:choose>

    </xsl:for-each>

  </xsl:template>

</xsl:stylesheet>