Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » XMI model from xtext file(XMI model from xtext file)
XMI model from xtext file [message #799950] Thu, 16 February 2012 13:54 Go to next message
Ismail Zine is currently offline Ismail ZineFriend
Messages: 11
Registered: February 2012
Junior Member
Hi,

And how can I get an XMI model from a DSL textual file?
You should know that I don't have the .generator project ( I don't have this option when creating an xtext project )

Thanks,
Re: XMI model from xtext file [message #800021 is a reply to message #799950] Thu, 16 February 2012 15:31 Go to previous messageGo to next message
Sebastian Zarnekow is currently offline Sebastian ZarnekowFriend
Messages: 3108
Registered: July 2009
Senior Member
Hi Ismail,

did you try to read the dsl file, resolve the cross references and add
the contents of the parsed resource to a newly created XMI resource? I
assume you are familiar with the EMF resource concept?

Regards,
Sebastian
--
Need professional support for Eclipse Modeling?
Go visit: http://xtext.itemis.com

Am 16.02.12 14:54, schrieb Ismail Zine:
> Hi,
>
> And how can I get an XMI model from a DSL textual file?
> You should know that I don't have the .generator project ( I don't have
> this option when creating an xtext project )
>
> Thanks,
Re: XMI model from xtext file [message #800028 is a reply to message #800021] Thu, 16 February 2012 15:46 Go to previous messageGo to next message
Ismail Zine is currently offline Ismail ZineFriend
Messages: 11
Registered: February 2012
Junior Member
Well, I read a little bit about it..
I wrote something quite similar to this but i don't where I should be put it

Injector injector = new MyModelStandaloneSetup().createInjectorAndDoEMFRegistration();
ResourceSet resourceSet = injector.getInstance(XtextResourceSet.class);

resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put(
Resource.Factory.Registry.DEFAULT_EXTENSION,
new XMIResourceFactoryImpl());

URI uri = URI.createURI("person.cm");
Resource xtextResource = resourceSet.getResource(uri, true);
try {
xtextResource.load(null);
} catch (IOException e1) {
e1.printStackTrace();
}
EcoreUtil.resolveAll(xtextResource);
Resource xmiResource = resourceSet.createResource(URI.createURI("test.xmi"));
xmiResource.getContents().add(xtextResource.getContents().get(0));
try {
xmiResource.save(null);
} catch (IOException e) {
e.printStackTrace();
}
Re: XMI model from xtext file [message #801077 is a reply to message #800028] Fri, 17 February 2012 22:16 Go to previous messageGo to next message
Ismail Zine is currently offline Ismail ZineFriend
Messages: 11
Registered: February 2012
Junior Member
I found something interesting in the generator workflow that could help to save the xtext resource as xmi..
<component file="my/textual/dsl/parser/Parser.oaw">
<metaModel idRef="mm"/>
<outputSlot value="mymodel"/>
<modelFile value="person.dsl"/>
</component>

<component class="oaw.emf.XmiWriter">
<modelFile value="out.xmi"/>
<inputSlot value="mymodel"/>
</component>

the problem is that The Modeling Workow Engine 2 syntax is different from the the modeling workflow engine, and when I try to write like :
component = oaw.emf.XmiWriter {
modelFile = "out.xmi"
inputSlot = "mymodel"
}
the following error appears : Couldn't resolve reference to JvmType 'oaw.emf.XmiWriter'
Re: XMI model from xtext file [message #801089 is a reply to message #801077] Fri, 17 February 2012 22:39 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 13601
Registered: July 2009
Senior Member
Hi,

which version do you use. i guess you use M2T Xpand (>=0.7) and not oAW Xpand (<= 4.3.1)

=> the classname is org.eclipse.xtend.typesystem.emf.XmiWriter
but since it is deprecated you should use org.eclipse.emf.mwe.utils.Writer

even if you use good old oaw xpand it is org.openarchitectureware....XmiWriter
(the shorthands of mwe wont work)

~Christian


Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/it-services/methods-and-tools/xtext
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: XMI model from xtext file [message #801109 is a reply to message #801089] Fri, 17 February 2012 23:17 Go to previous messageGo to next message
Ismail Zine is currently offline Ismail ZineFriend
Messages: 11
Registered: February 2012
Junior Member
Thanks for your response, I have 1.1.1 version
there is no documentation of org.eclipse.emf.mwe.utils.Writer, which is weird!!
do u know how can I write the parser component ( the file property !! )
<component file="my/textual/dsl/parser/Parser.oaw">
<metaModel idRef="mm"/>
<outputSlot value="mymodel"/>
<modelFile value="person.dsl"/>
</component>
using the Modeling Workow Engine 2.

thanks,

Ismail
Re: XMI model from xtext file [message #801326 is a reply to message #801109] Sat, 18 February 2012 07:26 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 13601
Registered: July 2009
Senior Member
Hi once more oAW Xtext != Eclipse Xtext => Trying to translate a oAW Xtext Workflow is of limited sense.
there is the org.eclipse.xtext.mwe.Reader or the org.eclipse.xtext.mwe.UriBasedReader
for that

~Christian


Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/it-services/methods-and-tools/xtext
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: XMI model from xtext file [message #801554 is a reply to message #801326] Sat, 18 February 2012 15:42 Go to previous messageGo to next message
Ismail Zine is currently offline Ismail ZineFriend
Messages: 11
Registered: February 2012
Junior Member
Hi,

this is driving me crazy!! I'm trying this which, I found in xtext 2.1 documentation:( to read the dsl file and load it as a xtextResource )

Injector injector = new GaCodeModelStandaloneSetup().createInjectorAndDoEMFRegistration();
XtextResourceSet resourceSet = injector.getInstance(XtextResourceSet.class);
URI uri = URI.createURI("person.cm");
Resource xtextResource = resourceSet.getResource(uri, true);

but it throws this exception :
Exception in thread "main" java.lang.RuntimeException: Cannot create a resource for 'person.cm'; a registered resource factory is needed
at org.eclipse.emf.ecore.resource.impl.ResourceSetImpl.getResource(ResourceSetImpl.java:394)
at org.eclipse.xtext.resource.SynchronizedXtextResourceSet.getResource(SynchronizedXtextResourceSet.java:23)

so I add this to the code
resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put(
Resource.Factory.Registry.DEFAULT_EXTENSION,
new XMIResourceFactoryImpl());

it throws
Exception in thread "main" org.eclipse.emf.ecore.resource.impl.ResourceSetImpl$1DiagnosticWrappedException: org.xml.sax.SAXParseException: Content is not allowed in prolog.
at org.eclipse.emf.ecore.resource.impl.ResourceSetImpl.handleDemandLoadException(ResourceSetImpl.java:315)
at org.eclipse.emf.ecore.resource.impl.ResourceSetImpl.demandLoadHelper(ResourceSetImpl.java:274)
at org.eclipse.emf.ecore.resource.impl.ResourceSetImpl.getResource(ResourceSetImpl.java:397)
at org.eclipse.xtext.resource.SynchronizedXtextResourceSet.getResource(SynchronizedXtextResourceSet.java:23)
at geneauto.models.ModelStandaloneSetup.main(ModelStandaloneSetup.java:50)
Caused by: org.xml.sax.SAXParseException: Content is not allowed in prolog.
at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.createSAXParseException(ErrorHandlerWrapper.java:195)
at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.fatalError(ErrorHandlerWrapper.java:174)
at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:388)
at com.sun.org.apache.xerces.internal.impl.XMLScanner.reportFatalError(XMLScanner.java:1414)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl$PrologDriver.next(XMLDocumentScannerImpl.java:1039)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(XMLDocumentScannerImpl.java:648)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:511)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:808)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:737)
at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:119)
at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1205)
at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(SAXParserImpl.java:522)
at javax.xml.parsers.SAXParser.parse(SAXParser.java:395)
at org.eclipse.emf.ecore.xmi.impl.XMLLoadImpl.load(XMLLoadImpl.java:181)
at org.eclipse.emf.ecore.xmi.impl.XMLResourceImpl.doLoad(XMLResourceImpl.java:242)
at org.eclipse.emf.ecore.resource.impl.ResourceImpl.load(ResourceImpl.java:1511)
at org.eclipse.emf.ecore.resource.impl.ResourceImpl.load(ResourceImpl.java:1290)
at org.eclipse.emf.ecore.resource.impl.ResourceSetImpl.demandLoad(ResourceSetImpl.java:255)
at org.eclipse.emf.ecore.resource.impl.ResourceSetImpl.demandLoadHelper(ResourceSetImpl.java:270)
... 3 more

