Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Error serializing CrossRefs: Unable to create a string represenation for refere
Error serializing CrossRefs: Unable to create a string represenation for refere [message #48569] Fri, 05 June 2009 15:17 Go to next message
Cosmin Ciuraru is currently offline Cosmin CiuraruFriend
Messages: 16
Registered: July 2009
Junior Member
Hello,

I've downloaded the TMF Xtext 0.7RC and I'm trying to serialize a model
loaded from a xmi file to text. I use the sample grammair which is created
with every new XText project. I have the following model:

datatype String;
datatype Integer;
datatype Boolean;

class Customer {
attr nume:String;
}

which is serialized to xmi like this:

<?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">
<elements xmi:type="myDsl:DataType" name="String"/>
<elements xmi:type="myDsl:DataType" name="Integer"/>
<elements xmi:type="myDsl:DataType" name="Boolean"/>
<elements xmi:type="myDsl:Class" name="Customer">
<properties xmi:type="myDsl:Attribute" name="nume">
<type
href=" test.mydsl#xtextLink_:://@elements.3/@properties.0::http://w ww.xtext.org/example/MyDsl#//Attribute/type::/5"/>
</properties>
</elements>
</myDsl:Model>


loaded and saved as text with the following code:

/*********************************************************** ********************/

/*
* LOAD DSL XMI MODEL

************************************************************ **************************/

MyDslStandaloneSetup.doSetup();
ResourceSet resourceSet = new ResourceSetImpl();
Resource resource = resourceSet
getResource(URI.createURI("test.mydsl.xmi"),true);
resource.load(null);


/*********************************************************** ***************************/

/*
* WRITE DSL MODEL BACK TO TEXT

************************************************************ *************************/

Resource resource2 =
resourceSet.createResource(URI.createURI("testback.mydsl"), null);
EObject root = resource.getContents().get(0);
resource2.getContents().add(root);
resource2.save(null);

Written to the output file the following result:

datatype String ; datatype Integer ; datatype Boolean ; class Customer {
attr nume :

And generated the following exception:

Exception in thread "main"
org.eclipse.xtext.parsetree.reconstr.XtextSerializationExcep tion: Error
serializing CrossRefs: Unable to create a string represenation for
reference 'DataType' using
org.eclipse.xtext.linking.impl.DefaultLinkingService EReference: type
Context:org.xtext.example.myDsl.impl.AttributeImpl@269997 (name: nume)
Target:org.xtext.example.myDsl.impl.DataTypeImpl@8a0544 (name: String)
at
org.eclipse.xtext.parsetree.reconstr.impl.DefaultCrossRefere nceSerializer.serializeCrossRef(DefaultCrossReferenceSeriali zer.java:37)
at
org.eclipse.xtext.parsetree.reconstr.impl.DefaultTokenSerial izer.elementCrossRef(DefaultTokenSerializer.java:81)
at
org.eclipse.xtext.parsetree.reconstr.impl.DefaultTokenSerial izer.tokenAssignment(DefaultTokenSerializer.java:141)
at
org.eclipse.xtext.parsetree.reconstr.impl.DefaultTokenSerial izer.token(DefaultTokenSerializer.java:133)
at
org.eclipse.xtext.parsetree.reconstr.impl.DefaultTokenSerial izer.serialize(DefaultTokenSerializer.java:124)
at
org.eclipse.xtext.parsetree.reconstr.impl.AbstractFormatting TokenSerializer.serialize(AbstractFormattingTokenSerializer. java:72)
at org.eclipse.xtext.resource.XtextResource.doSave(XtextResourc e.java:189)
at
org.eclipse.emf.ecore.resource.impl.ResourceImpl.save(Resour ceImpl.java:1406)
at
org.eclipse.emf.ecore.resource.impl.ResourceImpl.save(Resour ceImpl.java:993)
at myparser.parser.main(parser.java:78)


Because of (I think,from debug):

public IScopedElement getScopedElement(EObject element) {
Iterable<IScopedElement> allContents = getAllContents();
for (IScopedElement scopedElement : allContents) {
if (scopedElement.element().equals(element))
return scopedElement;
}
return null;
}

The equals returns false, the two instances of DataTypeImpl for String
possibly refer to different objects.

Any suggestions, please? Thank you!

Best regards,
Cosmin
Re: Error serializing CrossRefs: Unable to create a string represenation for refere [message #48631 is a reply to message #48569] Fri, 05 June 2009 15:36 Go to previous messageGo to next message
Sebastian Zarnekow is currently offline Sebastian ZarnekowFriend
Messages: 3118
Registered: July 2009
Senior Member
Hi Cosmin,

please provide the option
XtextResource.OPTION_RESOLVE_ALL, Boolean.True
as parameter to resource.load(..). This will ensure that any EObject
will be resolved. You may check resource.getErrors() for linking
problems. The serialized xmi looks like there have been some issues with
the LazyLinker.

Regards,
Sebastian


Am 05.06.2009 17:17 Uhr, schrieb Cosmin Ciuraru:
> Hello,
>
> I've downloaded the TMF Xtext 0.7RC and I'm trying to serialize a model
> loaded from a xmi file to text. I use the sample grammair which is
> created with every new XText project. I have the following model:
>
> datatype String;
> datatype Integer;
> datatype Boolean;
>
> class Customer {
> attr nume:String;
> }
>
> which is serialized to xmi like this:
>
> <?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">
> <elements xmi:type="myDsl:DataType" name="String"/>
> <elements xmi:type="myDsl:DataType" name="Integer"/>
> <elements xmi:type="myDsl:DataType" name="Boolean"/>
> <elements xmi:type="myDsl:Class" name="Customer">
> <properties xmi:type="myDsl:Attribute" name="nume">
> <type
> href=" test.mydsl#xtextLink_:://@elements.3/@properties.0::http://w ww.xtext.org/example/MyDsl#//Attribute/type::/5"/>
>
> </properties>
> </elements>
> </myDsl:Model>
>
>
> loaded and saved as text with the following code:
>
> /*********************************************************** ********************/
>
>
> /*
> * LOAD DSL XMI MODEL
> ************************************************************ **************************/
>
>
> MyDslStandaloneSetup.doSetup();
> ResourceSet resourceSet = new ResourceSetImpl();
> Resource resource = resourceSet
> getResource(URI.createURI("test.mydsl.xmi"),true); resource.load(null);
> /*********************************************************** ***************************/
>
> /*
> * WRITE DSL MODEL BACK TO TEXT
> ************************************************************ *************************/
>
> Resource resource2 =
> resourceSet.createResource(URI.createURI("testback.mydsl"), null);
> EObject root = resource.getContents().get(0);
> resource2.getContents().add(root);
> resource2.save(null);
>
> Written to the output file the following result:
>
> datatype String ; datatype Integer ; datatype Boolean ; class Customer {
> attr nume :
> And generated the following exception:
>
> Exception in thread "main"
> org.eclipse.xtext.parsetree.reconstr.XtextSerializationExcep tion: Error
> serializing CrossRefs: Unable to create a string represenation for
> reference 'DataType' using
> org.eclipse.xtext.linking.impl.DefaultLinkingService EReference: type
> Context:org.xtext.example.myDsl.impl.AttributeImpl@269997 (name: nume)
> Target:org.xtext.example.myDsl.impl.DataTypeImpl@8a0544 (name: String)
> at
> org.eclipse.xtext.parsetree.reconstr.impl.DefaultCrossRefere nceSerializer.serializeCrossRef(DefaultCrossReferenceSeriali zer.java:37)
>
> at
> org.eclipse.xtext.parsetree.reconstr.impl.DefaultTokenSerial izer.elementCrossRef(DefaultTokenSerializer.java:81)
>
> at
> org.eclipse.xtext.parsetree.reconstr.impl.DefaultTokenSerial izer.tokenAssignment(DefaultTokenSerializer.java:141)
>
> at
> org.eclipse.xtext.parsetree.reconstr.impl.DefaultTokenSerial izer.token(DefaultTokenSerializer.java:133)
>
> at
> org.eclipse.xtext.parsetree.reconstr.impl.DefaultTokenSerial izer.serialize(DefaultTokenSerializer.java:124)
>
> at
> org.eclipse.xtext.parsetree.reconstr.impl.AbstractFormatting TokenSerializer.serialize(AbstractFormattingTokenSerializer. java:72)
>
> at org.eclipse.xtext.resource.XtextResource.doSave(XtextResourc e.java:189)
> at
> org.eclipse.emf.ecore.resource.impl.ResourceImpl.save(Resour ceImpl.java:1406)
>
> at
> org.eclipse.emf.ecore.resource.impl.ResourceImpl.save(Resour ceImpl.java:993)
>
> at myparser.parser.main(parser.java:78)
>
>
> Because of (I think,from debug):
>
> public IScopedElement getScopedElement(EObject element) {
> Iterable<IScopedElement> allContents = getAllContents();
> for (IScopedElement scopedElement : allContents) {
> if (scopedElement.element().equals(element))
> return scopedElement;
> }
> return null;
> }
>
> The equals returns false, the two instances of DataTypeImpl for String
> possibly refer to different objects.
> Any suggestions, please? Thank you!
>
> Best regards,
> Cosmin
>
>
>
Re: Error serializing CrossRefs: Unable to create a string represenation for refere [message #48717 is a reply to message #48631] Fri, 05 June 2009 16:19 Go to previous messageGo to next message
Cosmin Ciuraru is currently offline Cosmin CiuraruFriend
Messages: 16
Registered: July 2009
Junior Member
I use this code now with the same error. GetError returns no elements.

MyDslStandaloneSetup.doSetup();
ResourceSet resourceSet = new ResourceSetImpl();
Resource resource =
resourceSet.getResource(URI.createURI("test.mydsl.xmi"), true);
Map m = new HashMap();
m.put(XtextResource.OPTION_RESOLVE_ALL, Boolean.TRUE);
resource.load(m);
List<Diagnostic> err = resource.getErrors();

Resource resource2
=resourceSet.createResource(URI.createURI("testback.mydsl"));
EObject root = resource.getContents().get(0);
resource2.getContents().add(root);

resource2.save(null);

I save the xmi file with this code:

String strMyDSLFile = "My.mydsl";
MyDslStandaloneSetup.doSetup();
ResourceSet resourceSet = new ResourceSetImpl();
URI uri = URI.createFileURI(strMyDSLFile);
Resource resource = resourceSet.getResource(uri, true);

EObject object = resource.getContents().iterator().next();

URI uri2 = URI.createFileURI(strMyDSLFile + ".xmi");
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();
}

Thank you!

Regards,
Cosmin
Re: Error serializing CrossRefs: Unable to create a string represenation for refere [message #48747 is a reply to message #48569] Fri, 05 June 2009 16:47 Go to previous messageGo to next message
Moritz Eysholdt is currently offline Moritz EysholdtFriend
Messages: 161
Registered: July 2009
Location: Kiel, Germany
Senior Member
Hi Cosmin,

for me this looks like the target of your cross reference is an
EDataType and not an EClass. Could you post the grammar rule that
contains the cross reference and the grammar rule that creates the
object that is being referenced?

regards,
Moritz

> Hello,
>
> I've downloaded the TMF Xtext 0.7RC and I'm trying to serialize a model
> loaded from a xmi file to text. I use the sample grammair which is
> created with every new XText project. I have the following model:
>
> datatype String;
> datatype Integer;
> datatype Boolean;
>
> class Customer {
> attr nume:String;
> }
>
> which is serialized to xmi like this:
>
> <?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">
> <elements xmi:type="myDsl:DataType" name="String"/>
> <elements xmi:type="myDsl:DataType" name="Integer"/>
> <elements xmi:type="myDsl:DataType" name="Boolean"/>
> <elements xmi:type="myDsl:Class" name="Customer">
> <properties xmi:type="myDsl:Attribute" name="nume">
> <type
> href=" test.mydsl#xtextLink_:://@elements.3/@properties.0::http://w ww.xtext.org/example/MyDsl#//Attribute/type::/5"/>
>
> </properties>
> </elements>
> </myDsl:Model>
>
>
> loaded and saved as text with the following code:
>
> /*********************************************************** ********************/
>
>
> /*
> * LOAD DSL XMI MODEL
>
> ************************************************************ **************************/
>
>
> MyDslStandaloneSetup.doSetup();
> ResourceSet resourceSet = new ResourceSetImpl();
> Resource resource = resourceSet
> getResource(URI.createURI("test.mydsl.xmi"),true);
> resource.load(null);
>
> /*********************************************************** ***************************/
>
> /*
> * WRITE DSL MODEL BACK TO TEXT
>
> ************************************************************ *************************/
>
> Resource resource2 =
> resourceSet.createResource(URI.createURI("testback.mydsl"), null);
> EObject root = resource.getContents().get(0);
> resource2.getContents().add(root);
> resource2.save(null);
>
> Written to the output file the following result:
>
> datatype String ; datatype Integer ; datatype Boolean ; class Customer {
> attr nume :
> And generated the following exception:
>
> Exception in thread "main"
> org.eclipse.xtext.parsetree.reconstr.XtextSerializationExcep tion: Error
> serializing CrossRefs: Unable to create a string represenation for
> reference 'DataType' using
> org.eclipse.xtext.linking.impl.DefaultLinkingService EReference: type
> Context:org.xtext.example.myDsl.impl.AttributeImpl@269997 (name: nume)
> Target:org.xtext.example.myDsl.impl.DataTypeImpl@8a0544 (name: String)
> at
> org.eclipse.xtext.parsetree.reconstr.impl.DefaultCrossRefere nceSerializer.serializeCrossRef(DefaultCrossReferenceSeriali zer.java:37)
>
> at
> org.eclipse.xtext.parsetree.reconstr.impl.DefaultTokenSerial izer.elementCrossRef(DefaultTokenSerializer.java:81)
>
> at
> org.eclipse.xtext.parsetree.reconstr.impl.DefaultTokenSerial izer.tokenAssignment(DefaultTokenSerializer.java:141)
>
> at
> org.eclipse.xtext.parsetree.reconstr.impl.DefaultTokenSerial izer.token(DefaultTokenSerializer.java:133)
>
> at
> org.eclipse.xtext.parsetree.reconstr.impl.DefaultTokenSerial izer.serialize(DefaultTokenSerializer.java:124)
>
> at
> org.eclipse.xtext.parsetree.reconstr.impl.AbstractFormatting TokenSerializer.serialize(AbstractFormattingTokenSerializer. java:72)
>
> at
> org.eclipse.xtext.resource.XtextResource.doSave(XtextResourc e.java:189)
> at
> org.eclipse.emf.ecore.resource.impl.ResourceImpl.save(Resour ceImpl.java:1406)
>
> at
> org.eclipse.emf.ecore.resource.impl.ResourceImpl.save(Resour ceImpl.java:993)
>
> at myparser.parser.main(parser.java:78)
>
>
> Because of (I think,from debug):
>
> public IScopedElement getScopedElement(EObject element) {
> Iterable<IScopedElement> allContents = getAllContents();
> for (IScopedElement scopedElement : allContents) {
> if (scopedElement.element().equals(element))
> return scopedElement;
> }
> return null;
> }
>
> The equals returns false, the two instances of DataTypeImpl for String
> possibly refer to different objects.
> Any suggestions, please? Thank you!
>
> Best regards,
> Cosmin
>
>
>
Re: Error serializing CrossRefs: Unable to create a string represenation for refere [message #48777 is a reply to message #48747] Fri, 05 June 2009 16:58 Go to previous messageGo to next message
Cosmin Ciuraru is currently offline Cosmin CiuraruFriend
Messages: 16
Registered: July 2009
Junior Member
Hi Moritz,

The rule Attribute references the rule DataType.
Here's the entire grammair:

grammar org.xtext.example.MyDsl with org.eclipse.xtext.common.Terminals

generate myDsl "http://www.xtext.org/example/MyDsl"


Model :
(imports+=Import)*
(elements+=Type)*;

Import :
'import' importURI=STRING;

Type:
DataType | Class;

DataType:
'datatype' name=ID ';'?;

Class :
'class' name=ID ('extends' superClass=[Class])? '{'
properties+=Property*
'}';

Property:
Attribute | Reference;

Attribute:
'attr' name=ID ':' type=[DataType] ';'?;

Reference:
'ref' name=ID ':' type=[Class] ';'?;


Thank you!

Regards,
Cosmin
Re: Error serializing CrossRefs: Unable to create a string represenation for refere [message #48806 is a reply to message #48717] Fri, 05 June 2009 17:40 Go to previous messageGo to next message
Sven Efftinge is currently offline Sven EfftingeFriend
Messages: 1823
Registered: July 2009
Senior Member
Hi Cosmin,

Cosmin Ciuraru schrieb:
> I use this code now with the same error. GetError returns no elements.
>
> MyDslStandaloneSetup.doSetup();
> ResourceSet resourceSet = new ResourceSetImpl();
> Resource resource =
> resourceSet.getResource(URI.createURI("test.mydsl.xmi"), true);
> Map m = new HashMap();
> m.put(XtextResource.OPTION_RESOLVE_ALL, Boolean.TRUE);
> resource.load(m);
> List<Diagnostic> err = resource.getErrors();
>
> Resource resource2
> =resourceSet.createResource(URI.createURI("testback.mydsl"));
> EObject root = resource.getContents().get(0);
> resource2.getContents().add(root);
>
> resource2.save(null);

Here you load an xmi resource and save it with an xtext resource.
This should work, but is probably not what you wanted.
I understood that you tried to load an xtext resource and save the
contents in an xmi resource, right? So maybe you should switch the URIs
in above's code?


>
> I save the xmi file with this code:
>
> String strMyDSLFile = "My.mydsl";
> MyDslStandaloneSetup.doSetup();
> ResourceSet resourceSet = new ResourceSetImpl();
> URI uri = URI.createFileURI(strMyDSLFile);
> Resource resource = resourceSet.getResource(uri, true);
>
> EObject object = resource.getContents().iterator().next();
>
> URI uri2 = URI.createFileURI(strMyDSLFile + ".xmi");
> 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();
> }
>

Here, the load option (OPTION_RESOLVE_ALL) is missing.

Cheers,
Sven
Re: Error serializing CrossRefs: Unable to create a string represenation for refere [message #48835 is a reply to message #48717] Fri, 05 June 2009 18:55 Go to previous messageGo to next message
Sebastian Zarnekow is currently offline Sebastian ZarnekowFriend
Messages: 3118
Registered: July 2009
Senior Member
Hi Cosmin,

sorry, I confused something. As far as I understood you correctly,
you loaded the sample model with xtext, serialized it as xmi (with the
proxy uri "..xtextlink..."), reloaded it and tried to serialize it in
the concrete syntax of your dsl.
The problem was, that you loaded the original dsl model without the load
option OPTION_RESOLVE_ALL. That's why, the xtext specific proxy uri has
been used in your xmi file, which in turn is useless when loaded from
xmi, as it relies on additional information, that is created by the
xtext parser.

I advise you to load your dsl model with the above mentioned option,
save your xmi, confirm that it does not contain an xtextlink-uri, and
retry to save it back into your dsl syntax with the code, that you
showed in your first post.

Sorry for inconvenience,
Sebastian

Am 05.06.2009 18:19 Uhr, schrieb Cosmin Ciuraru:
> I use this code now with the same error. GetError returns no elements.
>
> MyDslStandaloneSetup.doSetup();
> ResourceSet resourceSet = new ResourceSetImpl();
> Resource resource =
> resourceSet.getResource(URI.createURI("test.mydsl.xmi"), true);
> Map m = new HashMap();
> m.put(XtextResource.OPTION_RESOLVE_ALL, Boolean.TRUE);
> resource.load(m);
> List<Diagnostic> err = resource.getErrors();
>
> Resource resource2
> =resourceSet.createResource(URI.createURI("testback.mydsl"));
> EObject root = resource.getContents().get(0);
> resource2.getContents().add(root);
>
> resource2.save(null);
>
> I save the xmi file with this code:
>
> String strMyDSLFile = "My.mydsl";
> MyDslStandaloneSetup.doSetup();
> ResourceSet resourceSet = new ResourceSetImpl();
> URI uri = URI.createFileURI(strMyDSLFile);
> Resource resource = resourceSet.getResource(uri, true);
>
> EObject object = resource.getContents().iterator().next();
>
> URI uri2 = URI.createFileURI(strMyDSLFile + ".xmi");
> 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();
> }
>
> Thank you!
>
> Regards,
> Cosmin
>
>
Re: Error serializing CrossRefs: Unable to create a string represenation for refere [message #48865 is a reply to message #48806] Fri, 05 June 2009 19:08 Go to previous messageGo to next message
Cosmin Ciuraru is currently offline Cosmin CiuraruFriend
Messages: 16
Registered: July 2009
Junior Member
Hi Sven,

The initial plan was to check out the m2t (serialization) offered in the
new XText. I'll try to put things together, in order to offer a clear
perspective on my trials. So, I've started with the default grammair:

Model :
(imports+=Import)*
(elements+=Type)*;

Import :
'import' importURI=STRING;

Type:
DataType | Class;

DataType:
'datatype' name=ID ';'?;

Class :
'class' name=ID ('extends' superClass=[Class])? '{'
properties+=Property*
'}';

Property:
Attribute | Reference;

Attribute:
'attr' name=ID ':' type=[DataType] ';'?;

Reference:
'ref' name=ID ':' type=[Class] ';'?;

For this grammair, I've created a simple text model:

datatype String;
datatype Integer;
datatype Boolean;

class Customer {
attr nume:String;
}

I used the following code in order to serialize this text model in xmi
format, according to the metamodel generated by XText:

String strMyDSLFile = "My.mydsl";
MyDslStandaloneSetup.doSetup();
ResourceSet resourceSet = new ResourceSetImpl();
URI uri = URI.createFileURI(strMyDSLFile);
Resource resource = resourceSet.getResource(uri, true);

EObject object = resource.getContents().iterator().next();

URI uri2 = URI.createFileURI(strMyDSLFile + ".xmi");
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();
}

I can't try out saving with the option RESOLVE_ALL right now, but I'll
give it a try as soon as possible.
After creating the xmi file, I want to load it into memory as a resource
and write it back as a text model, to complete the verification. For this,
I do like this:

MyDslStandaloneSetup.doSetup();
ResourceSet resourceSet = new ResourceSetImpl();
Resource resource =
resourceSet.getResource(URI.createURI("test.mydsl.xmi"), true);
Map m = new HashMap();
m.put(XtextResource.OPTION_RESOLVE_ALL, Boolean.TRUE);
resource.load(m);
List<Diagnostic> err = resource.getErrors();

Resource resource2
=resourceSet.createResource(URI.createURI("testback.mydsl"));
EObject root = resource.getContents().get(0);
resource2.getContents().add(root);

resource2.save(null);

I expect to obtain the initial text model.

I also tried creating a dsl model graphically (exporting plugin of the dsl
metamodel and using an editor), but, as expected, it gets saved with the
extension specific for the dsl model and when I try to load it as a
resource, it thinks it's a text model and tries to parse it, thus
generating some errors.
(Dumb question: will changing the extension make it possible for a
graphically created model to be loaded as a resource according to the
metamodel and not parsed?)

Hope I made things clearer and thank you for your patience.

Regards,
Cosmin
Re: Error serializing CrossRefs: Unable to create a string represenation for refere [message #48894 is a reply to message #48865] Fri, 05 June 2009 19:35 Go to previous messageGo to next message
Sven Efftinge is currently offline Sven EfftingeFriend
Messages: 1823
Registered: July 2009
Senior Member
Cosmin Ciuraru schrieb:
> I used the following code in order to serialize this text model in xmi
> format, according to the metamodel generated by XText:
>
> String strMyDSLFile = "My.mydsl";
> MyDslStandaloneSetup.doSetup();
> ResourceSet resourceSet = new ResourceSetImpl();
> URI uri = URI.createFileURI(strMyDSLFile);

you need to replace the following line ...

> Resource resource = resourceSet.getResource(uri, true);

.... with ...

Resource resource = resourceSet.getResource(uri, false);
Map m = new HashMap();
m.put(XtextResource.OPTION_RESOLVE_ALL, Boolean.TRUE);
resource.load(m);

that is what Sebastian meant.

Background:
In Xtext we use proxies to do lazy linking. The URIs in those proxies
are only meaningful to XtextResources. But if you put such prxies into
an XMI resources the XMI resource avoids expensive reslution of proxies
but just writes them to the XMI as is. When loading the XMI resource
tries to load the lazy linking URI which does not work.
Therefore all lazy linking proxies have to be resolved before you put
them into another resource. This is what the load option
OPTION_RESOLVE_ALL is for.

hope that helps,
Sven
Re: Error serializing CrossRefs: Unable to create a string represenation for refere [message #48924 is a reply to message #48865] Fri, 05 June 2009 19:42 Go to previous messageGo to next message
Sven Efftinge is currently offline Sven EfftingeFriend
Messages: 1823
Registered: July 2009
Senior Member
Cosmin Ciuraru schrieb:
> I also tried creating a dsl model graphically (exporting plugin of the
> dsl metamodel and using an editor), but, as expected, it gets saved with
> the extension specific for the dsl model and when I try to load it as a
> resource, it thinks it's a text model and tries to parse it, thus
> generating some errors.
> (Dumb question: will changing the extension make it possible for a
> graphically created model to be loaded as a resource according to the
> metamodel and not parsed?)

I'm not sure I understand. From the EMF Resource API point of viewe
there's no difference in using an XMI or an Xtext resource.
Any EMF editor working on that API shoudn't care and should like wise
work with XMI resources or Xtext resources.

There are different ways to control what kind of resource is created,
but generally it is determined by the file extension.
And if there's no mapping, usually the catch all is the XMI resource.

Sven
Re: Error serializing CrossRefs: Unable to create a string represenation for refere [message #48951 is a reply to message #48894] Sat, 06 June 2009 12:17 Go to previous messageGo to next message
Cosmin Ciuraru is currently offline Cosmin CiuraruFriend
Messages: 16
Registered: July 2009
Junior Member
Hi Sven,

It worked and I understood what you'd explained. I have just one amendment
to make:

Resource resource = resourceSet.getResource(uri, false);

will return null for the resource; if we change the loadoption to true,
the resource will be returned correctly but the xmi file will still
contain the xtextlink.

I've solved this one with:

Resource resource = resourceSet.createResource(uri);

Most probably, my observation is trivial, but as a beginner with eclipse,
emf and oaw... I tend to stumble a lot. So thank you Sven and Sebastian,
you've solved my problem.

Best regards,
Cosmin
Re: Error serializing CrossRefs: Unable to create a string represenation for refere [message #48980 is a reply to message #48924] Sat, 06 June 2009 12:50 Go to previous messageGo to next message
Cosmin Ciuraru is currently offline Cosmin CiuraruFriend
Messages: 16
Registered: July 2009
Junior Member
I'll try to explain myself. I took the ecore metamodel generated by XText,
created an EMF project, added a genmodel and generated all the code. I
then exported the packages as a plugin. I can now use the ecore editor, in
order to build a model (add childs, siblings...of certain types). The
result is a file, with a XML-like structure, which I can open and
visualize with the ecore editor. The problem is that this file has the
same extension as a file which contains a model text of my metamodel (the
one that is supposed to be parsed by the XText generated parser). Now, if
I want to load into a resource, the file built with the ecore editor, it
will think it is a text model and thus try to parse it according to my
grammair. This is why I created a xmi file, to avoid having the same
extension as the text model has. So, the post where I ask the dumb
question ( :-) ), was to see whether I can just change the extension of my
ecore-editor-built file to something else in order to be loaded as it is
and not parsed. I hope I'm not being too much off topic, the idea was just
to explain why I had to load, serialize, load and serialize again, as
Sebastian remarked in his post.

Thank you once again,
Cosmin
Re: Error serializing CrossRefs: Unable to create a string represenation for refere [message #48991 is a reply to message #48980] Sat, 06 June 2009 13:01 Go to previous messageGo to next message
Sebastian Zarnekow is currently offline Sebastian ZarnekowFriend
Messages: 3118
Registered: July 2009
Senior Member
Hi Cosmin,

have you tried Open With ... Sample Ecore Editor on your DSL file? You
will be suprised, as the tree-like editor will work fine with you DSL
file. Usually there is no need to store anything in XMI when Xtext comes
into play.

Regards,
Sebastian

Am 06.06.2009 14:50 Uhr, schrieb Cosmin Ciuraru:
> I'll try to explain myself. I took the ecore metamodel generated by
> XText, created an EMF project, added a genmodel and generated all the
> code. I then exported the packages as a plugin. I can now use the ecore
> editor, in order to build a model (add childs, siblings...of certain
> types). The result is a file, with a XML-like structure, which I can
> open and visualize with the ecore editor. The problem is that this file
> has the same extension as a file which contains a model text of my
> metamodel (the one that is supposed to be parsed by the XText generated
> parser). Now, if I want to load into a resource, the file built with the
> ecore editor, it will think it is a text model and thus try to parse it
> according to my grammair. This is why I created a xmi file, to avoid
> having the same extension as the text model has. So, the post where I
> ask the dumb question ( :-) ), was to see whether I can just change the
> extension of my ecore-editor-built file to something else in order to be
> loaded as it is and not parsed. I hope I'm not being too much off topic,
> the idea was just to explain why I had to load, serialize, load and
> serialize again, as Sebastian remarked in his post.
> Thank you once again,
> Cosmin
>
Re: Error serializing CrossRefs: Unable to create a string represenation for refere [message #49107 is a reply to message #48991] Mon, 08 June 2009 07:31 Go to previous messageGo to next message
Cosmin Ciuraru is currently offline Cosmin CiuraruFriend
Messages: 16
Registered: July 2009
Junior Member
Hi Sebastian,

When you say the DSL file you refer to:

<?xml version="1.0" encoding="UTF-8"?>
<myDsl:Model xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:myDsl="http://www.xtext.org/example/MyDsl">
<elements xsi:type="myDsl:Class" name="MyClass">
<properties xsi:type="myDsl:Attribute" name="MyAtrr"
type="//@elements.1"/>
<properties name="getSmth"/>
</elements>
<elements xsi:type="myDsl:DataType" name="String"/>
</myDsl:Model>

or to:

datatype String;
datatype Integer;
datatype Boolean;

class Customer {
attr nume:String;
}

For the former, the ecore editor works, for the latter, it says:

org.eclipse.emf.ecore.resource.impl.ResourceSetImpl$1Diagnos ticWrappedException:
org.xml.sax.SAXParseException: Content is not allowed in prolog.
at
org.eclipse.emf.ecore.resource.impl.ResourceSetImpl.handleDe mandLoadException(ResourceSetImpl.java:315)
at
org.eclipse.emf.ecore.resource.impl.ResourceSetImpl.demandLo adHelper(ResourceSetImpl.java:274)
at
org.eclipse.emf.ecore.resource.impl.ResourceSetImpl.getResou rce(ResourceSetImpl.java:397)
at myDsl.presentation.MyDslEditor.createModel(MyDslEditor.java: 945)
at myDsl.presentation.MyDslEditor.createPages(MyDslEditor.java: 1002)
at
org.eclipse.ui.part.MultiPageEditorPart.createPartControl(Mu ltiPageEditorPart.java:357)
at
org.eclipse.ui.internal.EditorReference.createPartHelper(Edi torReference.java:662)
at
org.eclipse.ui.internal.EditorReference.createPart(EditorRef erence.java:462)
at
org.eclipse.ui.internal.WorkbenchPartReference.getPart(Workb enchPartReference.java:595)
at
org.eclipse.ui.internal.EditorReference.getEditor(EditorRefe rence.java:286)
at
org.eclipse.ui.internal.WorkbenchPage.busyOpenEditorBatched( WorkbenchPage.java:2857)
at
org.eclipse.ui.internal.WorkbenchPage.busyOpenEditor(Workben chPage.java:2762)
at
org.eclipse.ui.internal.WorkbenchPage.access$11(WorkbenchPag e.java:2754)
at org.eclipse.ui.internal.WorkbenchPage$10.run(WorkbenchPage.j ava:2705)
at org.eclipse.swt.custom.BusyIndicator.showWhile(BusyIndicator .java:70)
at
org.eclipse.ui.internal.WorkbenchPage.openEditor(WorkbenchPa ge.java:2701)
at
org.eclipse.ui.internal.WorkbenchPage.openEditor(WorkbenchPa ge.java:2685)
at org.eclipse.ui.actions.OpenWithMenu.openEditor(OpenWithMenu. java:344)
at
org.eclipse.ui.actions.OpenWithMenu$4.handleEvent(OpenWithMe nu.java:373)
at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java :84)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1176)
at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.ja va:3485)
at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java :3104)
at org.eclipse.ui.internal.Workbench.runEventLoop(Workbench.jav a:2405)
at org.eclipse.ui.internal.Workbench.runUI(Workbench.java:2369)
at org.eclipse.ui.internal.Workbench.access$4(Workbench.java:22 21)
at org.eclipse.ui.internal.Workbench$5.run(Workbench.java:500)
at
org.eclipse.core.databinding.observable.Realm.runWithDefault (Realm.java:332)
at
org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Work bench.java:493)
at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.j ava:149)
at
org.eclipse.ui.internal.ide.application.IDEApplication.start (IDEApplication.java:113)
at
org.eclipse.equinox.internal.app.EclipseAppHandle.run(Eclips eAppHandle.java:194)
at
org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher .runApplication(EclipseAppLauncher.java:110)
at
org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher .start(EclipseAppLauncher.java:79)
at
org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseS tarter.java:368)
at
org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseS tarter.java:179)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAcce ssorImpl.java:39)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMe thodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java: 559)
at org.eclipse.equinox.launcher.Main.basicRun(Main.java:514)
at org.eclipse.equinox.launcher.Main.run(Main.java:1311)
Caused by: org.xml.sax.SAXParseException: Content is not allowed in prolog.
at
com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper. createSAXParseException(ErrorHandlerWrapper.java:195)
at
com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper. fatalError(ErrorHandlerWrapper.java:174)
at
com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.rep ortError(XMLErrorReporter.java:388)
at
com.sun.org.apache.xerces.internal.impl.XMLScanner.reportFat alError(XMLScanner.java:1411)
at
com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerIm pl$PrologDriver.next(XMLDocumentScannerImpl.java:1038)
at
com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerIm pl.next(XMLDocumentScannerImpl.java:648)
at
com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentS cannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java: 510)
at
com.sun.org.apache.xerces.internal.parsers.XML11Configuratio n.parse(XML11Configuration.java:807)
at
com.sun.org.apache.xerces.internal.parsers.XML11Configuratio n.parse(XML11Configuration.java:737)
at
com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(X MLParser.java:107)
at
com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser .parse(AbstractSAXParser.java:1205)
at
com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSA XParser.parse(SAXParserImpl.java:522)
at javax.xml.parsers.SAXParser.parse(SAXParser.java:395)
at org.eclipse.emf.ecore.xmi.impl.XMLLoadImpl.load(XMLLoadImpl. java:181)
at
org.eclipse.emf.ecore.xmi.impl.XMLResourceImpl.doLoad(XMLRes ourceImpl.java:180)
at
org.eclipse.emf.ecore.resource.impl.ResourceImpl.load(Resour ceImpl.java:1494)
at
org.eclipse.emf.ecore.resource.impl.ResourceImpl.load(Resour ceImpl.java:1282)
at
org.eclipse.emf.ecore.resource.impl.ResourceSetImpl.demandLo ad(ResourceSetImpl.java:255)
at
org.eclipse.emf.ecore.resource.impl.ResourceSetImpl.demandLo adHelper(ResourceSetImpl.java:270)
... 41 more


