Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Model to Text error: resolution of uriFragment 'xtextLink ...
Model to Text error: resolution of uriFragment 'xtextLink ... [message #628400] Thu, 23 September 2010 08:12 Go to next message
Eclipse User
Originally posted by: daniruiz.lcc.uma.es

Hi all,

I am trying to get the ecore model form a textual spec and then
serialize the model to get the textual spec again.

First I get the ecore model from the textual spec using:

XtextResourceSet resourceSet = new XtextResourceSet();
URI uri = URI.createFileURI(textFile);
Resource xtextResource = resourceSet.getResource(uri , true);
Resource xmiResource = new
XMIResourceFactoryImpl().createResource(URI.createFileURI(mo del));
xmiResource.getContents().add(xtextResource.getContents().ge t(0));
xmiResource.save(null);

Then I serialize it back:

Injector injector = new ODPTextStandaloneSetup().createInjector();
ResourceSet set = injector.getInstance(XtextResourceSet.class);
Resource xmi = set.getResource(URI.createFileURI(model), true);
Resource xtext = set.createResource(URI.createFileURI(text));
xtext.getContents().addAll(xmi.getContents()); // or EcoreUtil.copy(..)
xtext.save(null);

The console output is:

3405910 [main] WARN org.eclipse.xtext.linking.lazy.LazyLinkingResource
- resolution of uriFragment
' xtextLink_:://@els.0::http://www.lcc.uma.es/odp/1.0/NV?NV_Ob ject?2::/7'
failed.

java.lang.NullPointerException
at ...

This exception is thrown for each reference in the model.

When I serialize any model generated by a m2m tranformation it works
perfectly. The differences between the two models are in the links
attribute (reference to other objects), in the generated model are like:

<els xsi:type="Engineering:NV_Object" name="Dup">
<links
href=" prueba2.odptext#xtextLink_:://@els.0::http://www.lcc.uma.es/ odp/1.0/NV«NV_Object«2::/7"/>
<links
href=" prueba2.odptext#xtextLink_:://@els.0::http://www.lcc.uma.es/ odp/1.0/NV«NV_Object«2::/9"/>
<links
href=" prueba2.odptext#xtextLink_:://@els.0::http://www.lcc.uma.es/ odp/1.0/NV«NV_Object«2::/11"/>
<links
href=" prueba2.odptext#xtextLink_:://@els.0::http://www.lcc.uma.es/ odp/1.0/NV«NV_Object«2::/13"/>
</els>

and in the m2m transformation output model are:

<els xsi:type="Engineering:NV_Object" name="Dup" links="//@els.8
//@els.7 //@els.4 //@els.5"/>


Any idea? How can I force xtext to generated a model with references
like the model which works?

Thanks!

Daniel Ruiz.
Universidad de Málaga. ETSI Informática.
Bulevar Louis Pasteur, 35. (29071) Malaga. Spain.
Re: Model to Text error: resolution of uriFragment 'xtextLink ... [message #628489 is a reply to message #628400] Thu, 23 September 2010 08:40 Go to previous messageGo to next message
Sebastian Zarnekow is currently offline Sebastian Zarnekow
Messages: 2807
Registered: July 2009
Senior Member
Hi Daniel,

please try to resolve all proxies of your resource before you try to
save it in XMI format.

Regards,
Sebastian
--
Need professional support for Eclipse Modeling?
Go visit: http://xtext.itemis.com

