Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » How to resolve cross-references from xtext to xmi?(Serializing xtext model to xmi)
How to resolve cross-references from xtext to xmi? [message #742476] Thu, 20 October 2011 14:27 Go to next message
Ioana  is currently offline Ioana Friend
Messages: 6
Registered: March 2011
Junior Member
Hi,

I'm trying to serialize a xtext model to a xmi, but I've observed that sometimes the cross-refence resolution is not being resolved.

e.g.

entity A
entity B

datatype Str

test T1(
  ent A
  type Str
)


is being serialized to xmi:

 <elements xsi:type="dml:Entity" name="A"/>
 <elements xsi:type="dml:Entity" name="B"/>
 <elements xsi:type="dml:Datatype" name="Str"/>
 <elements xsi:type="Test" name="T1">
    <ent  href="platform:/resource/TestProject/proj/test.dml#xtextLink_::0.3.10::3::/17"/>
    <type href="platform:/resource/TestProject/proj/test.dml#xtextLink_::0.3.10::4::/21"/>
  </elements>


instead of:
<elements xsi:type="dml:Entity" name="A"/>
 <elements xsi:type="dml:Entity" name="B"/>
 <elements xsi:type="dml:Datatype" name="Str"/>
 <elements xsi:type="Test" name="T1" ent="//@elements.0" type="//@elements.2"/>


I've used the following code to realize the serialization:
XMIResource res = new XMIResourceImpl(URI.createURI(exactLocation + xmiFileName + ".xmi"));						res.getContents().add(parseResult.getRootASTElement());
res.save(null);
res.unload();


Why isn't working?

Thank you in advance

Ioana

P.S. The quoted example is processed and the linking fragments may not the ok
Re: How to resolve cross-references from xtext to xmi? [message #742482 is a reply to message #742476] Thu, 20 October 2011 14:34 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 6552
Registered: July 2009
Senior Member
Hi,

the problem is the parseResult.getRootASTElement());
this gives you an unlinked model.
you should read the model as described here
http://wiki.eclipse.org/Xtext/FAQ#How_do_I_load_my_model_in_a_standalone_Java_application.C2.A0.3F

~Christian
Re: How to resolve cross-references from xtext to xmi? [message #742502 is a reply to message #742482] Thu, 20 October 2011 14:53 Go to previous messageGo to next message
Ioana  is currently offline Ioana Friend
Messages: 6
Registered: March 2011
Junior Member
Thank you for your solution. I've tried it and instead off

res.getContents().add(parseResult.getRootASTElement());


I've used
res.getContents().add(model)
after implementing everything like in the link described. Unfortunately, it's not working. The cross-references of the serialized model are not resolved.
Re: How to resolve cross-references from xtext to xmi? [message #742515 is a reply to message #742502] Thu, 20 October 2011 15:06 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 6552
Registered: July 2009
Senior Member
Hi,

the following works for me

public static void main(String[] args) throws IOException {
		Injector injector = new MyDslStandaloneSetup().createInjectorAndDoEMFRegistration();
		ResourceSet resourceSet = injector.getInstance(XtextResourceSet.class);
		Resource xtextResource = resourceSet.getResource(URI.createURI("src/test.mydsl"), true);
		xtextResource.load(null);
		EcoreUtil.resolveAll(xtextResource);
		Resource xmiResource = resourceSet.createResource(URI.createURI("src/test.xmi"));
		xmiResource.getContents().add(xtextResource.getContents().get(0));
		xmiResource.save(null);
	}


~Christian
Re: How to resolve cross-references from xtext to xmi? [message #742663 is a reply to message #742502] Thu, 20 October 2011 17:57 Go to previous messageGo to next message
Moritz Eysholdt is currently offline Moritz EysholdtFriend
Messages: 143
Registered: July 2009
Location: Kiel, Germany
Senior Member
Hi Ioana,

res.getContents().get(0) returns the same as
parseResult.getRootASTElement(). Therefore,
res.getContents().add(parseResult.getRootASTElement()); has no effect.

To solve your problem, you'll need to call
EcoreUtil.resolveAll(xtextResource);
before you serialize your model.

If you then still have cross reference in the format
"xtextLink_::0.3.10:" in your serialized model, then the Xtext file you
have been parsing contains linking errors.

regards,
Moritz

On 20.10.11 16:54, Ioana wrote:
> Thank you for your solution. I've tried it and instead off
> res.getContents().add(parseResult.getRootASTElement());
>
> I've used res.getContents().add(model) after implementing everything
> like in the link described. Unfortunately, it's not working. The
> cross-references of the serialized model are not resolved.
Re: How to resolve cross-references from xtext to xmi? [message #752161 is a reply to message #742663] Wed, 26 October 2011 09:44 Go to previous message
Ioana  is currently offline Ioana Friend
Messages: 6
Registered: March 2011
Junior Member
Hi,

thank you a lot. Your solution and your explanation works now for me. I assumed you must first resolve all the references, but I didn't know how.
Previous Topic:MWE2 running as standalone with external workflow file
Next Topic:resolve cross-reference in LabelProvider
Goto Forum:
  


Current Time: Mon Dec 22 15:07:07 GMT 2014

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

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