Book a Demo

Author Topic: java forward/reverse/synch  (Read 8796 times)

tanja

  • EA User
  • **
  • Posts: 71
  • Karma: +0/-0
    • View Profile
java forward/reverse/synch
« on: October 05, 2005, 06:47:23 am »
Hello,

I've posted a topic at <http://www.sparxsystems.com.au/cgi-bin/yabb/YaBB.pl?board=general;action=display;num=1124737672;start=0#0>, and for the first time since visiting this Forum, got no answers. I concluded that it must be because I was not polite enough :-), but I might be wrong. So, while presenting my excuses for somewhat iritated mood for the previous post, I give it another try, in hope that some kind soul would help me with a workaround, or simply confirm there is an issue.

I've played more with synchronisation from java code into model. In all what follows, the associations have roles explicitly defined on both sides, with cardinalities (i.e., the two classes reference each other). Here the conclusions:
- an array in the code produces 2 uni-directional association in model- I found no way to make them a single, direction agnostic one;
- any java member that is not a Collection (e.g., ArrayList) produces a single uni-directional link (the second one is lost somewhere). This boils down to associations with UML cardinalities 1 and 0..1, i.e., anything that is not considered as a collection in general;
-  the only correct handling of associations between two classes (I mean: you already have a non-directed association with both roles specified) after reverse synch is where at least one role has multiplicity 0..* or 1..*, i.e., where I have java ArrayList in my code (this doesn't work for arrays, as stated above).

It would be more than useful to have an explicit list of mappings for code engineering, which would save some time for developers/modellers.

With hope somebody hears me ...


Eve

  • EA Administrator
  • EA Guru
  • *****
  • Posts: 8110
  • Karma: +119/-20
    • View Profile
Re: java forward/reverse/synch
« Reply #1 on: October 10, 2005, 05:44:44 pm »
I'm sorry, I'd like to help but I'm not actually sure what is going on/what you're expecting to see.

thomaskilian

  • Guest
Re: java forward/reverse/synch
« Reply #2 on: October 11, 2005, 12:21:41 am »
Probably it would help to break it down in single questions instead of "Houston, we have a problem" ;)

tanja

  • EA User
  • **
  • Posts: 71
  • Karma: +0/-0
    • View Profile
Re: java forward/reverse/synch
« Reply #3 on: October 30, 2005, 03:22:58 am »
Sorry for my late reply, but I was away for a few weeks.

My problem is related to associations handling when forward and reverse engineering.

Background:
-----------------
The original model was in Rational Rose. All the associations were with unspecified direction, but both ends of each and every association have a name. This means that, in the diagram there are no arrows at any association end, but the associations are in fact bi-directional (as both ends are named). If class A has a member of class B, then B also has a member of A (you can extrapolate this to any cardinality).

Yes, I know that the 'unspecified' direction is inherently wrong if bi-directional is meant, but I cannot change the modellers who are in a standards' committee :-), while I have to deal with the model they produced. Since they've been using Rose for modelling, and in Rose associations are by default with unspecified direction, all the associations are so. The model itself is an ontology, so it is important to have names at both ends of each association. Also, the standard does not want to explicitly state all the directions, in order to allow for implementation flexibility.

From Rose to EA:
---------------------
Now, I've exported Rose model into XMI and imported into EA - so far so good.

In EA - code generation and manual fixes:
-----------------------------------------------------
I started forward engineering from UML to java and stumbled over several problems. Some of them I could solve by manually fixing problems in each and every of about 500 files (now you understand why I was a bit irritated in my first posting):
- imports were missing in .java files
- for each association, EA generated member variables for only one class; e.g., for association between A and B, A had a member of type, but B had not a member of type A.

In EA - reverse engineering/synch and what I couldn't fix:
------------------------------------------------------------------------
After the above issues have been fixed, and the whole code could compile, I've started reverse engineering from the code into the model: In project browser, I select a package, and from its context menu (right mouse click) I select Code Engineering -> Synchronise package contents -> Reverse engineer (source->model). This is now my only mode of operation, since I have my code as master source.

