Author Topic: Java API for reading/writing the model  (Read 9078 times)

vorpatril

  • EA Novice
  • *
  • Posts: 8
  • Karma: +0/-0
  • I love YaBB 1G - SP1!
    • View Profile
Java API for reading/writing the model
« on: March 13, 2007, 09:42:38 am »
Hi all,

I am new to EA and I would like to know if the product provides a Java API. The purpose is to create/delete/modify UML Elements from an Eclipse plugin of my own.

I have installed EA MDG for Eclipse and read the documentation but I can't find any information about this subject.

Thanks in advance.

mikewhit

  • EA User
  • **
  • Posts: 608
  • Karma: +0/-0
  • Accessing ....
    • View Profile
Re: Java API for reading/writing the model
« Reply #1 on: March 13, 2007, 09:55:01 am »
http://sparxsystems.com.au/EAUserGuide/automationscripting.htm

In other words, your tool will need to talk COM/OLE.

There are probably some good examples in Perl or VB that you could translate to Java (given COM/OLE !) if you search the forum over the last few years (use 9999 days).

«Midnight»

  • EA Guru
  • *****
  • Posts: 5651
  • Karma: +0/-0
  • That nice Mister Grey
    • View Profile
Re: Java API for reading/writing the model
« Reply #2 on: March 13, 2007, 12:01:55 pm »
Actually, there is a beta version of a Java API. It comes with the full install kit, but I don't know if it is part of the evaluation product.

You have to look through the installation directory to find it.
No, you can't have it!

Eve

  • EA Administrator
  • EA Guru
  • *****
  • Posts: 8078
  • Karma: +118/-20
    • View Profile
Re: Java API for reading/writing the model
« Reply #3 on: March 13, 2007, 12:05:01 pm »
Mike, here's your opportunity to learn something new about EA.  There is a Java API that mirrors the COM interface.  There is a subdirectory in your EA install directory called Java API that includes all the necessary files.

Have a look at http://sparxsystems.com.au/EAUserGuide/index.html?setup.htm and the readme file in that directory for information on how to set it up and use it.

This is still in a Beta form, but the feedback has been good.

vorpatril

  • EA Novice
  • *
  • Posts: 8
  • Karma: +0/-0
  • I love YaBB 1G - SP1!
    • View Profile
Re: Java API for reading/writing the model
« Reply #4 on: March 13, 2007, 10:35:52 pm »
Thank you for your answers.

Ok, I've got the directory in the trial version.

Is there any documentation and / or examples ?

mikewhit

  • EA User
  • **
  • Posts: 608
  • Karma: +0/-0
  • Accessing ....
    • View Profile
Re: Java API for reading/writing the model
« Reply #5 on: March 14, 2007, 06:36:01 am »
Sorry for my ignorance - I haven't updated my EA version since I stopped doing UML full-time :(

«Midnight»

  • EA Guru
  • *****
  • Posts: 5651
  • Karma: +0/-0
  • That nice Mister Grey
    • View Profile
Re: Java API for reading/writing the model
« Reply #6 on: March 14, 2007, 07:18:30 am »
I looked at this a build or two ago. What you find in the install directory, and any references therein, is all that's available for now. My guess is that when (if?) the interface proves out Sparx will add it to the main documentation set, and perhaps issue a white paper.

David
No, you can't have it!

Eve

  • EA Administrator
  • EA Guru
  • *****
  • Posts: 8078
  • Karma: +118/-20
    • View Profile
Re: Java API for reading/writing the model
« Reply #7 on: March 14, 2007, 01:01:49 pm »
Sorry, the only example is the one in my previous link.  Other than the classes being in a package, and all of the collections using generics if follows the existing interface exactly, so the same documentation should still be valid.

vorpatril

  • EA Novice
  • *
  • Posts: 8
  • Karma: +0/-0
  • I love YaBB 1G - SP1!
    • View Profile
Re: Java API for reading/writing the model
« Reply #8 on: March 15, 2007, 01:08:52 am »
Ok, I think I can start testing this API.

vorpatril

  • EA Novice
  • *
  • Posts: 8
  • Karma: +0/-0
  • I love YaBB 1G - SP1!
    • View Profile
Re: Java API for reading/writing the model
« Reply #9 on: March 16, 2007, 02:57:30 am »
Here is my first experience with this API :

1) I create a new Repository
2) I open an existing EA file
3) I get the models from the repository
4) I create a new Package

The problems :

1) The EA Application does not start when I launch my test (it is supposed to considering the documentation) - (if I start EA before my test does not work at all)
2) I don't know how to save the model via the API

Any ideas ?

Eve

  • EA Administrator
  • EA Guru
  • *****
  • Posts: 8078
  • Karma: +118/-20
    • View Profile
Re: Java API for reading/writing the model
« Reply #10 on: March 18, 2007, 01:05:26 pm »
1) Try calling Repository.ShowWindow(1)
2) Call the Update method on anything that you modify.

vorpatril

  • EA Novice
  • *
  • Posts: 8
  • Karma: +0/-0
  • I love YaBB 1G - SP1!
    • View Profile
Re: Java API for reading/writing the model
« Reply #11 on: March 19, 2007, 01:29:48 am »
Still not working  :(

Here is my code :
-------------------------------------
Repository repo = new Repository();
repo.ShowWindow(1);
boolean b = repo.OpenFile("mytest.eap");
Collection<Package> c = repo.GetModels();
Package pkg = c.GetAt((short)0);
String modelName = pkg.GetName();
Package p = (Package) pkg.GetPackages().AddNew("MyPkgName", "Nothing");
pkg.GetElements().Refresh();
pkg.Update();
repo.CloseFile();
repo.Exit();
-----------------------------------------------

The first line (call of "new Repository()") launches the "Evaluation Version of Entreprise Architect" window. I click "Continue Trial"

The second line (repo.ShowWindow(1)) does nothing

b is true : seems ok
modelName is the name of my model : seems ok
the new package I create seems ok

But at the end of the program nothing has changed : my model has not been changed.

jkorman

  • EA User
  • **
  • Posts: 99
  • Karma: +0/-0
    • View Profile
Re: Java API for reading/writing the model
« Reply #12 on: March 19, 2007, 10:02:09 am »
You're almost there.....

Code: [Select]

Package p = pkg.GetPackages().AddNew("MyPkgName", "Nothing");
p.Update();  // Update what you're adding!!
pkg.GetPackages().Refresh(); // refresh the collection.


Seems to do the job.

I can run this with the EA application open, just have to refresh the project for stuff to show up.

BTW - You don't need to cast the return from GetPackages()

Jim

vorpatril

  • EA Novice
  • *
  • Posts: 8
  • Karma: +0/-0
  • I love YaBB 1G - SP1!
    • View Profile
Re: Java API for reading/writing the model
« Reply #13 on: March 21, 2007, 01:27:39 am »
Ok, it works !!!
Thank you very much for your help.

1) I open my project in EA.
2) I launch my test
3) I update the project in EA and I can see my package

Now I have a little question :

I would like to create a Java application that uses the EA API and I want to be notified when UML elements are created/modified/deleted in EA (running simultaneously).

So the question is : is there a event/listening system ?

«Midnight»

  • EA Guru
  • *****
  • Posts: 5651
  • Karma: +0/-0
  • That nice Mister Grey
    • View Profile
Re: Java API for reading/writing the model
« Reply #14 on: March 21, 2007, 02:11:10 am »
Yes there is. You'll probably have to load the application as an add-in. Check the documentation for the events. In the table of contents look under Automation and Scripting | Add-Ins | Broadcast Events.
No, you can't have it!