I would like to achieve a workflow in which I make a m2m transformation in
atl, in which the target model will be written to a file, having a
xml-like layout (see first form of this post). I then want to load the
file as a resource and transform it to text, as in the second form of my
post. That is why I said, that when I try to load the file in the first
form, using the code I posted, it tries to parse it, thinking it's a text
model already.

Regards,
Cosmin
Re: Error serializing CrossRefs: Unable to create a string represenation for refere [message #49608 is a reply to message #49107] Tue, 09 June 2009 08:37 Go to previous messageGo to next message
Sebastian Zarnekow is currently offline Sebastian ZarnekowFriend
Messages: 3118
Registered: July 2009
Senior Member
Hi Cosmin,

please find my answer below.

Am 08.06.2009 9:31 Uhr, schrieb Cosmin Ciuraru:
> Hi Sebastian,
>
> When you say the DSL file you refer to:
>
> <?xml version="1.0" encoding="UTF-8"?>
> <myDsl:Model xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI"
> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
> xmlns:myDsl="http://www.xtext.org/example/MyDsl">
> <elements xsi:type="myDsl:Class" name="MyClass">
> <properties xsi:type="myDsl:Attribute" name="MyAtrr" type="//@elements.1"/>
> <properties name="getSmth"/>
> </elements>
> <elements xsi:type="myDsl:DataType" name="String"/>
> </myDsl:Model>
>
> or to:
>
> datatype String;
> datatype Integer;
> datatype Boolean;
>
> class Customer {
> attr nume:String;
> }
>

I refer to the latter.

> For the former, the ecore editor works, for the latter, it says:
>
If I understand the stacktrace correctly, you generated the EMF
treebased editor from your genmodel. It looks like you registered the
xtext editor and resource with the same file extension as the xtext editor.

> org.eclipse.emf.ecore.resource.impl.ResourceSetImpl$1Diagnos ticWrappedException:
> org.xml.sax.SAXParseException: Content is not allowed in prolog.
> at
> org.eclipse.emf.ecore.resource.impl.ResourceSetImpl.handleDe mandLoadException(ResourceSetImpl.java:315)
>
> at
> org.eclipse.emf.ecore.resource.impl.ResourceSetImpl.demandLo adHelper(ResourceSetImpl.java:274)
>
> at
> org.eclipse.emf.ecore.resource.impl.ResourceSetImpl.getResou rce(ResourceSetImpl.java:397)
>
> at myDsl.presentation.MyDslEditor.createModel(MyDslEditor.java: 945)
> at myDsl.presentation.MyDslEditor.createPages(MyDslEditor.java: 1002)
> at
> org.eclipse.ui.part.MultiPageEditorPart.createPartControl(Mu ltiPageEditorPart.java:357)
>
> at
> org.eclipse.ui.internal.EditorReference.createPartHelper(Edi torReference.java:662)

[snip]

>
>
> I would like to achieve a workflow in which I make a m2m transformation
> in atl, in which the target model will be written to a file, having a
> xml-like layout (see first form of this post). I then want to load the
> file as a resource and transform it to text, as in the second form of my
> post. That is why I said, that when I try to load the file in the first
> form, using the code I posted, it tries to parse it, thinking it's a
> text model already.
>

Can you please outline in a few words, what you want to do at all.
Something like "I want to edit DSL and generate XYZ", without the
intermediate formats that are not part of the requirements.
I've the impression, that the described steps are not necessary.

Xtext ships with an EMF Resource implementation. The interface has
methods like load(Stream), save(Stream) and List<EObject>:getContents().
This resource will utilize the DSL parser to create your semantic model.
Other tools like GMF, ATL et al will be able to work with this resource,
even if they don't have any clue about Xtext. That's part of the EMF
Framework functionality.

Hope that helps,
Sebastian


> Regards,
> Cosmin
>
Re: Error serializing CrossRefs: Unable to create a string represenation for refere [message #49757 is a reply to message #49608] Wed, 10 June 2009 12:37 Go to previous messageGo to next message
Cosmin Ciuraru is currently offline Cosmin CiuraruFriend
Messages: 16
Registered: July 2009
Junior Member
Hi Sebastian,

I think you're right, I have the same extension both for the treelike
editor and the XText editor so it's normal to crush due to this ambiguity.

In my project I have to write a m2m transformation, whose target model has
as metamodel an ecore created by XText (I've written the grammair rules
and XText generated the metamodel). I'll have the target model written to
a file and I would like to be able to load this file as a resource and
make a m2t transformation on it, in order to get the dsl text
represantation of the target model. When I try to load the file as a
resource, because of the extension, it tries to parse it with the XText
generated parser and throws an error because it has a xml structure and
it's not a dsl file. How should I tackle this? (changing the name of the
metamodel before using the genmodel will solve it?)

Thank you,
Cosmin
Re: Error serializing CrossRefs: Unable to create a string represenation for refere [message #49913 is a reply to message #49757] Thu, 11 June 2009 07:18 Go to previous message
Sven Efftinge is currently offline Sven EfftingeFriend
Messages: 1823
Registered: July 2009
Senior Member
Hi Cosmin,

we're getting closer :-)

From what I udnerstood, the process is :

1) you've got some infromation (don't know in what format)
2) you've written an M2M transformation transforming the given
information into an instance of an Xtext-generated ecore model
3) you want to write the model to the disk
4) you ant to load it again
5) in order to pass it to an m2t transformation
6) to finally get the textual representation of that model

