Book a Demo

Author Topic: 1-many associations in generated Java Code  (Read 4985 times)

cspowers

  • EA Novice
  • *
  • Posts: 18
  • Karma: +0/-0
  • I love YaBB 1 Gold!
    • View Profile
1-many associations in generated Java Code
« on: March 09, 2002, 06:22:04 am »
Howdy,

I'm failry new to UML and very new to EA, but I think I've found a bug in Java code generation.


I create an association between objects A and B and set up the multipliciites as a 1-0..* And I set "bidirectionall" as the diretion for the association, I expect that the generated Java code will have a reference in B to A, which I see. And in A, I see a reference to B, but it's just a single object. I'd expect that in A there should be some sort of container, like a collection or Vector that could contain multiple instances of B, because the multiplicity for B is marked 0..*.

Is this a bug? Or is there something I'm not understanding about associations?


(thought it looks fantastic so far!)

gsparks

  • EA User
  • **
  • Posts: 325
  • Karma: +0/-0
  • I love YaBB 1 Gold!
    • View Profile
Re: 1-many associations in generated Java Code
« Reply #1 on: March 09, 2002, 03:50:41 pm »
Hi,

This has been an ongoing problem .. due to the fact EA uses no code markers and on reparsing the source code an attribute of the collection type would be created without a direct link to the actual contained class.

For the next update of EA (build 470 or higher) I have made some changes to the Java code generator which will now support a generic collection class for object associations. You can set this in the code generation section of the Local Options dialog (Java options) ... for example set the collection class to Vector. All new classes you create will get this option as their default behaviour.

For classes you have already created, use the Advanced button on the code generation dialog to set the collection class.

The following will now happen:

If the target end of a link has a multiplicity (and not "0", "1", "0..1") and the collection class is set, then an attribute of the collection class type will be generated instead of the contained class.

On import (synchronize) the collection class will be imported as an attribute - but this is probably not an issue - in fact it does reflect the actual implementation details - a 1..many relationship to another class expressed thru the association and a collection class expressed thru the actual attribute.

In this case EA will not overwrite the attribute if it already exists by Name - so if you want to change something you will have to manually delete the exisiting variable from the code.

I suggest you get the latest build of EA (470 or higher) when it is released - (probably Monday) and test this out.

If anyone has some comments or suggestions on this I am open to ideas.

Once the Java behaviour is working OK Ill do the other languages the same.


Geoff Sparks