Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » Epsilon » Loading models into IModel objects(Load a dynamically built model from memory, rather than from a file?)
Loading models into IModel objects [message #539413] Thu, 10 June 2010 12:07 Go to next message
Stephen Barrett is currently offline Stephen Barrett
Messages: 46
Registered: May 2010
Member
Hello Epsilon Fans,

I've looked through the source, and don't see that what I want is provided for, but I thought I would ask anyway:

I am constructing UML2 models in Java which I want to manipulate with the Epsilon family of languages, also running in Java. Is it possible to load an IModel object directly with a UML2 model (or something similar)? Or maybe accomplish the same thing by specifying a URI scheme other than file:// for the PROPERTY_MODEL_FILE property?

This would save having to write a model out to an XMI file right after building it, only to turn around and read it back in again into an EmfModel. And it would also save having to unravel filesystem paths, permissions, etc., which is a consideration for standalone tools.

That being said, this is not a critical item, more of a "Wouldn't it be nice?" kind of thing.

Regards,
--Stephen
Re: Loading models into IModel objects [message #539428 is a reply to message #539413] Thu, 10 June 2010 13:03 Go to previous messageGo to next message
Louis Rose is currently offline Louis Rose
Messages: 439
Registered: July 2009
Location: York, United Kingdom
Senior Member
Hi Stephen,

Thanks for the interest. Sure, I think InMemoryEmfModel is a perfect fit for this case.

Presuming that you're invoking Epsilon from Java, you can use code similar to this:

final InMemoryEmfModel model = new InMemoryEmfModel("NameOfYourModel", resource, UmlPackage.eINSTANCE);


where resource is an instance of EMF's Resource interface.

The in-memory model can then be used with Epsilon just like any other model. The following code, for example, could be use the in-memory model with EGL to generate some text:

final IEglContext context = new EglContext();
context.getModelRepository().addModel(model);

final EglFileGeneratingTemplateFactory factory = new EglFileGeneratingTemplateFactory(context);

final EglFileGeneratingTemplate template = factory.load(aUriOrFileToYourEglTemplate);

template.process();

// or use template.generate(...) if you want to 
// store the results of the main template to disk


I hope this helps.

Cheers,
Louis.


[Updated on: Thu, 10 June 2010 13:04]

Report message to a moderator

Re: Loading models into IModel objects [message #539430 is a reply to message #539413] Thu, 10 June 2010 13:01 Go to previous messageGo to next message
Dimitrios Kolovos is currently offline Dimitrios Kolovos
Messages: 1776
Registered: July 2009
Senior Member
Hi Stephen,

You can use InMemoryEmfModel to access loaded EMF Resources from Epsilon
programs.

Cheers,
Dimitris

On 10/06/2010 19:07, Stephen Barrett wrote:
> Hello Epsilon Fans,
>
> I've looked through the source, and don't see that what I want is
> provided for, but I thought I would ask anyway:
>
> I am constructing UML2 models in Java which I want to manipulate with
> the Epsilon family of languages, also running in Java. Is it possible to
> load an IModel object directly with a UML2 model (or something similar)?
> Or maybe accomplish the same thing by specifying a URI scheme other than
> file:// for the PROPERTY_MODEL_FILE property?
>
> This would save having to write a model out to an XMI file right after
> building it, only to turn around and read it back in again into an
> EmfModel. And it would also save having to unravel filesystem paths,
> permissions, etc., which is a consideration for standalone tools.
>
> That being said, this is not a critical item, more of a "Wouldn't it be
> nice?" kind of thing.
>
> Regards,
> --Stephen
Re: Loading models into IModel objects [message #539578 is a reply to message #539428] Fri, 11 June 2010 08:16 Go to previous messageGo to next message
Stephen Barrett is currently offline Stephen Barrett
Messages: 46
Registered: May 2010
Member
I think you're right guys. I found InMemoryEmfModel after more digging, and it fits the bill exactly. Thanks for the confirmation!

Regards,
--Stephen
Re: Loading models into IModel objects [message #541780 is a reply to message #539578] Tue, 22 June 2010 09:57 Go to previous messageGo to next message
Stephen Barrett is currently offline Stephen Barrett
Messages: 46
Registered: May 2010
Member
Hi,

I'm finally back to this issue of loading a UML model from an XMIResource instead of a file. You all gave me the right answer, but there is a bit of a catch I thought I would mention in case some one else is trying to do the same thing. Namely, the model resource needs to be part of a set, even if it's the only thing in the set. Otherwise Epsilon throws an exception. So here's the working Java code:

IEolExecutableModule module;

...

ResourceSet res_set = new ResourceSetImpl();
res_set.getResources().add(uml_model);

InMemoryEmfModel model = 
    new InMemoryEmfModel("UML", uml_model, UMLPackage.eNS_URI);
module.getContext().getModelRepository().addModel(model);


--Stephen
Re: Loading models into IModel objects [message #541792 is a reply to message #541780] Tue, 22 June 2010 10:01 Go to previous messageGo to next message
Dimitrios Kolovos is currently offline Dimitrios Kolovos
Messages: 1776
Registered: July 2009
Senior Member
Hi Stephen,

Many thanks for reporting back on this! Could you please file a bug
report for this?

Cheers,
Dimitris

Stephen Barrett wrote:
> Hi,
>
> I'm finally back to this issue of loading a UML model from an
> XMIResource instead of a file. You all gave me the right answer, but
> there is a bit of a catch I thought I would mention in case some one
> else is trying to do the same thing. Namely, the model resource needs to
> be part of a set, even if it's the only thing in the set. Otherwise
> Epsilon throws an exception. So here's the working Java code:
>
>
> IEolExecutableModule module;
>
> ..
>
> ResourceSet res_set = new ResourceSetImpl();
> res_set.getResources().add(uml_model);
>
> InMemoryEmfModel model = new InMemoryEmfModel("UML", uml_model,
> UMLPackage.eNS_URI);
> module.getContext().getModelRepository().addModel(model);
>
>
> --Stephen
Re: Loading models into IModel objects [message #541798 is a reply to message #541792] Tue, 22 June 2010 10:41 Go to previous messageGo to next message
Stephen Barrett is currently offline Stephen Barrett
Messages: 46
Registered: May 2010
Member
If you consider this a bug, I'll file a report Dimitris.

Cheers,
--Stephen
Re: Loading models into IModel objects [message #541961 is a reply to message #541798] Wed, 23 June 2010 07:28 Go to previous messageGo to next message
Dimitrios Kolovos is currently offline Dimitrios Kolovos
Messages: 1776
Registered: July 2009
Senior Member
Hi Stephen,

It's not a major bug but it probably makes sense to perform this check
and add the resource to a set in case it is does not already belong to
one within InMemoryModel.

Cheers,
Dimitris

Stephen Barrett wrote:
> If you consider this a bug, I'll file a report Dimitris.
>
> Cheers,
> --Stephen
Re: Loading models into IModel objects [message #549051 is a reply to message #541961] Fri, 23 July 2010 17:27 Go to previous messageGo to next message
Stephen Barrett is currently offline Stephen Barrett
Messages: 46
Registered: May 2010
Member
Dimitris, Louis,

I somehow managed to break my previously working code. I switched from using a UML to an Ecore model. The new code for the left XMIResource looks like this:

new ResourceSetImpl().getResources().add(xmi_model_lf);
module.getContext().getModelRepository().addModel(
    new InMemoryEmfModel("Left", xmi_model_lf, EcorePackage.eNS_URI));


The right is similar. When I try to execute an ECL module that has successfully parsed a rules file, Epsilon throws this error: Type 'Left!Model' not found ... @2:17

The relevant rule looks like this:

rule Models
  match l : Left!Model with r : Right!Model {
  compare : true
  do {
    matchInfo.put("mirador", 0.7);
  }
}


Which used to work just fine. It seems that the model names are not being registered, which make me think I missed a step. Any ideas?

--Stephen
Re: Loading models into IModel objects [message #549082 is a reply to message #549051] Sat, 24 July 2010 04:04 Go to previous messageGo to next message
Louis Rose is currently offline Louis Rose
Messages: 439
Registered: July 2009
Location: York, United Kingdom
Senior Member
Hi Stephen,

I think the error is occurring because the Ecore metamodel does not contain the Model type.

The Ecore metamodel is similar to the class diagram part of the UML metamodel, but not identical. There's a fairly good overview of the Ecore metamodel in the EMF javadoc: http://download.eclipse.org/modeling/emf/emf/javadoc/2.6.0/o rg/eclipse/emf/ecore/package-summary.html

You may need to create a new comparison for Ecore models that incorporates these differences (e.g. change Package to EPackage). Another alternative would be to write a transformation from Ecore to UML, and run that before running the comparison.

Perhaps Dimitris will have some ideas about this too.

Cheers,
Louis.

Re: Loading models into IModel objects [message #559740 is a reply to message #549082] Fri, 17 September 2010 15:49 Go to previous messageGo to next message
Stephen Barrett is currently offline Stephen Barrett
Messages: 46
Registered: May 2010
Member
Hello Louis,

Thanks for your help. Many months later I have finally gotten around to giving your idea a test.

Replacing Class with EClass, etc. in the ECL rules file does the trick. There is no Ecore EModel element however, but since this is only test code I just dropped that particular rule.

--Stephen

P.S. Will you guys be at MoDELS next month?
Re: Loading models into IModel objects [message #559836 is a reply to message #559740] Sun, 19 September 2010 15:52 Go to previous messageGo to next message
Louis Rose is currently offline Louis Rose
Messages: 439
Registered: July 2009
Location: York, United Kingdom
Senior Member
Hi Stephen,

Great, I'm glad it worked. I believe that Ecore's EPackage is probably the concept closest to the notion of a "Model".

Yes, Dimitris and I will be at MoDELS. Are you also attending? It'd be good to chat with you again...

Cheers,
Louis.
Re: Loading models into IModel objects [message #559840 is a reply to message #539413] Sun, 19 September 2010 18:58 Go to previous message
Stephen Barrett is currently offline Stephen Barrett
Messages: 46
Registered: May 2010
Member
Yes I'm coming to Oslo. See the both of you in October!

Cheers,
--Stephen
Re: Loading models into IModel objects [message #589980 is a reply to message #539413] Thu, 10 June 2010 13:01 Go to previous message
Dimitrios Kolovos is currently offline Dimitrios Kolovos
Messages: 1776
Registered: July 2009
Senior Member
Hi Stephen,

You can use InMemoryEmfModel to access loaded EMF Resources from Epsilon
programs.

Cheers,
Dimitris

On 10/06/2010 19:07, Stephen Barrett wrote:
> Hello Epsilon Fans,
>
> I've looked through the source, and don't see that what I want is
> provided for, but I thought I would ask anyway:
>
> I am constructing UML2 models in Java which I want to manipulate with
> the Epsilon family of languages, also running in Java. Is it possible to
> load an IModel object directly with a UML2 model (or something similar)?
> Or maybe accomplish the same thing by specifying a URI scheme other than
> file:// for the PROPERTY_MODEL_FILE property?
>
> This would save having to write a model out to an XMI file right after
> building it, only to turn around and read it back in again into an
> EmfModel. And it would also save having to unravel filesystem paths,
> permissions, etc., which is a consideration for standalone tools.
>
> That being said, this is not a critical item, more of a "Wouldn't it be
> nice?" kind of thing.
>
> Regards,
> --Stephen
Re: Loading models into IModel objects [message #589995 is a reply to message #539413] Thu, 10 June 2010 13:03 Go to previous message
Louis Rose is currently offline Louis Rose
Messages: 439
Registered: July 2009
Location: York, United Kingdom
Senior Member
Hi Stephen,

Thanks for the interest. Sure, I think InMemoryEmfModel is a perfect fit for this case.

Presuming that you're invoking Epsilon from Java, you can use code similar to this:

final InMemoryEmfModel model = new InMemoryEmfModel("NameOfYourModel", resource, UmlPackage.eINSTANCE);

where resource is an instance of EMF's Resource interface.

The in-memory model can then be used with Epsilon just like any other module. The following code, for example, could be use the in-memory model with EGL to generate some text:

final IEglContext context = new EglContext();
context.getModelRepository().addModel(model);

final EglFileGeneratingTemplateFactory factory = new EglFileGeneratingTemplateFactory(context);

final EglFileGeneratingTemplate template = factory.load(aUriOrFileToYourEglTemplate);

template.process();

// or use template.generate(...) if you want to
// store the results of the main template to disk

I hope this helps.

Cheers,
Louis.
Re: Loading models into IModel objects [message #590020 is a reply to message #539428] Fri, 11 June 2010 08:16 Go to previous message
Stephen Barrett is currently offline Stephen Barrett
Messages: 46
Registered: May 2010
Member
I think you're right guys. I found InMemoryEmfModel after more digging, and it fits the bill exactly. Thanks for the confirmation!

Regards,
--Stephen
Re: Loading models into IModel objects [message #590244 is a reply to message #539578] Tue, 22 June 2010 09:57 Go to previous message
Stephen Barrett is currently offline Stephen Barrett
Messages: 46
Registered: May 2010
Member
Hi,

I'm finally back to this issue of loading a UML model from an XMIResource instead of a file. You all gave me the right answer, but there is a bit of a catch I thought I would mention in case some one else is trying to do the same thing. Namely, the model resource needs to be part of a set, even if it's the only thing in the set. Otherwise Epsilon throws an exception. So here's the working Java code:


IEolExecutableModule module;

...

ResourceSet res_set = new ResourceSetImpl();
res_set.getResources().add(uml_model);

InMemoryEmfModel model =
new InMemoryEmfModel("UML", uml_model, UMLPackage.eNS_URI);
module.getContext().getModelRepository().addModel(model);


--Stephen
Re: Loading models into IModel objects [message #590263 is a reply to message #541780] Tue, 22 June 2010 10:01 Go to previous message
Dimitrios Kolovos is currently offline Dimitrios Kolovos
Messages: 1776
Registered: July 2009
Senior Member
Hi Stephen,

Many thanks for reporting back on this! Could you please file a bug
report for this?

Cheers,
Dimitris

Stephen Barrett wrote:
> Hi,
>
> I'm finally back to this issue of loading a UML model from an
> XMIResource instead of a file. You all gave me the right answer, but
> there is a bit of a catch I thought I would mention in case some one
> else is trying to do the same thing. Namely, the model resource needs to
> be part of a set, even if it's the only thing in the set. Otherwise
> Epsilon throws an exception. So here's the working Java code:
>
>
> IEolExecutableModule module;
>
> ..
>
> ResourceSet res_set = new ResourceSetImpl();
> res_set.getResources().add(uml_model);
>
> InMemoryEmfModel model = new InMemoryEmfModel("UML", uml_model,
> UMLPackage.eNS_URI);
> module.getContext().getModelRepository().addModel(model);
>
>
> --Stephen
Re: Loading models into IModel objects [message #590283 is a reply to message #541792] Tue, 22 June 2010 10:41 Go to previous message
Stephen Barrett is currently offline Stephen Barrett
Messages: 46
Registered: May 2010
Member
If you consider this a bug, I'll file a report Dimitris.

Cheers,
--Stephen
Re: Loading models into IModel objects [message #590319 is a reply to message #590283] Wed, 23 June 2010 07:28 Go to previous message
Dimitrios Kolovos is currently offline Dimitrios Kolovos
Messages: 1776
Registered: July 2009
Senior Member
Hi Stephen,

It's not a major bug but it probably makes sense to perform this check
and add the resource to a set in case it is does not already belong to
one within InMemoryModel.

Cheers,
Dimitris

Stephen Barrett wrote:
> If you consider this a bug, I'll file a report Dimitris.
>
> Cheers,
> --Stephen
Re: Loading models into IModel objects [message #590900 is a reply to message #541961] Fri, 23 July 2010 17:27 Go to previous message
Stephen Barrett is currently offline Stephen Barrett
Messages: 46
Registered: May 2010
Member
Dimitris, Louis,

I somehow managed to break my previously working code. I switched from using a UML to an Ecore model. The new code for the left XMIResource looks like this:


new ResourceSetImpl().getResources().add(xmi_model_lf);
module.getContext().getModelRepository().addModel(
new InMemoryEmfModel("Left", xmi_model_lf, EcorePackage.eNS_URI));


The right is similar. When I try to execute an ECL module that has successfully parsed a rules file, Epsilon throws this error: Type 'Left!Model' not found ... @2:17

The relevant rule looks like this:


rule Models
match l : Left!Model with r : Right!Model {
compare : true
do {
matchInfo.put("mirador", 0.7);
}
}


Which used to work just fine. It seems that the model names are not being registered, which make me think I missed a step. Any ideas?

--Stephen
Re: Loading models into IModel objects [message #590908 is a reply to message #590900] Sat, 24 July 2010 04:04 Go to previous message
Louis Rose is currently offline Louis Rose
Messages: 439
Registered: July 2009
Location: York, United Kingdom
Senior Member
Hi Stephen,

I think the error is occurring because the Ecore metamodel does not contain the Model type.

The Ecore metamodel is similar to the class diagram part of the UML metamodel, but not identical. There's a fairly good overview of the Ecore metamodel in the EMF javadoc: http://download.eclipse.org/modeling/emf/emf/javadoc/2.6.0/o rg/eclipse/emf/ecore/package-summary.html

You may need to create a new comparison for Ecore models that incorporates these differences (e.g. change Package to EPackage). Another alternative would be to write a transformation from Ecore to UML, and run that before running the comparison.

Perhaps Dimitris will have some ideas about this too.

Cheers,
Louis.
Previous Topic:Running the EGL example
Next Topic:ETL ANT Script help
Goto Forum:
  


Current Time: Wed Jul 30 23:39:40 EDT 2014

Powered by FUDForum. Page generated in 0.03147 seconds