Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » MoDisco » Converting Java POJOs to EMF model
Converting Java POJOs to EMF model [message #1715081] Thu, 19 November 2015 05:03 Go to next message
Pascal Rapicault is currently offline Pascal RapicaultFriend
Messages: 333
Registered: July 2009
Location: Ottawa
Senior Member
Hi,

I have about 47 java classes in EGerrit (http://git.eclipse.org/c/egerrit/org.eclipse.egerrit.git/tree/org.eclipse.egerrit.core/src/org/eclipse/egerrit/core/rest) that are mostly data structures (no logic).
Now I am at a point where I regret my choice of POJOs and want to replace those by an EMF model and the corresponding generated classes.

I've started playing with Modisco in the hope to get help from this and it looks promising. After running the Java project discoverer, I have an EMF model that represents the code in great details which includes everything and more.

My question is now, given this model how to I get a "standard" EMF model that would only include the structural information of my program?

Thanks

Pascal

[Updated on: Thu, 19 November 2015 05:10]

Report message to a moderator

Re: Converting Java POJOs to EMF model [message #1715110 is a reply to message #1715081] Thu, 19 November 2015 10:41 Go to previous messageGo to next message
Hugo Bruneliere is currently offline Hugo BruneliereFriend
Messages: 674
Registered: July 2009
Senior Member
Hi,

Thanks for testing MoDisco.
The model that you obtain from initial discovery conforms to a full Java metamodel defined in Ecore.
We already have automated transformations to UML Class (via KDM in MoDisco, or direct Java-to-UMLClass from https://bugs.eclipse.org/bugs/show_bug.cgi?id=477598).
Could this correspond to what you need?

EMF Ecore has been initially designed to represent domain and/or data models.
In Java code, and thus in Java models, you usually have many (or at least some) classes that are technical/implementation ones.
As a consequence, producing a coherent Ecore model from a Java model is not so trivial in the general case: that's why we don't have such a generic transformation available so far.
But of course, it is always possible to hard-code a specific transformation for a given case(s) such as yours.
A UML-to-Ecore transformation filtering the required classes could be used to this intent.

Kind regards,


--------------------------------------------------------
Hugo Bruneliere, PhD
NaoMod team (IMT Atlantique & LS2N-CNRS)
Nantes - France
--------------------------------------------------------
Re: Converting Java POJOs to EMF model [message #1715147 is a reply to message #1715081] Thu, 19 November 2015 15:33 Go to previous messageGo to next message
Pascal Rapicault is currently offline Pascal RapicaultFriend
Messages: 333
Registered: July 2009
Location: Ottawa
Senior Member
Thanks Hugo. It now feels like I'm one step closer, but not there yet Smile
Using the Java-to-UML converter you provided, I've been able to get a class diagram.

Now, how should I proceed on run the UML-to-Ecore transform?
Sorry, if this is a stupid question, but I'm really new to Modisco (installed it for the first time less than 12h ago Smile) and model transforms but it really feels like it can help me.

Note that even if there was nothing that I could reuse, I would be happy to write code to produce my new model.

Thanks in advance,

Pascal
Re: Converting Java POJOs to EMF model [message #1715166 is a reply to message #1715147] Thu, 19 November 2015 17:40 Go to previous messageGo to next message
Hugo Bruneliere is currently offline Hugo BruneliereFriend
Messages: 674
Registered: July 2009
Senior Member
There are no stupid questions, just questions Smile
We don't have

There are actually several ways for you to implement your transformation:

  • Try the UML2EcoreConverter from the UML2 project (but I don't really know how it behaves in the general case)
  • Use a model-to-model transformation language such as ATL (https://eclipse.org/atl/).
  • Use plain Java code via the EMF API for Ecore and the UML2-specific API (please refer to these Eclipse projects for more details).
I hope this helps.


--------------------------------------------------------
Hugo Bruneliere, PhD
NaoMod team (IMT Atlantique & LS2N-CNRS)
Nantes - France
--------------------------------------------------------
Re: Converting Java POJOs to EMF model [message #1715190 is a reply to message #1715166] Fri, 20 November 2015 01:29 Go to previous messageGo to next message
Pascal Rapicault is currently offline Pascal RapicaultFriend
Messages: 333
Registered: July 2009
Location: Ottawa
Senior Member
Thanks, I'll give it a try and report on what I ended up doing.
Re: Converting Java POJOs to EMF model [message #1717288 is a reply to message #1715190] Fri, 11 December 2015 13:05 Go to previous messageGo to next message
Pascal Rapicault is currently offline Pascal RapicaultFriend
Messages: 333
Registered: July 2009
Location: Ottawa
Senior Member
I cna now declare success on this Smile

Here is what I've done:
- Use Modisco model discovery to extract a Java Model from the source code. This was trivial to do. Right click on the Java project from which I wanted to extract the source, configure, done. At this point I have a model of my Java program, but this is not following the ecore metamodel but a Java metamodel provided by modisco
- Use Modisco model discovery to extract a UML model from the Java model previously generated.

With this last model, I wrote a little bit of code that created an ecore based model. The code is relatively simple, it goes through all the classes listed in my UML model, and create EClasses from those. I managed to generate all but one attribute of my model, so I'm fairly happy.
I did not try ATL. This was mostly because it seemed more complex to comprehend.

Finally another solution that I came across but did not try is to generate an EMF model from a Json document.

HTH
Re: Converting Java POJOs to EMF model [message #1717322 is a reply to message #1717288] Fri, 11 December 2015 16:42 Go to previous message
Hugo Bruneliere is currently offline Hugo BruneliereFriend
Messages: 674
Registered: July 2009
Senior Member
Thanks a lot for the feedback.
Don't hesitate to tell us more about your experiments if any other Smile


--------------------------------------------------------
Hugo Bruneliere, PhD
NaoMod team (IMT Atlantique & LS2N-CNRS)
Nantes - France
--------------------------------------------------------
Previous Topic:AM3 project code whereabouts
Next Topic:XML Discoverer - standalone
Goto Forum:
  


Current Time: Thu Apr 25 03:32:33 GMT 2024

Powered by FUDForum. Page generated in 0.04279 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top