Is that right?

So basically you want to
1) transform the given information to
3) the textual representation defined with Xtext

That's pretty easy.
All you need to do is to make sure that you use the right Recource
implementation, when storing the outcome of the M2M trafo.

Xtext generates a special ResourceFactory. You have to make sure that
this resource factory is registered in the global registry. This can
either be done by extension points (see the generated plugin.xml) or
done programmatically (see the generated standalone setup).

The resource will automatically save to the textual representation.
The M2M or any other component which just relies on EMF API won't care,
i.e. they don't expect the resource to save information in XMI.

Cheers,
Sven


Cosmin Ciuraru schrieb:
> Hi Sebastian,
>
> I think you're right, I have the same extension both for the treelike
> editor and the XText editor so it's normal to crush due to this ambiguity.
>
> In my project I have to write a m2m transformation, whose target model
> has as metamodel an ecore created by XText (I've written the grammair
> rules and XText generated the metamodel). I'll have the target model
> written to a file and I would like to be able to load this file as a
> resource and make a m2t transformation on it, in order to get the dsl
> text represantation of the target model. When I try to load the file as
> a resource, because of the extension, it tries to parse it with the
> XText generated parser and throws an error because it has a xml
> structure and it's not a dsl file. How should I tackle this? (changing
> the name of the metamodel before using the genmodel will solve it?)
>
> Thank you,
> Cosmin
>
>
>
Previous Topic:[Xtext] Controlling import search path
Next Topic:download for RC3 fails
Goto Forum:
  


Current Time: Sat Apr 20 03:15:42 GMT 2024

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

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

Back to the top