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  |
Eclipse User |
|
|
|
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   |
Eclipse User |
|
|
|
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] by Moderator
|
|
|
Re: Loading models into IModel objects [message #539430 is a reply to message #539413] |
Thu, 10 June 2010 13:01   |
Eclipse User |
|
|
|
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 #589980 is a reply to message #539413] |
Thu, 10 June 2010 13:01  |
Eclipse User |
|
|
|
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  |
Eclipse User |
|
|
|
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 #590244 is a reply to message #539578] |
Tue, 22 June 2010 09:57  |
Eclipse User |
|
|
|
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  |
Eclipse User |
|
|
|
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 #590319 is a reply to message #590283] |
Wed, 23 June 2010 07:28  |
Eclipse User |
|
|
|
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  |
Eclipse User |
|
|
|
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
|
|
| |
Goto Forum:
Current Time: Wed Jul 23 18:54:47 EDT 2025
Powered by FUDForum. Page generated in 0.07654 seconds
|