Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » M2T (model-to-text transformation) » [ACCELEO 3] problem using an ecore metamodel with hierarchical packages
[ACCELEO 3] problem using an ecore metamodel with hierarchical packages [message #659705] Tue, 15 March 2011 10:04 Go to next message
Marc Missing name is currently offline Marc Missing nameFriend
Messages: 38
Registered: March 2011
Member
Hello,

I'm currently evaluating different solutions for generating code from an EMF
model. The solution that seems to fit our needs is acceleo, but unfortunately,
I'm unable to make a simple example. I'll try to describe as precisely as
possible my setup so that maybe someone can point me in the correct direction to
find my problem.

I have created an ecore model that is hierarchically organized as a set of
packages with classes as leaf (upcase letters):
.
└── a
    └── b
        └── c
            ├── D
            ├── E
            ├── F
            └── G

Each one of this package has a nsPrefix/nsURI. Example for the package a.b.c:

Ns Prefix = a.b.c
Ns URI = http://a/b/c/1.0

For a.b:
Ns Prefix = a.b
Ns URI = http://a/b/1.0

When I create an accelo project, in the wizard, in the "Create a new Acceleo
generation file" (the one where you can add several "Module Files", I can fin my
model by clicking the "Browse" for "Metamodel URI" and selecting "Runtime
Version".
There, I can find my URIs:

http://a/1.0 http://a/b/1.0 http://a/b/c/1.0

Here, I'm not sure which one I'm supposed to select. I tried the one
corresponding to the package that contains the classes: http://a/b/c/1.0 and the
root package http://a/1.0.

Then I'm able to select the corresponding classe in the drop down menu "Generate
for type": D,E,F or G.

So far, it seems to work correctly...

The template does not show any error and I'm able to access my classe's
attributes/references. But for the first example, I keep the template untouched.

Then, I want to run the simple template on a model that uses my metamodel
describe before.

This model is serialized in an XMI file (I also try XSD, but this does not
change anything). I'm using the 'main' method created in the generated code. I
add a single line to register my package in some EMF registry:

public static void main(String[] args) {
EPackage.Registry.INSTANCE.put(DPackage.eNS_URI, DPackage.eINSTANCE);
...

I use an absolute path to the XMI file as first argument and an absolute path as
the second argument.

It runs... But the template is never applied.

After some digging using the debugger, I can see something that can be a
symptom:

at AcceleoService.java:374 (doGenerate method), the argument for the template is
read, and the the model loaded from my XMI is tested against this type: if they
are equals, the template is applied.
In my case, they are never the same.

My loaded model has correct types (DImpl and so on) whereas the "expected" type
in the template is EClassImpl. If I look this object, I can see it has an
"eProxyURI" that looks like:

http://a/1.0#//b/c/D

I've read that having this kind of proxy classes maybe a sign that something is
not registered in EMF correctly. I thought of registering the root package, but
as there is no generated java code, I can't use the same trick as above.

Then I tried to find documentation and/or examples on models with hierarchical
packages but couldn't find any. I've read the "EMF" book (2nd edition), but when
it comes to this URI/Prefix attributes, it's vague.

Sorry if this is too long, I tried to provide only & all needed information.

I can read doc and/or code, but as far as I've tried, I couldn't find anything
useful, even if google is my friend...
Re: [ACCELEO 3] problem using an ecore metamodel with hierarchical packages [message #659979 is a reply to message #659705] Wed, 16 March 2011 13:17 Go to previous messageGo to next message
Laurent Goubet is currently offline Laurent GoubetFriend
Messages: 1902
Registered: July 2009
Senior Member
Hi Marc,

If must admit I have never created a model with "empty" parent packages. If your need is only to provide a namespace, this can be handled through the genmodel. For example, if your package hierachy resembles something like :

fr
|----imag
      |----project
            |----ClassA
            |----ClassB


you should change it to

project
|----ClassA
|----ClassB


and use the genmodel to define your namespace, i.e set the genmodel's "basePackage" property to "fr.imag".

That being said, I don't really know how to prevent issues when you have multiple packages, that will need some investigation.

Laurent Goubet
Obeo
Re: [ACCELEO 3] problem using an ecore metamodel with hierarchical packages [message #660034 is a reply to message #659979] Wed, 16 March 2011 15:33 Go to previous message
Marc Missing name is currently offline Marc Missing nameFriend
Messages: 38
Registered: March 2011
Member
Laurent Goubet wrote on Wed, 16 March 2011 09:17

and use the genmodel to define your namespace, i.e set the genmodel's "basePackage" property to "fr.imag".

That being said, I don't really know how to prevent issues when you have multiple packages, that will need some investigation.



Hello,

thanks very much for you answer. I'll detail what I tested and what I've decided to do Smile

First, I tried your proposed solution, but I faced the same problem, mainly because my root package only contained packages, and I don't want to remove this hierarchy. So, to force the generation of the root package Java class by EMF, I created a "PlaceHolder" class. I also added "base package" to every package and subpackage in the model (that's a bit error prone...).

Then, I added the :

 EPackage.Registry.INSTANCE.put(XXXPackage.eNS_URI, XXXPackage.eINSTANCE);


and the acceleo generator worked.

But then, I wondered if I could do the same "trick" using my original model, without moving packages around and fine tuning the genmodel file. I added PlaceHolder class in every package that only contained packages, I registered the whole hierarchy in the acceleo generator, and it works Smile (note that I really needed to add placeholders in all package, only putting one at the root did not work).

I'm not sure whether this is a bug in acceleo, a design error in my model or if there is another way to force registration (ie. without the XXXPackage.eNS_URI & friend from EMF generated code).

But it was a pain to fix. Thanks *again* for your message, as I had already decided to drop acceleo and was looking for the next candidate.

I tried to give as many details as possible, as this may be useful for others.
Previous Topic:[JET] Weird behaviour with Jet Builder when it's translating the templates
Next Topic:Missing dependencies (xtend, xpand, emf.mwe)
Goto Forum:
  


Current Time: Fri Apr 26 01:02:10 GMT 2024

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

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

Back to the top