What I would like to preserve in the UML model is the ***single association of unspecified direction*** in the case of each two classes A and B pointing to each other, for every possible cardinality implementation (collection, array, single value). This is what I mean by "normal".

My problem is that EA does synchronisation differently as a function of what I use in my code to implement the cardinalities. Here 3 examples:

1) The case of a java collection at any or both sides produces (or better said: preserves) the single association of unspecified direction in the model. Example:
public class A {
 private ArrayList<B> myBs; // card. [1..*] or [0..*]
}
public class B {
 private A myA;  // card. [1] or [0..1]
}

2) The case of a java array DOES NOT preserve the original association in the model.  It creates two uni-directional associations. Example:
public class A {
 private B[] myBs; // card. [1..*] or [0..*]
}
public class B {
 private A myA;  // card. [1] or [0..1]
}

3) The case of a single value at both sides DOES NOT preserve the original association in the model. It creates two uni-directional associations. Example:
public class A {
 private B myB; // card. [1] or [0..1]
}
public class B {
 private A myA; // card. [1] or [0..1]
}

So, please tell me how I could make the cases 2) and 3) behave as case 1)? In particular, the non-coherent result produced by EA for the 3 cases above is somewhat disturbing, and limits me in the implementation choice if I want to preserve the model.

Hope this one was not "Houston, we have a problem" :-)

Thanx in advance!

Eve

  • EA Administrator
  • EA Guru
  • *****
  • Posts: 8110
  • Karma: +119/-20
    • View Profile
Re: java forward/reverse/synch
« Reply #4 on: October 30, 2005, 04:17:40 pm »
Your description this time is much clearer.

Unfortunately, I think you're not going to like my answer.

Case 1 isn't becoming two separate associations because EA only creates an association when the type of the attribute matches the class name.  In this case it doesn't match.

Have you tried setting the direction of the single association to bi-directional before reversing the code?  I think EA should then recognise the association as the same and not create a new one.

tanja

  • EA User
  • **
  • Posts: 71
  • Karma: +0/-0
    • View Profile
Re: java forward/reverse/synch
« Reply #5 on: October 31, 2005, 01:06:09 am »
Thanx for so quick feedback!

I've retried yesterday all three cases after I sent out the posting, by first deleting completely an existing association in the model.

Worth mentioning is that in Synch options, I keep existing associations, if I remember well, I did so because I've seen some associations disappear in the very beginning.

So, here the results when doing synch from code -> model, where I first delete the association in question from the model and let EA generate them from the code:

1) with a java collection, EA creates ONE (not two) directed association. If I make it, by hand, of unspecified direction, and I add the other (missing) association end name and cardinalities, and then repeat the synch, the association stays as I modified it, i.e., as I would like to have them all (this is probably because of the synch local option to not remove existing associations).

2, 3) with a java array or a single valued field, EA creates 2 uni-directional associations. If I try, by hand, to remove one and adjust the remaining one as above (make it unspecified direction, add cardinalities, add the name of the other association end), then synch again, EA keeps what I modified but also adds a single uni-directional association that I've deleted by hand.

What else to try?

Eve

  • EA Administrator
  • EA Guru
  • *****
  • Posts: 8110
  • Karma: +119/-20
    • View Profile
Re: java forward/reverse/synch
« Reply #6 on: October 31, 2005, 02:46:24 pm »
As I said in my previous email.  Try setting the direction to bi-directional.

I just checked and this does work.

tanja

  • EA User
  • **
  • Posts: 71
  • Karma: +0/-0
    • View Profile
Re: java forward/reverse/synch
« Reply #7 on: November 01, 2005, 01:51:06 am »
I know it would work with bi-directional, but then I'm modifying the original model (an international standard that shouldn't be modified), which has *unspecified* directions.

The people in the standards committee were considering moving from Rose to some other tool, but this might be a stopper for them to use EA ...

Thanx anyway for replies !

mikewhit

  • EA User
  • **
  • Posts: 608
  • Karma: +0/-0
  • Accessing ....
    • View Profile
