Author Topic: Accessing all elements beneath a package  (Read 1820 times)

marke

  • EA User
  • **
  • Posts: 39
  • Karma: +0/-0
    • View Profile
Accessing all elements beneath a package
« on: February 10, 2012, 04:38:29 am »
Hi,

The Package class Elements attribute help entry says it is "a collection of elements that belong to this package". Is that collection just the elements that are leafs of the package? Or does it include the whole tree beneath the package?

Experimentation suggests it is the former (just leaf elements) which I found a bit surprising.

If the former, is there an existing method to return the whole tree as a collection or do I need to implement a traversal method?

Thank you,

Mark

Kaibot

  • EA Novice
  • *
  • Posts: 5
  • Karma: +0/-0
    • View Profile
Re: Accessing all elements beneath a package
« Reply #1 on: February 10, 2012, 04:52:47 am »
Personally I use a traversal method. Elements inside a package will have a packageID attribute that will be the parent package. That is the main thing I use to identify elements inside a certain package.

Let me know if you want more detail!
___kai___

Bjorn S

  • EA Novice
  • *
  • Posts: 11
  • Karma: +0/-0
    • View Profile
Re: Accessing all elements beneath a package
« Reply #2 on: February 10, 2012, 04:59:04 am »
In general, Packages may have more Packages, Elements and Diagrams as children. Elements may have more Elements and Diagrams as children. Thus you need to do a traversal to pick up all the children below an element and construct the structure you wish to get out of it. This is pretty trivial using Javascript and recursion. ;)

Bjorn.

qwerty

  • EA Guru
  • *****
  • Posts: 9438
  • Karma: +150/-139
  • I'm no guru at all
    • View Profile
Re: Accessing all elements beneath a package
« Reply #3 on: February 10, 2012, 09:30:51 am »
That has changed somewhen between 7.5 and 9.0 (don't remember exactly). In older EA builds you get everything - meaning direct elements AND embedded elements in those. Now you get only the elements without embedded ones. But you never get the recursive list of all contained packages. You need to traverse or to write some tricky SQL.

q.

marke

  • EA User
  • **
  • Posts: 39
  • Karma: +0/-0
    • View Profile
Re: Accessing all elements beneath a package
« Reply #4 on: February 10, 2012, 08:18:51 pm »
Thank you for all the responses. In case anyone else stumbles across the same problem here is what worked for me:

function traverseAllElementsIn( elements ) // elements as EA.Collection
{      
      // Navigate the elements collection.
      for ( var j = 0 ; j < elements.Count ; j++ )
      {
            var theElement as EA.Element;
            theElement = elements.GetAt( j );
                  
              renameVerifMethod(theElement); // this does the work
                  
            var subElements as EA.Collection;
            subElements = theElement.Elements;
                  
            if (subElements.Count > 0)
            {
                  Session.Output("# of sub elements " + subElements.Count);
                  traverseAllElementsIn( subElements );
            }
      }
}

Mark

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 8204
  • Karma: +193/-23
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Accessing all elements beneath a package
« Reply #5 on: February 10, 2012, 08:55:04 pm »
Have you tested that with sub-packages as well?
Because packages are a bit strange, they are both package and element...

Geert

marke

  • EA User
  • **
  • Posts: 39
  • Karma: +0/-0
    • View Profile
Re: Accessing all elements beneath a package
« Reply #6 on: February 10, 2012, 09:15:23 pm »
Geert,

I tried it and this function does not traverse down through sub-packages - that's for another day (or an exercise for the reader ;)).

I found a model dump example jscript which would no doubt give tips on how to traverse sub-packages.

Mark

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 8204
  • Karma: +193/-23
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Accessing all elements beneath a package
« Reply #7 on: February 10, 2012, 09:29:07 pm »
Allright, as long as you are aware of the issue..

Geert

Kaibot

  • EA Novice
  • *
  • Posts: 5
  • Karma: +0/-0
    • View Profile
Re: Accessing all elements beneath a package
« Reply #8 on: February 11, 2012, 07:20:28 am »
I'll tell you what, the whole Packages are a package and element thing can make it a bit tedious. Especially because I use an interface to handle all "elements".

I think the reason for this though was to make relationships between EA.Elements, EA.Packages, and the diagram a bit more intuitive.

I supposed editing is also a bit easier.
___kai___

qwerty

  • EA Guru
  • *****
  • Posts: 9438
  • Karma: +150/-139
  • I'm no guru at all
    • View Profile
Re: Accessing all elements beneath a package
« Reply #9 on: February 11, 2012, 07:46:24 am »
You got it. It's called EAUI (EA Unique Interface).

q.
« Last Edit: February 11, 2012, 07:46:39 am by qwerty »