Author Topic: Iterating on pckgs/elements and diagrams Java API  (Read 2672 times)

Albert De La Fuente

  • EA Novice
  • *
  • Posts: 7
  • Karma: +0/-0
    • View Profile
Iterating on pckgs/elements and diagrams Java API
« on: June 02, 2012, 12:30:16 am »
Hi,

I'm trying to build a program that iterates trough all the packages, elements and diagrams using Java EA API.

I found some python code that does something similar, ideally I would like to translate that code to Java but I'm not able to find some properties. Here are some Python snippets that I need to run on Java.

def DumpRepository(Earepository):
   print "-- Repostitory  --"
   print "Instance GUID: ", Earepository.InstanceGUID
   print "ConnectionString: ", Earepository.ConnectionString
   print "Library version: ", Earepository.LibraryVersion
   print
   print "Model count: ", Earepository.Models.Count
   print "Terms count: ", Earepository.Terms.Count
   print "Issues count: ", Earepository.Issues.Count
   print "Author count: ", Earepository.Authors.Count
   print "Client count: ", Earepository.Clients.Count
   print "Task count: ", Earepository.Tasks.Count
   print "Datatypes count: ", Earepository.Datatypes.Count
   print "Recource count: ", Earepository.Resources.Count
   print "Stereotype count: ", Earepository.Stereotypes.Count
   print "PropertyType count: ", Earepository.PropertyTypes.Count
   print

def expand_diags(diagrams, indent):
   for i in xrange(0, diagrams.Count):
        diagram = diagrams.GetAt(i)              
        print ("  " * indent) + "Diagram ID: " + `diagram.DiagramID` + "\t" + diagram.Name    
        
def expand_elems(elements, indent):
   for i in xrange(0, elements.Count):
        element = elements.GetAt(i)
        print ("  " * indent) + "Element ID: " + `element.ElementID` + "\t" + element.Name      
        
def expand_pkgs(packages, indent):
   for i in xrange(0, packages.Count):
        package = packages.GetAt(i)
        if 'p' in opts:
            print ("  " * indent) + "Package ID: " + `package.PackageID` + "\t" + package.Name
        if 'd' in opts:  
            expand_diags(package.Diagrams, indent + 1)
        if 'e' in opts:
            expand_elems(package.Elements, indent + 1)
      
        innerpkg = package.Packages
        if innerpkg.Count > 0:
            expand_pkgs(innerpkg, indent + 1)

Does anyone can please help me with something similar? I couldn't find similar examples on Java. I'm running this code and I always get NullPointerException:

    public void run (String[] args) throws Exception
    {
        inputFile = "C:\\EA\\siga.EAP";
                
        org.sparx.Repository r = new org.sparx.Repository();
        r.OpenFile(inputFile);
        
        out.println("-- Repostitory --");
        out.println("Models Count: " + r.GetModels().GetCount());

Thanks a lot for your help.

Eve

  • EA Administrator
  • EA Guru
  • *****
  • Posts: 8085
  • Karma: +118/-20
    • View Profile
Re: Iterating on pckgs/elements and diagrams Java
« Reply #1 on: June 04, 2012, 08:27:24 am »
Have a look at C:\Program Files (x86)\Sparx Systems\EA\Code Samples\Java_Sample. (Assuming you're on a 64 bit system)

But my guess is that creation of the repository object is failing because EA is 32 bit and you're running a 64 bit version of the JDK.
« Last Edit: June 04, 2012, 08:29:11 am by simonm »

Albert De La Fuente

  • EA Novice
  • *
  • Posts: 7
  • Karma: +0/-0
    • View Profile
Re: Iterating on pckgs/elements and diagrams Java
« Reply #2 on: June 04, 2012, 10:44:25 am »
Oh I didn't thought of that detail :o... It makes a lot of sense! Thanks!!

Actually I'm compiling on a linux machine (64bits) and running it on a VM (32bits) over ssh (Cygwin), since is a terminal app and debugging is easier. I thought about compiling over lan or crosscompiling but I couldn't do that yet...

Actually everything would be much easier if Sparx would support officially a native version of EA but they don't so I have to do those magic tricks.

Thanks for your answer, very helpful! =)