Skip to main content

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 15:49 Go to next message
Fa Za is currently offline Fa ZaFriend
Messages: 245
Registered: March 2010
Senior Member
Dear All,
I implement this grammar
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.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{
		String text_file_extension="mydsl";
		String model_file_extension="xmi";
		String strMyDSLFile = args[0];
		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);
		EObject object = resource.getContents().get(0);
		URI uri2 = URI.createFileURI(strMyDSLFile +"."+ model_file_extension);
		XMIResourceFactoryImpl x = new XMIResourceFactoryImpl();
		XMIResource rr = (XMIResource)x.createResource(uri2);
		Map<Object, Object> m = rr.getDefaultSaveOptions();
		m.put(XMIResource.OPTION_USE_XMI_TYPE, Boolean.TRUE);
		try {;
		} catch (IOException e1) {

the generated model is
<?xml version="1.0" encoding="ASCII"?>
<myDsl:Model xmi:version="2.0" xmlns:xmi="" xmlns:myDsl="">
    <g name="test">
      <package href="cc.mydsl#xtextLink_::"/>
    <f name="xx">
      <table ecoreTypes="//@elements.0/@g.0">
        <class href="cc.mydsl#xtextLink_::"/>

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 15: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 09:55 Go to previous message
Fa Za is currently offline Fa ZaFriend
Messages: 245
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

[Updated on: Mon, 11 March 2013 09: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: Mon Feb 24 16:19:55 GMT 2020

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

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

Back to the top