Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Modell-Instance of the DSL(Xtetx 2.5.1)
Modell-Instance of the DSL [message #1718555] Sun, 27 December 2015 09:34 Go to next message
Parisa Moosavi is currently offline Parisa MoosaviFriend
Messages: 81
Registered: June 2015
Member
Hi

How can I have the modell instance of the DSL?
I mean in Runtime eclipse that I have a SDL editor and I write my DSL, How can I access the Modell Instance of the DSL which I have in DSL Editor? I want to compare this instance modell with an instance modell which is created with EMF editor.

Thanx
Re: Modell-Instance of the DSL [message #1718932 is a reply to message #1718555] Sat, 02 January 2016 21:18 Go to previous messageGo to next message
Sven Efftinge is currently offline Sven EfftingeFriend
Messages: 1823
Registered: July 2009
Senior Member
You can load an Xtext based DSL-file similarly to any other EMF resource. The main difference is that you need to make sure that the language's injector is properly set up and that the EMF registries are populated. In standard Java process you do this using the [MyDSL]StandaloneSetup.

Here is some (untested) code that should get you started.
public static void main(String ... args) {
  // initialize Xtext language
  new MyDslStandaloneSetup().createInjectorAndDoEMFRegistration();

  // standard EMF code
  ResourceSet rs = new ResourceSet();
  Resource resource = rs.getResource(URI.create("path/to/MyFile.mydsl", true)
  ...
}
Re: Modell-Instance of the DSL [message #1718951 is a reply to message #1718932] Sun, 03 January 2016 16:35 Go to previous messageGo to next message
Parisa Moosavi is currently offline Parisa MoosaviFriend
Messages: 81
Registered: June 2015
Member
I tried to use your code but which I can write is like this Confused
		new CarStandaloneSetup().createInjectorAndDoEMFRegistration();
		ResourceSet rs = new ResourceSet() {

			public void eSetDeliver(boolean deliver) {
				// TODO Auto-generated method stub

			}

			public void eNotify(Notification notification) {
				// TODO Auto-generated method stub

			}

			public boolean eDeliver() {
				// TODO Auto-generated method stub
				return false;
			}

			public EList<Adapter> eAdapters() {
				// TODO Auto-generated method stub
				return null;
			}

			public void setURIConverter(URIConverter converter) {
				// TODO Auto-generated method stub

			}

			public void setResourceFactoryRegistry(
					org.eclipse.emf.ecore.resource.Resource.Factory.Registry resourceFactoryRegistry) {
				// TODO Auto-generated method stub

			}

			public void setPackageRegistry(Registry packageRegistry) {
				// TODO Auto-generated method stub

			}

			public URIConverter getURIConverter() {
				// TODO Auto-generated method stub
				return null;
			}

			public EList<Resource> getResources() {
				// TODO Auto-generated method stub
				return null;
			}

			public org.eclipse.emf.ecore.resource.Resource.Factory.Registry getResourceFactoryRegistry() {
				// TODO Auto-generated method stub
				return null;
			}

			public Resource getResource(URI uri, boolean loadOnDemand) {
				// TODO Auto-generated method stub
				return null;
			}

			public Registry getPackageRegistry() {
				// TODO Auto-generated method stub
				return null;
			}

			public Map<Object, Object> getLoadOptions() {
				// TODO Auto-generated method stub
				return null;
			}

			public EObject getEObject(URI uri, boolean loadOnDemand) {
				// TODO Auto-generated method stub
				return null;
			}

			public TreeIterator<Notifier> getAllContents() {
				// TODO Auto-generated method stub
				return null;
			}

			public EList<AdapterFactory> getAdapterFactories() {
				// TODO Auto-generated method stub
				return null;
			}

			public Resource createResource(URI uri, String contentType) {
				// TODO Auto-generated method stub
				return null;
			}

			public Resource createResource(URI uri) {
				// TODO Auto-generated method stub
				return null;
			}
		};

		Resource resource = rs.getResource(URI.createURI("D:\\...\\src\\car.car"), true);
	



Because ResourceSet is an interface. And imports are like this.
import java.util.Map;

import org.eclipse.emf.common.notify.Adapter;
import org.eclipse.emf.common.notify.AdapterFactory;
import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.common.notify.Notifier;
import org.eclipse.emf.common.util.EList;
import org.eclipse.emf.common.util.TreeIterator;
import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.EPackage.Registry;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.ecore.resource.ResourceSet;
import org.eclipse.emf.ecore.resource.URIConverter;

[Updated on: Sun, 03 January 2016 16:36]

Report message to a moderator

Re: Modell-Instance of the DSL [message #1718954 is a reply to message #1718951] Sun, 03 January 2016 18:25 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Assign the injector you get from createInjectorAndDoEMFRegistration to a var and ask it for an instance of resourceset.
O r create a new resourcesetimpl

Please note this will only work in a standalone app


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Modell-Instance of the DSL [message #1718957 is a reply to message #1718954] Sun, 03 January 2016 20:39 Go to previous messageGo to next message
Parisa Moosavi is currently offline Parisa MoosaviFriend
Messages: 81
Registered: June 2015
Member
Now I'm using this code to load the model. Is it possible to save it in XMI format? Rolling Eyes
		Injector injector = new CarStandaloneSetup().createInjectorAndDoEMFRegistration();
		XtextResourceSet resourceSet = injector.getInstance(XtextResourceSet.class);
		resourceSet.addLoadOption(XtextResource.OPTION_RESOLVE_ALL, Boolean.TRUE);
		Resource resource = resourceSet.getResource(
			    URI.createURI("file:///D:/.../car.car"), true);
		AllCars model = (AllCars) resource.getContents().get(0);
Re: Modell-Instance of the DSL [message #1718960 is a reply to message #1718957] Sun, 03 January 2016 21:29 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Simply move the content to anxmi resource

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Modell-Instance of the DSL [message #1719118 is a reply to message #1718960] Tue, 05 January 2016 13:12 Go to previous message
Parisa Moosavi is currently offline Parisa MoosaviFriend
Messages: 81
Registered: June 2015
Member
Perfect, thanks!
Previous Topic:How to add web integration to existing project?(Xtext 2.9)
Next Topic:Dangling Reference Error with Hierarchical Entities - I'm Lost
Goto Forum:
  


Current Time: Fri Apr 19 07:33:21 GMT 2024

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

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

Back to the top