in the second eclipse, when I try to open the dsl file using a sample reflective ecore editor as shown in the xtext website, it gives the same exception!! ( content is not allowed in prolog )
Re: XMI model from xtext file [message #801586 is a reply to message #801554] Sat, 18 February 2012 16:37 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 13601
Registered: July 2009
Senior Member
Hi are you sure cm is the extension of your dsl

Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/it-services/methods-and-tools/xtext
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: XMI model from xtext file [message #801666 is a reply to message #801586] Sat, 18 February 2012 19:26 Go to previous messageGo to next message
Ismail Zine is currently offline Ismail ZineFriend
Messages: 11
Registered: February 2012
Junior Member
Yes, I'm sure...
When I create files with cm as extension in the second eclipse, I can use all the editor functions..
Re: XMI model from xtext file [message #801671 is a reply to message #801666] Sat, 18 February 2012 19:37 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 13601
Registered: July 2009
Senior Member
Hi,

then

Injector injector = new GaCodeModelStandaloneSetup().createInjectorAndDoEMFRegistration();
XtextResourceSet resourceSet = injector.getInstance(XtextResourceSet.class);
URI uri = URI.createURI("person.cm");
Resource xtextResource = resourceSet.getResource(uri, true);


should be totally sufficient. and i have no idea why this is not working

can you share the code of your GaCodeModelStandaloneSetup and GaCodeModelStandaloneSetupGenerated?

~Christian


Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/it-services/methods-and-tools/xtext
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: XMI model from xtext file [message #801702 is a reply to message #801671] Sat, 18 February 2012 20:53 Go to previous messageGo to next message
Ismail Zine is currently offline Ismail ZineFriend
Messages: 11
Registered: February 2012
Junior Member
public class GaCodeModelStandaloneSetup extends GaCodeModelStandaloneSetupGenerated{

	public static void doSetup() {
		new GaCodeModelStandaloneSetup().createInjectorAndDoEMFRegistration();
	}
}

public class GaCodeModelStandaloneSetupGenerated implements ISetup {

	public Injector createInjectorAndDoEMFRegistration() {
		org.eclipse.xtext.common.TerminalsStandaloneSetup.doSetup();

		Injector injector = createInjector();
		register(injector);
		return injector;
	}
	
	public Injector createInjector() {
		return Guice.createInjector(new geneauto.models.GaCodeModelRuntimeModule());
	}
	
	public void register(Injector injector) {
	if (!EPackage.Registry.INSTANCE.containsKey("http://www.models.geneauto/GaCodeModel")) {
		EPackage.Registry.INSTANCE.put("http://www.models.geneauto/GaCodeModel", geneauto.models.gaCodeModel.GaCodeModelPackage.eINSTANCE);
	}

		org.eclipse.xtext.resource.IResourceFactory resourceFactory = injector.getInstance(org.eclipse.xtext.resource.IResourceFactory.class);
		org.eclipse.xtext.resource.IResourceServiceProvider serviceProvider = injector.getInstance(org.eclipse.xtext.resource.IResourceServiceProvider.class);
		Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().put("CM", resourceFactory);
		org.eclipse.xtext.resource.IResourceServiceProvider.Registry.INSTANCE.getExtensionToFactoryMap().put("CM", serviceProvider);
	}
}
Re: XMI model from xtext file [message #801703 is a reply to message #801671] Sat, 18 February 2012 20:53 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 13601
Registered: July 2009
Senior Member
P.S Btw from "where" do you execute this code.

Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/it-services/methods-and-tools/xtext
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: XMI model from xtext file [message #801712 is a reply to message #801702] Sat, 18 February 2012 21:09 Go to previous messageGo to next message
Ismail Zine is currently offline Ismail ZineFriend
Messages: 11
Registered: February 2012
Junior Member
Yeah it could be the problem..
I created a main method in the GaCodeModelStandaloneSetup class to test the code...is it a problem?
Re: XMI model from xtext file [message #801716 is a reply to message #801712] Sat, 18 February 2012 21:17 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 13601
Registered: July 2009
Senior Member
nope this is ok. but your fileextension is CM and not cm (the editor will work anyway - but may be buggy to)

Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/it-services/methods-and-tools/xtext
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: XMI model from xtext file [message #801719 is a reply to message #801716] Sat, 18 February 2012 21:19 Go to previous messageGo to next message
Ismail Zine is currently offline Ismail ZineFriend
Messages: 11
Registered: February 2012
Junior Member
I tried with CM and it gives the same error!!!
Re: XMI model from xtext file [message #801720 is a reply to message #801719] Sat, 18 February 2012 21:21 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 13601
Registered: July 2009
Senior Member
Of course if you use the correct file extension you wont need the

resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put(
Resource.Factory.Registry.DEFAULT_EXTENSION, 
new XMIResourceFactoryImpl());


stuff


Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/it-services/methods-and-tools/xtext
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: XMI model from xtext file [message #801725 is a reply to message #801720] Sat, 18 February 2012 21:28 Go to previous messageGo to next message
Ismail Zine is currently offline Ismail ZineFriend
Messages: 11
Registered: February 2012
Junior Member
Thanks, you are totally right....
I deleted this statement and I tried with the CM extension and it works.
Here is the code for who may be interested:
Injector injector = new GaCodeModelStandaloneSetup().createInjectorAndDoEMFRegistration();
		
		XtextResourceSet resourceSet = injector.getInstance(XtextResourceSet.class);
		
		URI uri = URI.createURI("personXMI.CM");
		// Resource xtextResource = resourceSet.createResource(uri);
		Resource xtextResource = resourceSet.getResource(uri, true);
		
		EcoreUtil.resolveAll(xtextResource);
		
		Resource xmiResource = resourceSet.createResource(URI.createURI("test.xmi"));
		xmiResource.getContents().add(xtextResource.getContents().get(0));
		try {
			xmiResource.save(null);
		} catch (IOException e) {
			e.printStackTr

thanks for your help.

Ismail
icon10.gif  Re: XMI model from xtext file [message #1479407 is a reply to message #801725] Wed, 19 November 2014 12:01 Go to previous message
Puneet Patwari is currently offline Puneet PatwariFriend
Messages: 64
Registered: November 2014
Member
This post has been of great help to me. I have been facing the same problem for a quite a long time now. Smile Very Happy
Previous Topic:Infer DSL by using ANT
Next Topic:How to reload a DefaultUiModule in xtext?
Goto Forum:
  


Current Time: Tue Sep 22 16:29:36 GMT 2020

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

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

Back to the top