Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » M2T (model-to-text transformation) » [Xpand] Using dynamic emf metamodel with Xpand
[Xpand] Using dynamic emf metamodel with Xpand [message #740250] Tue, 18 October 2011 10:03 Go to next message
Anders S is currently offline Anders SFriend
Messages: 29
Registered: February 2011
Junior Member
I have a DSM which I want to generate code from. This DSM has a metamodel which in its turn is specified in ecore. Using the DSM's metamodel in Xpand works, but is unecessary complex, since the DSM only uses a subset of the metamodel.

What I want to do is use the DSM as metamodel for Xpand. For now I have mapped the DSM to ecore programmatically; basically traversing the graph and creating EClasses, EAttributes etc.

My problem is that I cant figure out how to initialize Xpand with this model. Is it not possible to use registerMetaModel on the XpandExecutionContext?
Re: [Xpand] Using dynamic emf metamodel with Xpand [message #740321 is a reply to message #740250] Tue, 18 October 2011 11:41 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14664
Registered: July 2009
Senior Member
Hi,

this should be same as it was years ago

(A) use registerecorefile=... in standaloensetup + emfregistrymetamodel
(b) use emfmetamodel + metamodelfile=...

~Christian


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: [Xpand] Using dynamic emf metamodel with Xpand [message #740433 is a reply to message #740321] Tue, 18 October 2011 14:00 Go to previous messageGo to next message
Tatiana Fesenko is currently offline Tatiana FesenkoFriend
Messages: 62
Registered: July 2009
Member
Hi navlelo,

> (b) use emfmetamodel + metamodelfile=...

It will look like that in your MWE file:

<bean id="my_mm" class="org.eclipse.xtend.typesystem.emf.EmfMetaModel">
<metaModelFile value="com/my/myMetamodel.ecore"/>
</bean>

Best wishes,
Tanya.

On 10/18/11 1:41 PM, Christian Dietrich wrote:
> Hi,
>
> this should be same as it was years ago
> (A) use registerecorefile=... in standaloensetup + emfregistrymetamodel
> (b) use emfmetamodel + metamodelfile=...
>
> ~Christian
Re: [Xpand] Using dynamic emf metamodel with Xpand [message #740612 is a reply to message #740433] Tue, 18 October 2011 17:59 Go to previous messageGo to next message
Anders S is currently offline Anders SFriend
Messages: 29
Registered: February 2011
Junior Member
Im not really using a workflow file. And the model is also created on the fly, so I dont have any ecore file.

My problem right now is that the namespace for my package isnt recognized by Xpand.

I am pretty new to Xpand, so please bear with me Smile
Re: [Xpand] Using dynamic emf metamodel with Xpand [message #740623 is a reply to message #740612] Tue, 18 October 2011 18:12 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14664
Registered: July 2009
Senior Member
Hi,

can you share sample code of what you are exactly doing?

~Christian


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: [Xpand] Using dynamic emf metamodel with Xpand [message #740635 is a reply to message #740623] Tue, 18 October 2011 18:28 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14664
Registered: July 2009
Senior Member
btw something like

package test;

import org.eclipse.emf.ecore.EAttribute;
import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.EFactory;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.EPackage;
import org.eclipse.emf.ecore.EcoreFactory;
import org.eclipse.emf.ecore.EcorePackage;
import org.eclipse.internal.xpand2.pr.ProtectedRegionResolver;
import org.eclipse.internal.xpand2.pr.ProtectedRegionResolverImpl;
import org.eclipse.xpand2.XpandExecutionContextImpl;
import org.eclipse.xpand2.XpandFacade;
import org.eclipse.xpand2.output.Outlet;
import org.eclipse.xpand2.output.Output;
import org.eclipse.xpand2.output.OutputImpl;
import org.eclipse.xtend.typesystem.emf.EmfMetaModel;

public class Main {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		EcoreFactory ecoreFactory = EcoreFactory.eINSTANCE;
		EPackage p = ecoreFactory.createEPackage();
		p.setName("test");
		p.setNsPrefix("test");
		p.setNsURI("http://www.example.com/test");
		EClass c = ecoreFactory.createEClass();
		c.setName("Test");
		p.getEClassifiers().add(c);
		EAttribute a = ecoreFactory.createEAttribute();
		a.setName("name");
		a.setEType(EcorePackage.Literals.ESTRING);
		c.getEStructuralFeatures().add(a);
		
		EFactory instanceFactory = p.getEFactoryInstance();
		EObject model = instanceFactory.create(c);
		model.eSet(a, "Das ist ein Test");
		
		Output output = new OutputImpl();
		Outlet outlet = new Outlet("src-gen");
		output.addOutlet(outlet );
		ProtectedRegionResolver prs = new ProtectedRegionResolverImpl();
		XpandExecutionContextImpl execCtx = new XpandExecutionContextImpl(output, prs);
		execCtx.registerMetaModel(new EmfMetaModel(p));
		XpandFacade.create(execCtx).evaluate("test::test::main", model);
		

	}

}



works for me - of course without editor support

~Christian


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: [Xpand] Using dynamic emf metamodel with Xpand [message #741280 is a reply to message #740635] Wed, 19 October 2011 11:17 Go to previous messageGo to next message
Anders S is currently offline Anders SFriend
Messages: 29
Registered: February 2011
Junior Member
Im basically trying to accomplish what your last example showed. Thank you!
When writing the template, do I import the model with the ns prefix?

Is it possible to use dynamic EMF and still get the editor support?


In the Xpand documentation there is briefly mentioned the option to implement your own metamodel. The most elegant solution for my problem would probably be to implement my DSM as an Xpand metamodel instead of the dynamic EMF "workaround". Am I right in this? Are there any example code on creating your own mm (or perhaps a bit more documentation)?
Re: [Xpand] Using dynamic emf metamodel with Xpand [message #741285 is a reply to message #741280] Wed, 19 October 2011 11:24 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14664
Registered: July 2009
Senior Member
Hi,

(1) you import the name of the epackage
(2) you need an ecore but not the ecore java classes.
(3) no i fear there is not much documentation - so you have to have a look at the existing ones.
is the DSM something completly own or what is it exactly?

~Christian


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: [Xpand] Using dynamic emf metamodel with Xpand [message #741315 is a reply to message #741285] Wed, 19 October 2011 12:14 Go to previous messageGo to next message
Anders S is currently offline Anders SFriend
Messages: 29
Registered: February 2011
Junior Member
The DSM is specified in a graph based framework (for metamodeling), which is modeled in ecore. The DSM itself describes Domain Classes, Attributes etc. Pretty simple stuff.

Its pretty simple to map the DSM directly to ecore, but it's not an elegant solution imo. Also it defeats the purpose if I can't have editor support Sad
Re: [Xpand] Using dynamic emf metamodel with Xpand [message #741320 is a reply to message #741315] Wed, 19 October 2011 12:23 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14664
Registered: July 2009
Senior Member
Hi,

what is wanted to know - what is technically behind dsm?

~Christian


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: [Xpand] Using dynamic emf metamodel with Xpand [message #741332 is a reply to message #741320] Wed, 19 October 2011 12:33 Go to previous messageGo to next message
Anders S is currently offline Anders SFriend
Messages: 29
Registered: February 2011
Junior Member
It's a framework called Diagram Predicate Framework: http://dpf.hib.no/

The DSM is stored as a xmi file.
Re: [Xpand] Using dynamic emf metamodel with Xpand [message #741348 is a reply to message #741332] Wed, 19 October 2011 12:50 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14664
Registered: July 2009
Senior Member
Hi,

does the framework give you a java version of the xmi too?
if yes use the javabeansmetamodel

~Christian


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: [Xpand] Using dynamic emf metamodel with Xpand [message #741375 is a reply to message #741348] Wed, 19 October 2011 13:23 Go to previous messageGo to next message
Anders S is currently offline Anders SFriend
Messages: 29
Registered: February 2011
Junior Member
Unfortunately it doesnt.
Re: [Xpand] Using dynamic emf metamodel with Xpand [message #741586 is a reply to message #741375] Wed, 19 October 2011 17:28 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14664
Registered: July 2009
Senior Member
Hi,

i just installed the stuff. it is ecore you you can directly use it. cant you?
so where is the "additional" stuff that is not in the ecore?
can you share sample code of what you are doing?

~Christian


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de

[Updated on: Wed, 19 October 2011 17:34]

Report message to a moderator

Re: [Xpand] Using dynamic emf metamodel with Xpand [message #742214 is a reply to message #741586] Thu, 20 October 2011 09:38 Go to previous messageGo to next message
Anders S is currently offline Anders SFriend
Messages: 29
Registered: February 2011
Junior Member
The DSM looks like this:
http://i.imgur.com/wMaxT.png
It's pretty simple right now, but will in time be more advanced. It is supposed to model the MVC stuff in a web app.

Everything in DPF metamodel is Ecore. This metamodel consists of nodes and arrows (and constraints) which I type on each metalevel. The problem when using the DPF metamodel as Xpand metamodel is that I have to do stuff like this:
  DEFINE DomainClass FOR core::Node»
	«IF this.getTypeName() == "DomainClass"»
  ... 

When wanting to process a specific node type like "DomainClass", I have to iterate over all the nodes in the model, and compare on the name of the node. It becomes a LOT of iterations when the template grows. What I want to do is something like:
   DEFINE class FOR DomainClass
       doSomething
   ...


As for now, I think the solution/workaround would be to dynamically create ecore from the DSM and perhaps write an ecore from it, and then load it into Xpand. This would give me editor support, right?
Re: [Xpand] Using dynamic emf metamodel with Xpand [message #742285 is a reply to message #742214] Thu, 20 October 2011 11:02 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14664
Registered: July 2009
Senior Member
Hi,

or you write a own (Xpand)Metamodel(Contributor) that does this for you.

~Christian


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: [Xpand] Using dynamic emf metamodel with Xpand [message #742303 is a reply to message #742285] Thu, 20 October 2011 11:23 Go to previous messageGo to next message
Anders S is currently offline Anders SFriend
Messages: 29
Registered: February 2011
Junior Member
Care to elaborate a bit on that? Smile
Re: [Xpand] Using dynamic emf metamodel with Xpand [message #742357 is a reply to message #742303] Thu, 20 October 2011 12:24 Go to previous message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14664
Registered: July 2009
Senior Member
No,

you have to dig into the code of the existing subclasses of org.eclipse.xtend.typesystem.MetaModel
and MetamodelContributor

~Christian


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Previous Topic:[Acceleo] Annotations of templates
Next Topic:Generation with Acceleo failed since 3.1.0M7 but worked for 3.1.0M6a
Goto Forum:
  


Current Time: Tue Apr 16 05:56:55 GMT 2024

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

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

Back to the top