Book a Demo

Author Topic: Accessing packages within a model document  (Read 4201 times)

herzogju

  • EA Novice
  • *
  • Posts: 2
  • Karma: +0/-0
  • I love YaBB 1G - SP1!
    • View Profile
Accessing packages within a model document
« on: March 19, 2007, 10:07:17 am »
Hi,

I've defined a class C with stereoptype <<model document>> ("virtual document") which contains a package P in a different model view. P is shown as an attribute of C.
I want to write a report using the VBA automation interface.
I got a handle onto C and from there a handle onto the attribute P. How can I get a handle onto the actual package which is referenced by C.P?

Regards Jürgen

jbatista

  • EA Novice
  • *
  • Posts: 5
  • Karma: +0/-0
  • I love YaBB 1G - SP1!
    • View Profile
Re: Accessing packages within a model document
« Reply #1 on: August 29, 2007, 12:14:32 am »
Hi, do u have further knowledge after all this months without reply?

I'm in similar position: want to export all packages within a Model document class to HTML. The thing is: which GUID or ID has the packages wich are attributes of an element.

I went deep on EA Type Library (delphi), and the onl thing that i've found different in an attribute of type package is that they have an ClassifierID.

I related that classifierID with the PackageID and tried to obtain Package Info trough packageID with values in Att.ClassifierID, without success.

I'mk trying now to relate Att With Element trough ClassifierID and Element with Package trough PackageID, because i realized that a Package have an associated Element  (Hidden one) for customizing some info.

jbatista

  • EA Novice
  • *
  • Posts: 5
  • Karma: +0/-0
  • I love YaBB 1G - SP1!
    • View Profile
Re: Accessing packages within a model document
« Reply #2 on: August 29, 2007, 03:20:14 am »
Tested and solved.

It's possible to access packages within element attributes, but is a little wicked.

First let me put things clearly:
1. Packages are containers of elements, that have an associated Element (Hidden one) for input of general information (just like element, e.g. Author, Status, Priority, etc..)
2. The Class stereotyped Model Document, can have attributes of Type Package, when this occur we just have set an attribute of a Class that is not Primitive, and for that EA just set a ClassifierID for the Attribute.

All things together:
» The package that we added to the Class as an attribute (for documentation purpose), was set with ClassifierID equal to ElementID that represents the Package General Information (as already said).
» To access Packages from Class Model Document you have to:
  1. Obtain The Element associated to Package: REpository.GetElementByID(Element.Attribute.ClassifierID)
  2. Iterate through packages for the package that have an Element associated that equals the classifierID we have in attribute: Package.Element.ElementID = REpository.GetElementByID(Element.Attribute.ClassifierID).ElementID

NOTES:
- Attributes with primitive type have classifierID set to 0.
- Root Node Packages have no element associated.

I hope that this helped you in some way, and all other one's  of EA's community.

My purpose of accessing packages in Class Model Document (MDC): i had to generate HTML reports for an MDC because EA's doesn't do it out of the box, so i created an Addin for the generation of HTML Reports based on MDC Classes.

herzogju

  • EA Novice
  • *
  • Posts: 2
  • Karma: +0/-0
  • I love YaBB 1G - SP1!
    • View Profile
Re: Accessing packages within a model document
« Reply #3 on: September 01, 2007, 05:23:38 am »
Hi,

I didn't get any further that time, so I went to parse the XML using this function:

Code: [Select]
Sub DumpModelDocument(element As EA.element)
   
   ' o element is a virtual document, i.e. an element with stereotype <<model document>>
   ' o extract the content of a package that is an attribute of element

   Dim EaProject As EA.project
   Set EaProject = EaRepos.GetProjectInterface
   
   Dim ObjectGUID As String
   ObjectGUID = EaProject.GUIDtoXML(element.ElementGUID)
 
   Dim xmlElement As New MSXML2.DOMDocument
   Dim xmlNode As MSXML2.IXMLDOMNode
   Dim xmlNodeList As MSXML2.IXMLDOMNodeList
     
   xmlElement.loadXML EaProject.GetElement(ObjectGUID)
   
   Set xmlNode = xmlElement.selectSingleNode("Document/Element")
   
   'go to first element - will be the actual element (i.e. UML:Class)
   Set xmlNode = xmlNode.firstChild()

   ' DEBUG:
   ' MsgBox "XML: " + xmlNode.xml

   Set xmlNode = xmlNode.selectSingleNode("UML:Classifier.feature")
   Set xmlNodeList = xmlNode.selectNodes("UML:Attribute")
   For Each xmlNode In xmlNodeList
       Set xmlNode = xmlNode.selectSingleNode("UML:StructuralFeature.type/UML:Classifier")
       
       Dim targetPackageXML As String
       targetPackageXML = xmlNode.Attributes.getNamedItem("xmi.idref").text
         
       Dim targetPackageGUID As String
       targetPackageGUID = EaProject.XMLtoGUID(targetPackageXML)
         
       Dim targetPackage As EA.package
       Set targetPackage = EaRepos.GetPackageByGuid(targetPackageGUID)
       
       ' Now you can something with targetPackage ...
   Next

End Sub


It probably does more or less the same as you described.

Regards Jürgen