Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » Parsing of ecore models
Parsing of ecore models [message #1089258] Sun, 18 August 2013 12:19 Go to next message
Phil H is currently offline Phil HFriend
Messages: 267
Registered: November 2012
Senior Member
Hi everyone,

First my use case: I want to extend my EMF editor so that users can import other ecore models, which differs in structure and naming. For example I've got ecoreA, which represents my EMF Editor. EcoreB describes a part of EcoreA, but with difference in structure and naming.
So when a user wants now to import an instance of ecoreB, there must be something like a parser which translates the ecoreB instance so that it fit in for ecoreA.

So what would be the best way to realize this? Are there any tools which I could use?

At the moment, I've extended the context menu with an Import menu item, which opens a FileDialog by clicking. This should be the hooking point for importig the other ecore instance and parse it.

I'm a little bit afraid that it could be a little bit complicated to include it then into the main model. Maybe there are some examples already?

Cheers,
Phil
Re: Parsing of ecore models [message #1090616 is a reply to message #1089258] Tue, 20 August 2013 12:04 Go to previous messageGo to next message
Daniel Strueber is currently offline Daniel StrueberFriend
Messages: 14
Registered: March 2011
Junior Member
To my impression, writing a dedicated parser would be a rather low-level solution to your use case. Since EMF provides a parser for EcoreB models out of the box, you might as well use this parser and then use model transformation to convert your EcoreB model (parsed by EMF's default mechanism) into an EcoreA model.

Such a model transformation would then involve two steps: You define some conversion rules and then you execute them on some input EcoreB model. If you employ a model transformation engine that comes along with an API, such as EMF Henshin, the second step can be executed from your context menu just as you described.

You might check out the Ecore-to-RDB example for a model-to-model-transformation in Henshin. Note that at this moment we're still resolving some compatibility issues with Eclipse Kepler. To give Henshin a try, you should thus use Eclipse Juno.

Regards,
Daniel

[Updated on: Tue, 20 August 2013 14:10]

Report message to a moderator

Re: Parsing of ecore models [message #1103103 is a reply to message #1090616] Fri, 06 September 2013 11:35 Go to previous messageGo to next message
Phil H is currently offline Phil HFriend
Messages: 267
Registered: November 2012
Senior Member
Hi Daniel,

I think you're right about writing my own parser. I had a quick look at henshin, but for me it seems to complex for my use case.

Are there any examples for the parser for EcoreB models? I hardly couldn't find any informations aout this.

What I've thought about is using a XML Parser, which reads in the model and then I'ld provide my own logic to integrate this model to the main model. Would this be a good approach? And can someone recommended a XML parser for this job?

Cheers,
Phil
Re: Parsing of ecore models [message #1103255 is a reply to message #1103103] Fri, 06 September 2013 14:43 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33137
Registered: July 2009
Senior Member
Phil,

I think the suggestion is to simply load B as normal and to transform
the B instances into A instance via Java code or using one of the
transformation languages such as ATL.


On 06/09/2013 1:35 PM, Phil H wrote:
> Hi Daniel,
>
> I think you're right about writing my own parser. I had a quick look
> at henshin, but for me it seems to complex for my use case.
>
> Are there any examples for the parser for EcoreB models? I hardly
> couldn't find any informations aout this.
>
> What I've thought about is using a XML Parser, which reads in the
> model and then I'ld provide my own logic to integrate this model to
> the main model. Would this be a good approach? And can someone
> recommended a XML parser for this job?
>
> Cheers,
> Phil


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Parsing of ecore models [message #1103285 is a reply to message #1103255] Fri, 06 September 2013 15:24 Go to previous messageGo to next message
Phil H is currently offline Phil HFriend
Messages: 267
Registered: November 2012
Senior Member
Hi Ed,

that's what I trying to do now. I use a filedialog to get the filepath of the model which I want to import. Then I want to use XMIResourceImpl to read in the model. Is this the right way so far?:

public class ImportHandler extends AbstractHandler {

	@Override
	public Object execute(ExecutionEvent event) throws ExecutionException {
		Shell shell = Display.getCurrent().getActiveShell();
		FileDialog fileDialog = new FileDialog(shell);
		fileDialog.setText("Import an existing Hardware Model");
		fileDialog.setFilterExtensions(new String[] { "*.hw" });
		fileDialog.setFilterNames(new String[] { "*.hw" });
		try {
			String path = fileDialog.open();
			URI uri = URI.createFileURI(path);
			Resource resource = new XMIResourceImpl();
			resource.unload();
			resource.setURI(uri);
			try {		
				resource.load(null);
			} catch (IOException e) {
				System.err.println("Exception occured while loading the resource file for configuration model: "+ e.getMessage());
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return null;
	}
}


This throws the following exception:

Package with uri 'http://www.itea2.org/model/hw' not found. (file:/C:/eclipse_hw/runtime-EclipseApplication/hw_test/My.hw, 2, 170)


I placed the ecore of the intances which I want to import in a seperate project as you can see in the attached image. Also I rightclicked on the ecore and selected Register EPackges. Am I completely wrong what I'm doing so far?

Cheers,
Phil
  • Attachment: model.JPG
    (Size: 30.94KB, Downloaded 193 times)
Re: Parsing of ecore models [message #1103419 is a reply to message #1103285] Fri, 06 September 2013 19:06 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33137
Registered: July 2009
Senior Member
Phil,

For your model, invoke Generate Test Code and look at the generated
XyzExample.java. Make sure your generate model is available (so that
it's registered).

On 06/09/2013 5:24 PM, Phil H wrote:
> Hi Ed,
>
> that's what I trying to do now. I use a filedialog to get the filepath of the model which I want to import. Then I want to use XMIResourceImpl to read in the model. Is this the right way so far?:
>
>
> public class ImportHandler extends AbstractHandler {
>
> @Override
> public Object execute(ExecutionEvent event) throws ExecutionException {
> Shell shell = Display.getCurrent().getActiveShell();
> FileDialog fileDialog = new FileDialog(shell);
> fileDialog.setText("Import an existing Hardware Model");
> fileDialog.setFilterExtensions(new String[] { "*.hw" });
> fileDialog.setFilterNames(new String[] { "*.hw" });
> try {
> String path = fileDialog.open();
> URI uri = URI.createFileURI(path);
> Resource resource = new XMIResourceImpl();
> resource.unload();
> resource.setURI(uri);
> try {
> resource.load(null);
> } catch (IOException e) {
> System.err.println("Exception occured while loading the resource file for configuration model: "+ e.getMessage());
> }
> } catch (Exception e) {
> e.printStackTrace();
> }
> return null;
> }
> }
>
>
> This throws the following exception:
>
> Package with uri 'http://www.itea2.org/model/hw' not found. (file:/C:/eclipse_hw/runtime-EclipseApplication/hw_test/My.hw, 2, 170)
>
> I placed the ecore of the intances which I want to import in a seperate project as you can see in the attached image. Also I rightclicked on the ecore and selected Register EPackges. Am I completely wrong what I'm doing so far?
>
> Cheers,
> Phil


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Parsing of ecore models [message #1105252 is a reply to message #1103419] Mon, 09 September 2013 15:34 Go to previous messageGo to next message
Phil H is currently offline Phil HFriend
Messages: 267
Registered: November 2012
Senior Member
Hi Ed,

as you told me, I used my genmodel to generate test code, but this doesn't work..What I have now is a project containing the ecore, genmodel and the generated test code..

What I still haven't understand yet if it's enough to have just the ecore model, or need I also the gen model and generate all the code? I expected that the ecore model would be sufficient..
Re: Parsing of ecore models [message #1105270 is a reply to message #1105252] Mon, 09 September 2013 15:55 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 33137
Registered: July 2009
Senior Member
Phil,

Comments below.

On 09/09/2013 5:34 PM, Phil H wrote:
> Hi Ed,
>
> as you told me, I used my genmodel to generate test code, but this
> doesn't work..
What specifically doesn't work?
> What I have now is a project containing the ecore, genmodel and the
> generated test code..
Better to generate it to a different project. So it sounds like it did
work and you've just not found the XyzExample.java?
>
> What I still haven't understand yet if it's enough to have just the
> ecore model, or need I also the gen model and generate all the code?
That depends.
> I expected that the ecore model would be sufficient..
For many models it's possible just to use dynamic Ecore. E.g., if you
right click on an EClass in the model, you can invoke Create Dynamic
Instance. But if you're going to write a model to model
transformation, you probably want to do that with the generated API for
the two models.


Ed Merks
Professional Support: https://www.macromodeling.com/
Previous Topic:[xcore] Error loading xcore resource in generated editor
Next Topic:Extend a Model via ExtendedMetaData Interface
Goto Forum:
  


Current Time: Sat Apr 20 02:35:57 GMT 2024

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

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

Back to the top