Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » importURI and cross references during serialization
importURI and cross references during serialization [message #1017176] Sun, 10 March 2013 11:49 Go to next message
Fi Fi is currently offline Fi Fi
Messages: 133
Registered: March 2010
Senior Member
Dear All,
I implement this grammar http://www.eclipse.org/forums/index.php/mv/msg/354225/875475/#msg_875475
I define this small example
import "http://test" as test
Foreach xx in test.ClassTest

I try to serialize it with this Java code
package org.xtext.example.mydsl;

import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.ecore.resource.ResourceSet;
import org.eclipse.emf.ecore.resource.Resource.Diagnostic;
import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
import org.eclipse.emf.ecore.util.EcoreUtil;
import org.eclipse.emf.ecore.xmi.XMIResource;
import org.eclipse.emf.ecore.xmi.impl.XMIResourceFactoryImpl;
import org.eclipse.xtext.resource.XtextResource;




public class DoRound {
	public static void main(String [] args) throws IOException{
		/*
		 * PARSE AND SAVE TEXT MODEL TO XMI
		 ********************************************************************************/
		String text_file_extension="mydsl";
		String model_file_extension="xmi";
		String strMyDSLFile = args[0];
		
		MyDslStandaloneSetup.doSetup();
		
		ResourceSet resourceSet = new ResourceSetImpl();
		
		URI uri = URI.createFileURI(strMyDSLFile);
		Resource resource = resourceSet.getResource(uri, true);//.createResource(uri);//(uri, false);
		Map mm = new HashMap();
		
		mm.put(XtextResource.OPTION_RESOLVE_ALL, Boolean.TRUE);
		
		resource.load(mm);
		EcoreUtil.resolveAll(resource); 
		EObject object = resource.getContents().get(0);
	
		URI uri2 = URI.createFileURI(strMyDSLFile +"."+ model_file_extension);
		XMIResourceFactoryImpl x = new XMIResourceFactoryImpl();
		XMIResource rr = (XMIResource)x.createResource(uri2);
		rr.getContents().add(object);
		Map<Object, Object> m = rr.getDefaultSaveOptions();
		m.put(XMIResource.OPTION_USE_XMI_TYPE, Boolean.TRUE);
		try {
		    rr.save(m);
		} catch (IOException e1) {
		    e1.printStackTrace();
		}
		
	}}


the generated model is
<?xml version="1.0" encoding="ASCII"?>
<myDsl:Model xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:myDsl="http://www.xtext.org/example/mydsl/MyDsl">
  <elements>
    <g name="test">
      <package href="cc.mydsl#xtextLink_::0.0.0.0.0::0::/2"/>
    </g>
    <f name="xx">
      <table ecoreTypes="//@elements.0/@g.0">
        <class href="cc.mydsl#xtextLink_::0.0.0.1.1::1::/3"/>
      </table>
    </f>
  </elements>
</myDsl:Model>

references to ecore metamodel are not resolved.
What I should modify in my java code to resolve this problem??

Thank you

[Updated on: Sun, 10 March 2013 11:50]

Report message to a moderator

Re: importURI and cross references during serialization [message #1017248 is a reply to message #1017176] Mon, 11 March 2013 05:55 Go to previous message
Fi Fi is currently offline Fi Fi
Messages: 133
Registered: March 2010
Senior Member
I don't understand what is the utility of importURI if it doesn't work during generating the dsl model!!!!!

Please help me
thanks

[Updated on: Mon, 11 March 2013 05:56]

Report message to a moderator

Previous Topic:Xtype: JvmTypeReference not working as wanted (validation, scope)
Next Topic:How to avoid including ecore for dsl and load dynamically using Namespace uri of the ecore ?
Goto Forum:
  


Current Time: Fri Jul 25 01:20:39 EDT 2014

Powered by FUDForum. Page generated in 0.01758 seconds