Am 23.09.10 14:12, schrieb Daniel Ruiz:
> Hi all,
>
> I am trying to get the ecore model form a textual spec and then
> serialize the model to get the textual spec again.
>
> First I get the ecore model from the textual spec using:
>
> XtextResourceSet resourceSet = new XtextResourceSet();
> URI uri = URI.createFileURI(textFile);
> Resource xtextResource = resourceSet.getResource(uri , true);
> Resource xmiResource = new
> XMIResourceFactoryImpl().createResource(URI.createFileURI(mo del));
> xmiResource.getContents().add(xtextResource.getContents().ge t(0));
> xmiResource.save(null);
>
> Then I serialize it back:
>
> Injector injector = new ODPTextStandaloneSetup().createInjector();
> ResourceSet set = injector.getInstance(XtextResourceSet.class);
> Resource xmi = set.getResource(URI.createFileURI(model), true);
> Resource xtext = set.createResource(URI.createFileURI(text));
> xtext.getContents().addAll(xmi.getContents()); // or EcoreUtil.copy(..)
> xtext.save(null);
>
> The console output is:
>
> 3405910 [main] WARN org.eclipse.xtext.linking.lazy.LazyLinkingResource -
> resolution of uriFragment
> ' xtextLink_:://@els.0::http://www.lcc.uma.es/odp/1.0/NV?NV_Ob ject?2::/7'
> failed.
>
> java.lang.NullPointerException
> at ...
>
> This exception is thrown for each reference in the model.
>
> When I serialize any model generated by a m2m tranformation it works
> perfectly. The differences between the two models are in the links
> attribute (reference to other objects), in the generated model are like:
>
> <els xsi:type="Engineering:NV_Object" name="Dup">
> <links
> href=" prueba2.odptext#xtextLink_:://@els.0::http://www.lcc.uma.es/ odp/1.0/NV«NV_Object«2::/7"/>
>
> <links
> href=" prueba2.odptext#xtextLink_:://@els.0::http://www.lcc.uma.es/ odp/1.0/NV«NV_Object«2::/9"/>
>
> <links
> href=" prueba2.odptext#xtextLink_:://@els.0::http://www.lcc.uma.es/ odp/1.0/NV«NV_Object«2::/11"/>
>
> <links
> href=" prueba2.odptext#xtextLink_:://@els.0::http://www.lcc.uma.es/ odp/1.0/NV«NV_Object«2::/13"/>
>
> </els>
>
> and in the m2m transformation output model are:
>
> <els xsi:type="Engineering:NV_Object" name="Dup" links="//@els.8
> //@els.7 //@els.4 //@els.5"/>
>
>
> Any idea? How can I force xtext to generated a model with references
> like the model which works?
>
> Thanks!
>
> Daniel Ruiz.
> Universidad de Málaga. ETSI Informática.
> Bulevar Louis Pasteur, 35. (29071) Malaga. Spain.
Re: Model to Text error: resolution of uriFragment 'xtextLink ... [message #629535 is a reply to message #628489] Tue, 28 September 2010 11:34 Go to previous messageGo to next message
Eclipse User
Originally posted by: daniruiz.lcc.uma.es

Thanks!

El 23/09/2010 14:40, Sebastian Zarnekow escribió:
> Hi Daniel,
>
> please try to resolve all proxies of your resource before you try to
> save it in XMI format.
>
> Regards,
> Sebastian
Re: Model to Text error: resolution of uriFragment 'xtextLink ... [message #1112240 is a reply to message #628489] Thu, 19 September 2013 05:44 Go to previous messageGo to next message
Sheetal Bhatewara is currently offline Sheetal Bhatewara
Messages: 13
Registered: August 2013
Junior Member
Hi Sebastian,

I have a grammar written in .xtext file.
Now, the default code generator is in .xtend.
But writing code generator in xtend is not easy for me, as syntax of xtend is new for me.
So, I want to change it to .java code generator.

So, if anyone has worked on it, then please let me know the steps to invoke the java code generator.

[ Right now, with .xtend, using my grammer , the files are getting generated at default location src-gen]
Re: Model to Text error: resolution of uriFragment 'xtextLink ... [message #1112886 is a reply to message #1112240] Fri, 20 September 2013 06:13 Go to previous messageGo to next message
Jan Koehnlein is currently offline Jan Koehnlein
Messages: 655
Registered: July 2009
Senior Member
Java's syntax is really horrible for code generaton. But if you want to
write the IGenerator for your language in Java rather than Xtend anyway:

- Implement IGenerator in Java
- Bind your implementation to the IGenerator interface in the runtime
module of your language

public Class<? extends org.eclipse.xtext.generator.IGenerator>
bindIGenerator() {
return <your implementation class>;
}
- In order to avoid the Xtend stub to be generated add
generateStub = false
in for the GeneratorFragment in the MWE workflow of your language.


Am 19.09.13 11:44, schrieb Sheetal Bhatewara:
> Hi Sebastian,
>
> I have a grammar written in .xtext file.
> Now, the default code generator is in .xtend.
> But writing code generator in xtend is not easy for me, as syntax of
> xtend is new for me.
> So, I want to change it to .java code generator.
>
> So, if anyone has worked on it, then please let me know the steps to
> invoke the java code generator.
>
> [ Right now, with .xtend, using my grammer , the files are getting
> generated at default location src-gen]


--
Need professional support for Eclipse Modeling?
Go visit: http://xtext.itemis.com
Re: Model to Text error: resolution of uriFragment 'xtextLink ... [message #1122310 is a reply to message #1112886] Tue, 01 October 2013 08:35 Go to previous message
Sheetal Bhatewara is currently offline Sheetal Bhatewara
Messages: 13
Registered: August 2013
Junior Member
Thanks, worked for me!
Previous Topic:NPE when serializing an in-memory model
Next Topic:Couldn't resolve reference to JvmIdentifiableElement '=='
Goto Forum:
  


Current Time: Wed Apr 16 09:26:42 EDT 2014

Powered by FUDForum. Page generated in 0.02039 seconds