Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » M2T (model-to-text transformation) » M2T Ecore2XML / Ecore2JSON Tutorial/Guide/Help(I'm clueless how to perform the transformations)
M2T Ecore2XML / Ecore2JSON Tutorial/Guide/Help [message #1807010] Tue, 21 May 2019 09:04 Go to next message
Ilja Shmelkin is currently offline Ilja ShmelkinFriend
Messages: 3
Registered: May 2019
Junior Member
Hello you,

I'm a new Member here in the Forum. I'm currently writing my masters thesis about the development and usage of an ecore-based metamodel.
Since the developed model will be used in different projects at some point it is necessary to transform it into different representations like XML and JSON, preferred but not necessarily the latter.

I searched for days now, without finding an appropriate solution by myself, how to transform my model.ecore to model.xml/model.json.
My model does not contain any special annotations or extensions - just plain ecore.
There has to be something obvious that I'm missing. I hope that someone here could help me to set up the transformation process in my Eclipse installation since I cant do it myself.

Thank you

PS: I attached the model.ecore
  • Attachment: model.ecore
    (Size: 16.01KB, Downloaded 16 times)
Re: M2T Ecore2XML / Ecore2JSON Tutorial/Guide/Help [message #1807179 is a reply to message #1807010] Fri, 24 May 2019 07:44 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 6440
Registered: July 2009
Senior Member
Hi

The start of your model.ecore is:

Quote:
<?xml version="1.0" encoding="UTF-8"?>
<ecore:EPackage xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:ecore="http://www.eclipse.org/emf/2002/Ecore" name="stARS" nsURI="stARS" nsPrefix="stARS">
<eClassifiers xsi:type="ecore:EClass" name="STARS">


demonstrating that a *.ecore file is an XML file or more strictly an XMI file. No transformation to XML is needed. Just copy/rename to model.xml if it helps you or another tool understand that it is XML.

JSON is standard in some communities so I am sure that there are Ecore to JSON M2Ts available; not my area. Googling "Ecore to JSON transformation" finds some hits that are probably worth following up.

Regards

Ed Willink
Re: M2T Ecore2XML / Ecore2JSON Tutorial/Guide/Help [message #1807180 is a reply to message #1807179] Fri, 24 May 2019 07:56 Go to previous messageGo to next message
Ilja Shmelkin is currently offline Ilja ShmelkinFriend
Messages: 3
Registered: May 2019
Junior Member
Hello,
thank you for taking time to answer.

After some initial trouble I finally understood how Acceleo works within and with the EMF and that you have to use a root element of your metamodel to parse the contents of it (was the ecore-package in my case).

I created a template for Acceleo to process my specific metamodel which I want to provide if someone has the same trouble in the future. I uploaded the template as an attachment to that post.

[comment encoding = UTF-8 /]
[module generateJSON('http://www.eclipse.org/emf/2002/Ecore')]


[template public generateElement(stARSpackage : EPackage)]
[comment @main/]
[file (stARSpackage.name.concat('.json'), false, 'UTF-8')]
{
"name" : "[stARSpackage.name/]",
"nsPrefix" : "[stARSpackage.nsPrefix/]",
"nsURI" : "[stARSpackage.nsURI/]",
"classes" : [for (class : EClass | stARSpackage.eAllContents(EClass)) before ('{\n') separator(',\n') after ('\n\t}\n')]
		"[class.name/]":{
			[if (class.eAllSuperTypes)->notEmpty()]
			"superTypes" : [for (c : EClassifier | class.eAllSuperTypes) before ('[') separator (', ') after ('],')]"[c.name/]"[/for]
			[/if]	
			"abstract" :  [class.abstract/],
			"interface" : [class.interface/][if (class.eAttributes->notEmpty())],
			"parameter" : [for (a : EAttribute | class.eAttributes) before ('{\n') separator(',\n') after ('\n\t\t\t}')]
				"[a.name/]": {
					[if (a.defaultValueLiteral)->notEmpty()]
					"defaultValue": "[a.defaultValueLiteral/]",
					[/if]
					"parameterType" : "[a.eType.name/]",
					"lowerBound" : [a.lowerBound/],
					"upperBound" : [a.upperBound/]
				}[/for]
			[/if]
			[if (class.eReferences->notEmpty())],
			"references" : [for (r : EReference | class.eReferences) before ('{\n') separator(',\n') after ('\n\t\t\t}\n')]
					"[r.name/]": {
						"isContainment" :[r.containment/],
						"lowerBound" : [r.lowerBound/],
						"upperBound" : [r.upperBound/]
					}[/for]
			[else]

			[/if]
		}[/for]
}[/file]
[/template]


The template processes an ecore-package and creates well-formatted JSON at least for my .ecore file which I already provided in the original post.

Good luck!
Re: M2T Ecore2XML / Ecore2JSON Tutorial/Guide/Help [message #1807186 is a reply to message #1807180] Fri, 24 May 2019 09:47 Go to previous message
Ed Willink is currently offline Ed WillinkFriend
Messages: 6440
Registered: July 2009
Senior Member
Hi

Wow, that was quick. Thak you for sharing. If you really want to be helpful to others you can provide a zipped project, or link to GitHub project. The project should contain an example input file and a launch configuration saved into the project using the Common Tab of the launch configuration. Then newbies can just load the project, run launch configuration, (read a readme), and see it working. There is probably an Acceleo Wiki page where you can publicize your facility.

Regards

Ed Willink

Previous Topic:[Acceleo] Disambiguate class reference
Next Topic:Error on model to text transformation in Acceleo
Goto Forum:
  


Current Time: Sat Aug 24 18:08:11 GMT 2019

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

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

Back to the top