Author Topic: Code generation for UML objects  (Read 4081 times)

Jim Beck

  • EA User
  • **
  • Posts: 29
  • Karma: +0/-0
    • View Profile
Code generation for UML objects
« on: February 24, 2010, 10:04:19 am »
Hello.  I am dragging classes onto a diagram and creating object instances with them.  I'd like to generate code for these and supply my own code templates, but the "Generate code..." right-click option is disabled for object instances.  The code template framework does not seem to address object instances.

I know that because these objects are in the model that I will be able to iterate through them and create code from an add-in.  Because the code generation is disabled for object instances, I'm not sure how I'll get to that point!  (Perhaps I'll make my own code framework that is all in an add-on.  That would be a shame however.)

Any ideas?  I'll keep you posted.  Thanks,

Jim

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13404
  • Karma: +567/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Code generation for UML objects
« Reply #1 on: February 24, 2010, 06:09:21 pm »
Jim,

I'm not following, why are you trying to generate code of of objects and not classes?
Objects live at runtime and are usually not implemented as code are they?
I'm confused :-?

Geert

Jim Beck

  • EA User
  • **
  • Posts: 29
  • Karma: +0/-0
    • View Profile
Re: Code generation for UML objects
« Reply #2 on: February 24, 2010, 06:30:33 pm »
Hello Geert.  We are basically trying to create Rational Rose RT in EA.  As such, we want to define classes with ports.  Messages come in the ports and make state transitions happen in a state machine that is in the class.  We connect ports with connectors at design time or using a pub-sub registration at run-time.  For connections made at design-time, we connect instances of classes together that are contained in another class.  This contianing class has the code that makes the connections happen.  Our applications are made of many such instacnes that are connected.

In fact, this is the way that Rational Rhapsody works.  We don't want to make our instances manually, but rather define them in the tool.

Thanks for your reply!

Jim

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13404
  • Karma: +567/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Code generation for UML objects
« Reply #3 on: February 24, 2010, 06:45:14 pm »
Ah, ok , i get it.
So you have some generic "messaging" classes (building blocks) that can be put together at runtime to provide the required behavior.

So in fact you are trying to generate the "behavior" part of the code (creating and connecting the right instances) rather then the "structural" part.
I'm not sure about the current state of affairs in EA, but usually behavior generation isn't really supported all that well in case tools such as EA.

I believe (without proof) that it might be faster to roll your own then to try and get EA's code generator to do the job.

Geert

Jim Beck

  • EA User
  • **
  • Posts: 29
  • Karma: +0/-0
    • View Profile
Re: Code generation for UML objects
« Reply #4 on: February 25, 2010, 02:39:29 am »
I'm beginning to suspect that.  Thanks for your input!

Jim

Jim Beck

  • EA User
  • **
  • Posts: 29
  • Karma: +0/-0
    • View Profile
Re: Code generation for UML objects
« Reply #5 on: February 25, 2010, 03:37:33 am »
Upon re-reading your reply, I wanted to point out that we are generating structure, at least what we consider structure.  Having one class contain two others and connecting them means structure to me (it was even called that In Rose RT :)).

Originally I tried using UML parts to show this, but there didn't seem to be a way to show and connect ports on parts, whereas you can if you use object instances (via a semi-obscure menu choice when dragging a class to a diagram - make it an instance - then don't select either of the radio button choices and check on option to include ports.)

Anyway, in the end we may be using EA as mostly as a diagramming tool and an IDE, with as many extra features as Sparx cares to heap on (which they seem to be doing with rapidity).  The rest we may do via add-ins, so I'm really glad that is an option.

The only thing stopping this approach (making our own code generator accessed via menu option that we create in an add-in) from being super clean is that the object model is somewhat non-obvious and I imagine they may change that at any time whereas the code templates  are there to provide a stable interface for iterating model elements.

Anyway, I will forge ahead!

Jim