Book a Demo

Author Topic: Custom Code Generator  (Read 7955 times)

tmud

  • EA Novice
  • *
  • Posts: 3
  • Karma: +0/-0
    • View Profile
Custom Code Generator
« on: April 19, 2010, 10:55:01 pm »
Hello,

We currently use another iUML tool that has an API allowing us to traverse UML model elements. We use that API for our own C++ code generation purposes; that is, I'm able to read all data about the classes, relationships, operations, and so on.

We're considering a move to EA, as its considerably less expensive that our current tool.

The question is: does Enterprise Architect provide an API that allows me to obtain detailed information about the model?

Thanks  :)

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13523
  • Karma: +574/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller

tmud

  • EA Novice
  • *
  • Posts: 3
  • Karma: +0/-0
    • View Profile
Re: Custom Code Generator
« Reply #2 on: April 19, 2010, 11:28:02 pm »

Makulik

  • EA User
  • **
  • Posts: 400
  • Karma: +0/-0
    • View Profile
Re: Custom Code Generator
« Reply #3 on: April 20, 2010, 12:17:16 am »
Hi,

There's theoretically more than one way to implement your own "deviations" for code generation. EA's standard way to do this is to modifiy and adapt the code generation templates for the desired target language with your specific needs:
http://www.sparxsystems.com/uml_tool_guide/sdk_for_enterprise_architect/codetemplates_2.htm

Alternatively there's the EA automation API (http://www.sparxsystems.com/uml_tool_guide/sdk_for_enterprise_architect/theautomationinterface.htm), which allows traversing the UML model tree in your own AddIns or automation processes, and completely implement the code generation yourself.

HTH
g.

tmud

  • EA Novice
  • *
  • Posts: 3
  • Karma: +0/-0
    • View Profile
Re: Custom Code Generator
« Reply #4 on: April 20, 2010, 12:37:44 am »
Thanks for the help.

Does anyone know if the automation interfaces works using wine/crossover for linux?

Thanks.

Also, I noticed it's possible to specify a separate mySQL database for the repository. Is it possible to use SQL statements therefore to navigate through a model?

« Last Edit: April 20, 2010, 12:38:25 am by tmud »

Makulik

  • EA User
  • **
  • Posts: 400
  • Karma: +0/-0
    • View Profile
Re: Custom Code Generator
« Reply #5 on: April 20, 2010, 01:43:25 am »
Quote
Does anyone know if the automation interfaces works using wine/crossover for linux?

I'm not knowing for sure (because I didn't try that), but I think it should work.

Quote
Also, I noticed it's possible to specify a separate mySQL database for the repository. Is it possible to use SQL statements therefore to navigate through a model?
Yes, that's more or less possible (read only!), but IMHO the worst choice you can take (you have to interpret which information is stored how and where by EA.). That's true, independent of SQL-server DB repository usage or not.

My advice is, you should stick to the code templates 1st, and check out what you can do with theese. If that's not sufficient, consider the other alternatives (EA object model preferably).

HTH
Günther
« Last Edit: April 20, 2010, 01:52:14 am by Makulik »

beginner

  • Guest
Re: Custom Code Generator
« Reply #6 on: April 20, 2010, 04:32:30 am »
Years ago I decided to take the API for code generation since it is much more flexible. The macros are quite crude and absolutely Sparxish. Though you can start quite fast you end up in a cul-de-sac in the same speed. Honestly I do not understand why the whole code gen is not an integrated part of the API but such a macro scrap.

b.

Eve

  • EA Administrator
  • EA Guru
  • *****
  • Posts: 8110
  • Karma: +119/-20
    • View Profile
Re: Custom Code Generator
« Reply #7 on: April 20, 2010, 08:52:07 am »
The automation interface works under WINE, however I believe you need to program for it directly under COM because .Net still has issues under WINE.

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13523
  • Karma: +574/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Custom Code Generator
« Reply #8 on: April 20, 2010, 01:40:29 pm »
tmud,

I would use the API object rather then trying to use too much SQL.
The reason is that you can be reasonably sure the API interface will stay the same over different version, where the database structure could change.

They only reason I use SQL statements in my addins is because of performance issues.

If you need to traverse a model, and visit thousands of elements it can be interesting to use the Repository.GetElements with an SQL statement to get exactly the elements you need, rather then visiting them all one by one.

And I'm inclined to agree with beginner. From what I've seen about code generation templates, it looks very complicated, and very EA specific.
If you write your code generation addin in a decent way it should be pretty easy to port that code to another UML case tool.

Geert

Frank Horn

  • EA User
  • **
  • Posts: 535
  • Karma: +1/-0
    • View Profile
Re: Custom Code Generator
« Reply #9 on: April 20, 2010, 05:31:55 pm »
There's a  third approach to setting up your own code generation: create your code from XMI. Well, Geert doesn't like XMI, but I do.

What we are doing is (roughly) this:

- create a profile and an MDG technology to define class and connector stereotypes for the code patterns you want to use (e.g. serializable classes, event argument classes and the like);

- set up XSL transformations from XMI to text (i.e. to code in any programming language you prefer), perhaps in some steps (i.e transform to some sort of consolidated xmi, then to some sort of language-independent meta-code, then to code);

- for code generation (manually or via API), export a package containing all the information you need to XMI (we prefer XMI 2.1, but you can use older versions of course) and transform.

This has some advantages:

- ALL the model information is contained in XMI (while some is not accessible via API);

- most of the information is contained in a way that does not even rely on EA; you can switch to another tool when needed without having to write everything new from scratch.

Makulik

  • EA User
  • **
  • Posts: 400
  • Karma: +0/-0
    • View Profile
Re: Custom Code Generator
« Reply #10 on: April 20, 2010, 08:18:49 pm »
Quote
There's a  third approach to setting up your own code generation: create your code from XMI.

Good idea Frank. I just forgot to mention it, because I'm not using XSL-transforms for code generation, but for other things (e.g. generating a compact HTML requirements report). We also use XML and XSL for code generation, but not (yet) for XML exported with EA XMI export.

If there is a person skilled with XSL in the project, or easily could get skilled with it, that would be my preferred way also ...

WBR
g.