Sparx Systems Forum
Enterprise Architect => Automation Interface, Add-Ins and Tools => Topic started by: vorpatril 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.
-
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).
-
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.
-
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.
-
Thank you for your answers.
Ok, I've got the directory in the trial version.
Is there any documentation and / or examples ?
-
Sorry for my ignorance - I haven't updated my EA version since I stopped doing UML full-time :(
-
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
-
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.
-
Ok, I think I can start testing this API.
-
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 ?
-
1) Try calling Repository.ShowWindow(1)
2) Call the Update method on anything that you modify.
-
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.
-
You're almost there.....
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
-
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 ?
-
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.
-
I had a look at the documentation about the add-ins and the broadcast events.
Is it possible to write add-ins in Java ?
(as far as I know it is not possible for the moment but I might be wrong)
-
No, the readme for the Java API states that Java addins are not supported.
However, it should be theoretically possible to write a COM add-in that queries you java application for what methods there are, tells COM that it provides them and passes on the calls to Java. I just haven't had time yet to prove the concept.
-
Ok, I understand.
Thank you for your help.