Re: java forward/reverse/synch
« Reply #8 on: November 01, 2005, 03:47:55 am »
Eventually, someone's going to write an EA scripting tool to allow the model elements to be operated on "natively", probably using Perl or Python operating on the Automation interface.

But sadly, I don't have the time to do that :-(

However, it might be something for Mr. Sparx to consider, where you want to make structured transformations within a model.

Or is there already an OMG definition for this functionality ?

rhk

  • EA Novice
  • *
  • Posts: 4
  • Karma: +0/-0
  • I love YaBB 1G - SP1!
    • View Profile
Re: java forward/reverse/synch
« Reply #9 on: December 01, 2005, 06:42:28 am »
Maybe my question is a little off-topic, but not at all.

I have a problem, generating java code from classes with collection attributes.

The class "A" has a property named "x" and the type of "x" is the Class "B". In the detail dialog for the property x I have set the multiplicity to 0..* and have set the Container Type of the Collection to java.util.Set. Additionally I've checked the "attribute is a Collection".

The code-generator produces confused code:

public class A {
   private B xjava.util.Set;
}

So it just adds the "Container Type" behind the propertyname without a whitespace. :o

But what I expect to be generated is:

public class A {
   private java.util.Set<B> x;
}

How can this be solved?

Thx,
Robert

Eve

  • EA Administrator
  • EA Guru
  • *****
  • Posts: 8110
  • Karma: +119/-20
    • View Profile
Re: java forward/reverse/synch
« Reply #10 on: December 01, 2005, 01:56:39 pm »
The default templates assume that you are using the attribute is a collection etc. with a simple array.

If you want to use it in the fasion you have described you'll need to modify the templates for that.

rhk

  • EA Novice
  • *
  • Posts: 4
  • Karma: +0/-0
  • I love YaBB 1G - SP1!
    • View Profile
Re: java forward/reverse/synch
« Reply #11 on: December 02, 2005, 08:22:28 am »
Hi,

ok I've modified the template.

Is there a possibility to modify the "reverse" template so that  reverse engineering will produce the correct diagram?

Is there a possibility to change a template when EA produces Getters and Setters for a property with a Container Type?

Would be very nice!

Robert

orientphoebus

  • EA Novice
  • *
  • Posts: 18
  • Karma: +0/-0
  • I love YaBB 1G - SP1!
    • View Profile
Re: java forward/reverse/synch
« Reply #12 on: December 02, 2005, 09:34:04 am »
RHK,

Please post here how you finished the "Forward" part.

For the forward part, one-to-many relationship, by default, EA doesn't generate like this:

Quote
public ClassB[] classB;


Many other Case tool do this.
Thanks
« Last Edit: December 02, 2005, 09:40:04 am by orientphoebus »

rhk

  • EA Novice
  • *
  • Posts: 4
  • Karma: +0/-0
  • I love YaBB 1G - SP1!
    • View Profile
Re: java forward/reverse/synch
« Reply #13 on: December 02, 2005, 10:48:06 am »
can you please stall till monday... I've changed the templates at my desktop pc in the office, so monday I will post it.

sorry

r.

orientphoebus

  • EA Novice
  • *
  • Posts: 18
  • Karma: +0/-0
  • I love YaBB 1G - SP1!
    • View Profile
Re: java forward/reverse/synch
« Reply #14 on: December 02, 2005, 11:21:08 am »
Sure thanks, I just got mine "Forward" working:
http://www.sparxsystems.com.au/cgi-bin/yabb/YaBB.pl?board=suggestions;action=display;num=1133559390

Please post yours if it's different.

for the "reverse", is what "Transformation templates... Ctrl+Alt+H" for? The online help really doesn't help much here.

RHK,
A question for you as you just come from Rose world. I have not use it for a long time:
How is rose support Qualified Collections when doing Code Engineering? Can it deal with roundtrip for this kind of code?
Quote
public class ClassA{
      public Map<string, ClassB> listBs;
}


« Last Edit: December 02, 2005, 02:55:28 pm by orientphoebus »