Book a Demo

Author Topic: retrieve element from repository by element.name  (Read 6693 times)

mariano774

  • EA Novice
  • *
  • Posts: 13
  • Karma: +0/-0
  • I love YaBB 1G - SP1!
    • View Profile
retrieve element from repository by element.name
« on: February 21, 2006, 10:42:44 am »
Hi

I'm coding a plugin and I need to retrieve an element from EARepository of which I only know its name, is there a way to do it ? I only found GetElementById() and GetElementByGUID()

Thanks in advance.
Mar

thomaskilian

  • Guest
Re: retrieve element from repository by element.na
« Reply #1 on: February 21, 2006, 10:53:16 am »
So what do you know that you can distinguish it from others? You need a unique identifier, don't you?

«Midnight»

  • EA Guru
  • *****
  • Posts: 5651
  • Karma: +0/-0
  • That nice Mister Grey
    • View Profile
Re: retrieve element from repository by element.na
« Reply #2 on: February 21, 2006, 10:57:43 am »
The problem of course is that elements within different namespaces may have identical names. Add to that the problem of anonymous elements and things get really dicey.

Some time ago I bit the bullet and wrote a simple recursive routine to traverse the qualified name of an element (i.e. the full path). Worked better than I thought it would, once I thought it through.

Of course, I immediately changed how I referenced elements, therefore making the routine obsolete. Since then I have no idea where I acrhived the code.

Take a look at the Project interface emumeration functions, grab an adequate XML library, and take a whack. Once you get the hang of it - which shoudl be quickly - it will fall into place.

David
No, you can't have it!

mariano774

  • EA Novice
  • *
  • Posts: 13
  • Karma: +0/-0
  • I love YaBB 1G - SP1!
    • View Profile
Re: retrieve element from repository by element.na
« Reply #3 on: February 21, 2006, 11:08:42 am »
thomaskilian:
Im doing a plugin to make a sequence
diagram out of a piece of code, so once I identify the className, I need to add it to the diagram. the diagram part works fine already but since i parse the class name from the code all I know is its name, I have no idea which ID the element has in the repository

Midnight:
I believe I can find out the namespace of the class using the import sentences available in the code, but Im not sure how to work with the 'Project interface emumeration functions' you mention, can you give me a clue there ? thanks

thomaskilian

  • Guest
Re: retrieve element from repository by element.na
« Reply #4 on: February 21, 2006, 11:14:51 am »
You can get all element of a package (package.Elements() yields a Collection). Pick the classes only. To recurse use package.Packages() (also Collection class),

mariano774

  • EA Novice
  • *
  • Posts: 13
  • Karma: +0/-0
  • I love YaBB 1G - SP1!
    • View Profile
Re: retrieve element from repository by element.na
« Reply #5 on: February 21, 2006, 11:18:28 am »
yes, that works fine, but my problem is I don't know how to bring the package containing my desired class.

again afaik I can only search for packages using GetPackageByGuid or GetPackageByID and i dont know any of those ids  :'( I only know the package name

any ideas ?

thomaskilian

  • Guest
Re: retrieve element from repository by element.na
« Reply #6 on: February 21, 2006, 11:33:00 am »
You have to recurse the packages from root. This is fast since there are only a few (in database measures) to traverse. Be sure to keep a trigger for multiple occurence of the package name so you can raise an error/ask the user which package to choose.

mariano774

  • EA Novice
  • *
  • Posts: 13
  • Karma: +0/-0
  • I love YaBB 1G - SP1!
    • View Profile
Re: retrieve element from repository by element.na
« Reply #7 on: February 21, 2006, 11:35:21 am »
ouch, well i guess i know whats my future suggestion for the next version

thanks

«Midnight»

  • EA Guru
  • *****
  • Posts: 5651
  • Karma: +0/-0
  • That nice Mister Grey
    • View Profile
Re: retrieve element from repository by element.na
« Reply #8 on: February 21, 2006, 12:44:29 pm »
You're likely stuck with this for good. The limitation is not in EA, but build right into UML.

UML allows a hierarchy of packages. Within each may be elements and packages. With named elements (classes, packages and so forth) these are generally uniquely named (or otherwise identified) within the containing package. The problem is that I can have a class with a given, say "foo" in my "outer" pagkage. The "outer" package may also contain a package, say "inner." The "inner" package may also have a class named "foo." Not only that, but the package containing the "outer" package may have other packages, say "sibling1," "sibling2" etc. Each of these may have its own "foo" class.

That's why you have to traverse the tree, looking for the package you want - remembering that the same duplication of names also holds true for packages - before looking up the element.

EA's .GetBeName() function works for such elements, but only within the context of a given package (or namespace of some kind), which is correct considering the above UML structural issues.
No, you can't have it!