Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Serialize cross-reference in stand-alone mode
Serialize cross-reference in stand-alone mode [message #1738402] Tue, 19 July 2016 13:10 Go to next message
Niels Brouwers is currently offline Niels BrouwersFriend
Messages: 80
Registered: July 2009
Member
Hi,

I am experiencing problems when serializing a cross-reference when using Xtext in a stand-alone context.

Below is a sample program that reproduces the serialization problem.

	@Test 
	public void testCrossReferencing() {
                ResourceSet resourceSet = new XtextResourceSet();
		DomainModel dm = XXXFactory.eINSTANCE.createDomainModel();
		dm.setName("TypesModel");
		Type t = XXXFactory.eINSTANCE.createType();
		t.setName("Integer");
		dm.getElements().add(t);
		URI uri1 = URI.createPlatformResourceURI("sample.tests/models/tmp/TypesModel.hddd");
		Resource rs1 = resourceSet.createResource(uri1);
		rs1.getContents().add(dm);
		TypedElement te = XXXFactory.eINSTANCE.createTypedElement();
		te.setType(t);
		te.setName("attr");
		ValueObject vo = XXXFactory.eINSTANCE.createValueObject();
		vo.setName("VO1");
		vo.getAttributes().add(te);
		DomainModel dm2 = XXXFactory.eINSTANCE.createDomainModel();
		dm2.setName("DataModel");
		dm2.getElements().add(vo);
		URI uri2 = URI.createPlatformResourceURI("sample.tests/models/tmp/DataModel.hddd");
		Resource rs2 = resourceSet.createResource(uri2);
		rs2.getContents().add(dm2);
		try {
			rs1.save(Collections.EMPTY_MAP);
			rs2.save(Collections.EMPTY_MAP);
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}


rs2 contains a cross-reference from the TypedElement object to a TypeObject in rs1 via the type reference. The resulting stack trace upon saving rs2 is the following:

java.lang.RuntimeException: No EObjectDescription could be found in Scope TypedElement.type for DomainModel'TypesModel'.elements[0]->Type'Integer'
Semantic Object: DomainModel'DataModel'.elements[0]->ValueObject'VO1'.attributes[0]->TypedElement'attr'
	at org.eclipse.xtext.serializer.diagnostic.ISerializationDiagnostic$ExceptionThrowingAcceptor.accept(ISerializationDiagnostic.java:77)
	at 
...


I have debugged the code up until the point that I could indeed verify that the scope is empty. No candidates exist to resolve the cross-reference.

From loading Xtext resources, I know that cross-references are only resolved when all resources are contained by the XtextResourceSet, so I expected something similar when adding and saving resources.

However, this doesn't seem to be the case. My question therefore is: how to update the index when adding new resources to the resourceset, such that the cross-references get resolved upon serialization of cross-references in Xtext resources?


Kind regards,
Niels Brouwers.
Re: Serialize cross-reference in stand-alone mode [message #1738411 is a reply to message #1738402] Tue, 19 July 2016 13:58 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14729
Registered: July 2009
Senior Member
Can you share a min reproducing example

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Day Job: https://www.everest-systems.com
Re: Serialize cross-reference in stand-alone mode [message #1738425 is a reply to message #1738411] Tue, 19 July 2016 16:12 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14729
Registered: July 2009
Senior Member
btw createPlatformResourceURI does not sound very standalone

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Day Job: https://www.everest-systems.com
Re: Serialize cross-reference in stand-alone mode [message #1738427 is a reply to message #1738425] Tue, 19 July 2016 16:48 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7679
Registered: July 2009
Senior Member
Hi

On the contrary, if you make sure you have a well-configured
URIMap/URIHandler, createPlatformResourceURI is very desirable for
standalone usage. The same code can be used standalone or within Eclipse
without chnage.

Regards

Ed Willink


On 19/07/2016 17:12, Christian Dietrich wrote:
> btw createPlatformResourceURI does not sound very standalone



---
This email has been checked for viruses by Avast antivirus software.
https://www.avast.com/antivirus
Re: Serialize cross-reference in stand-alone mode [message #1738454 is a reply to message #1738427] Wed, 20 July 2016 05:16 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14729
Registered: July 2009
Senior Member
yes. this is why i asked for a reproducable example. with a handmade one i cannot reproduce in standalone, but in eclipse for sure.

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Day Job: https://www.everest-systems.com
Re: Serialize cross-reference in stand-alone mode [message #1738500 is a reply to message #1738454] Wed, 20 July 2016 11:16 Go to previous messageGo to next message
Niels Brouwers is currently offline Niels BrouwersFriend
Messages: 80
Registered: July 2009
Member
Thanks for your replies. The discussion the two of you had triggered me to perform a small experiment where the platform URI is replaced with a file URI. To my surprise, both resources, also the one that contains the cross-reference, were correctly serialized to disk. Great!

Question remains: why was the absolute file URI required for the Xtext index/scoping mechanism to properly resolve the cross-reference during serialization?

Btw. I tried to extend the URIMap of the URIConverter attached to the resourceSet with an entry to map the platform URI onto the file URI:
	URI srcURI = URI.createPlatformResourceURI("sample.tests/");
	URI trgtURI = URI.createFileURI("C:/myworkspace/sample.tests/");
	resourceSet.getURIConverter().getURIMap().put(srcURI, trgtURI);


Somehow, normalization takes no effect so the platform URI from the example is not automatically translated into the physical URI. When I print the string representation of the normalized URI, the file URI is however correct:

	URI uri1 = URI.createURI("platform:/resource/sample.tests/models/tmp/TypesModel.hddd");
	System.out.println(resourceSet.getURIConverter().normalize(uri1).toString());


Console shows output:
file:/C:/myworkspace/sample.tests/tmp/TypesModel.hddd


Any thoughts on this?


Kind regards,
Niels Brouwers.
Re: Serialize cross-reference in stand-alone mode [message #1738502 is a reply to message #1738500] Wed, 20 July 2016 11:26 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14729
Registered: July 2009
Senior Member
This ensures searialized models can be reparsed / the model you serialize
fulfills your scoping rules


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Day Job: https://www.everest-systems.com
Re: Serialize cross-reference in stand-alone mode [message #1738516 is a reply to message #1738502] Wed, 20 July 2016 13:37 Go to previous messageGo to next message
Niels Brouwers is currently offline Niels BrouwersFriend
Messages: 80
Registered: July 2009
Member
Again, thanks for your reply. It still leaves me a bit puzzled to be honest. Can you please elaborate more on the answer to my question? Apparently it's required for the Xtext global scope to be build with resources for which it holds that they can be properly referenced by a absolute file URI. Why is that the case?

Kind regards,
Niels Brouwers.
Re: Serialize cross-reference in stand-alone mode [message #1738536 is a reply to message #1738516] Wed, 20 July 2016 15:43 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14729
Registered: July 2009
Senior Member
Niels Brouwers <forums-noreply@xxxxxxxx> wrote:
> Again, thanks for your reply. It still leaves me a bit puzzled to be
> honest. Can you please elaborate more on the answer to my question?
> Apparently it's required for the Xtext global scope to be build with
> resources for which it holds that they can be properly referenced by a
> absolute file URI. Why is that the case?

I dont get that Part of the question. In standalone mode the global scope
is the sum of all resources in the resourceset but what about your
customization to the scope


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Day Job: https://www.everest-systems.com
Re: Serialize cross-reference in stand-alone mode [message #1738557 is a reply to message #1738402] Wed, 20 July 2016 20:15 Go to previous messageGo to next message
Niels Brouwers is currently offline Niels BrouwersFriend
Messages: 80
Registered: July 2009
Member
The question is why the cross-reference serialization fails when using platform resource URIs (possibly that cannot be properly normalized), but succeeds when using file URIs?

I am not aware of any customizations I made to the global scope, however it could well be the case that I selected a different scope strategy in the MWE2 workflow to allow resolution of cross-references based on fully qualified names.


Kind regards,
Niels Brouwers.
Re: Serialize cross-reference in stand-alone mode [message #1738558 is a reply to message #1738557] Wed, 20 July 2016 20:32 Go to previous message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14729
Registered: July 2009
Senior Member
Niels Brouwers <forums-noreply@xxxxxxxx> wrote:
> The question is why the cross-reference serialization fails when using
> platform resource URIs (possibly that cannot be properly normalized), but
> succeeds when using file URIs?
>
> I am not aware of any customizations I made to the global scope, however
> it could well be the case that I selected a different scope strategy in
> the MWE2 workflow to allow resolution of cross-references based on fully qualified names.

Can you please Share a complete example


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Day Job: https://www.everest-systems.com
Previous Topic:[SOLVED] XtextBuilder issue with a created project from existing model
Next Topic:Xtext/Xtend in C Language
Goto Forum:
  


Current Time: Fri Nov 08 23:23:12 GMT 2024

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

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

Back to the top