Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Parser and models
Parser and models [message #650816] Wed, 26 January 2011 17:06 Go to next message
chuck  is currently offline chuck Friend
Messages: 160
Registered: July 2010
Senior Member
In java class where I'm reading textual model I need to open some ecore models... When I try to open a file I receive an error concerning metamodel uri not found... How I can register metamodel file with uri?
Re: Parser and models [message #650869 is a reply to message #650816] Wed, 26 January 2011 23:22 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Hello Chuck,
As said 1000 times before some more information in your posts would help.
-do you want to read .ecore files or some .mymetamodelsfileextension files.
-snippet of the code you use
-error message you get
. . .

Thanks, Christian


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Parser and models [message #650921 is a reply to message #650869] Thu, 27 January 2011 07:57 Go to previous messageGo to next message
chuck  is currently offline chuck Friend
Messages: 160
Registered: July 2010
Senior Member
yes you're right Smile

i'm reading .mydsl models but i also need to read .ecore model... I followed this tutorial http://antonywilkins.blogspot.com/2009/08/xtext-spring-demo- part-2.html and is the line I receive error:

Resource modelecore=loadModelResource(myModelPath);

i receive - Package with uri 'http://myMMuri' not found...

where myMMuri is the metamodel to which is conforming my ecore model... i need to register metamodel and after read ecore model....the xtext model .mydsl reading works fine...

Re: Parser and models [message #650924 is a reply to message #650921] Thu, 27 January 2011 08:17 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Hi,

what about doing the same that Xtext does for you in the Generated StandaloneSetup for your stuff:

If you have java classes for your ecore:

something like

EPackage.Registry.INSTANCE.put(MyPackage.eNSURI, MyPackage.eInstance)

if you use dynamic emf http://wiki.eclipse.org/EMF/FAQ

~Christian


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Parser and models [message #651725 is a reply to message #650924] Tue, 01 February 2011 12:51 Go to previous messageGo to next message
chuck  is currently offline chuck Friend
Messages: 160
Registered: July 2010
Senior Member
OK,,,my problem was the incorrect ecore model Smile
now i'm reading textual model and i have some crossreferences to external ecore model... i found that is an eproxy reference...but i don't how to access to right model element.
Re: Parser and models [message #651727 is a reply to message #651725] Tue, 01 February 2011 13:00 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Hi

i am just guessing

Quote:

now i'm reading textual model and i have some crossreferences to external ecore model... i found that is an eproxy reference...but i don't how to access to right model element.



So now you are Standalone and want to read the model file. Please not the the global scope standalone is by default all contoent of the resourceset so add all models (including the ones that contain the referenced stuff) to the resourceset.

~ Christian


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Parser and models [message #651731 is a reply to message #651727] Tue, 01 February 2011 13:11 Go to previous messageGo to next message
chuck  is currently offline chuck Friend
Messages: 160
Registered: July 2010
Senior Member
yes...I read the file ecore loading resource....

but when i do that:

EClassifier elementLF=r.getMLF().getElementLF();
//InternalEObject element = (InternalEObject)elementLF;
System.out.println(element.getName());

i receive null....



Re: Parser and models [message #651740 is a reply to message #651731] Tue, 01 February 2011 13:16 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Hi,

i am still not sure what you are doing and where you geht the error? withing xtext, within ecore? please SET MORE CONTEXT.

~Christian


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Parser and models [message #651757 is a reply to message #651740] Tue, 01 February 2011 13:45 Go to previous messageGo to next message
chuck  is currently offline chuck Friend
Messages: 160
Registered: July 2010
Senior Member
i'm reading textual xtext models...and during that operation i need to read ecore file in resourceset...

i loaded ecore model :
this.mod=(DynamicEObjectImpl)(TFile.getContents().get(0));

and after i try to read the first EClass of this model...
just that... printing that i saw that EclassImpl is eproxy.... and i don't know hot to access to real Eclass...

i hope that will be more clear... Neutral
Re: Parser and models [message #651785 is a reply to message #651757] Tue, 01 February 2011 15:40 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Hi,

Can you please set more context. e.g dummy grammar / dummy xtext model .....

Running sample code ...

~Christian


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Parser and models [message #651796 is a reply to message #651785] Tue, 01 February 2011 16:05 Go to previous messageGo to next message
chuck  is currently offline chuck Friend
Messages: 160
Registered: July 2010
Senior Member
ok I try to reduce my grammar...

Rule:"rule" name=ID

"{"
mLeft=MLeft "..."

"}"
;
MLeft:"order" elLeft=[ecore::EClass] name=ID



in parser i would like to manipulate textual model and some core models...

public class ReadLangModelTest {


static {

LangStandaloneSetup.doSetup();
}



public static void main(String[] args) throws MigrationException {

//here i read mydsl models and it works fine...and i have MLeft element and i need to obtain Eclass in crossreference...



EClassifier elementLeft=element.getELeft();
InternalEObject element = (InternalEObject)elementSX;

System.out.println(elementSX.getName());

//here i receive null and i would receive eclass name in crossreference




}

it's ok now?
Re: Parser and models [message #651801 is a reply to message #651796] Tue, 01 February 2011 16:24 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Maybe i got it: what about if you'd post your questions like

I have a grammar like this

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

import "http://www.eclipse.org/emf/2002/Ecore" as ecore

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

Model:
	elements+=Element*
;

Element:
	"element" name=ID "refs" ref=[ecore::EClass]
;


and an ecore like this
<?xml version="1.0" encoding="UTF-8"?>
<ecore:EPackage xmi:version="2.0"
    xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:ecore="http://www.eclipse.org/emf/2002/Ecore" name="test"
    nsURI="http://www.example.com/test" nsPrefix="test">
  <eClassifiers xsi:type="ecore:EClass" name="A"/>
  <eClassifiers xsi:type="ecore:EClass" name="B"/>
</ecore:EPackage>



and ref it from a model like this

element X refs A
element Y refs B


and i dead it programmatically

public class Main {

	public static void main(String[] args) {
		new EcoreSupport().preInvoke();
		MyDslStandaloneSetup.doSetup();
		ResourceSet rs = new ResourceSetImpl();
		Resource r1 = rs.getResource(URI.createURI("src/test.ecore"), true);
		Resource r2 = rs.getResource(URI.createURI("src/test.mydsl"), true);
		Model m = (Model) r2.getContents().get(0);
		for (Element e : m.getElements()) {
			System.out.println(e.getName() + " => " + e.getRef().getName());
		}
	}

}


and it works like a charm

~ Christian


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Parser and models [message #651802 is a reply to message #651801] Tue, 01 February 2011 16:30 Go to previous messageGo to next message
chuck  is currently offline chuck Friend
Messages: 160
Registered: July 2010
Senior Member
the problem is similar...

when I try to print eclass without cast... i get that;
org.eclipse.emf.ecore.impl.EClassImpl@6bef4b2b (eProxyURI: src/model/m1.mydsl#xtextLink_::0.3.5.0.2::0::/2)...

and when i try to print the eclass name it's null.... °_°

Re: Parser and models [message #651803 is a reply to message #651802] Tue, 01 February 2011 16:36 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Hi,

does your code contain this line new EcoreSupport().preInvoke();
or does it something similar?

~Christian


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Parser and models [message #651805 is a reply to message #651803] Tue, 01 February 2011 16:38 Go to previous messageGo to next message
chuck  is currently offline chuck Friend
Messages: 160
Registered: July 2010
Senior Member
yes I added that line! Neutral
Re: Parser and models [message #651806 is a reply to message #651805] Tue, 01 February 2011 16:38 Go to previous message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
I cannot help you unless you provide a complete runnable example to reproduce the problem.

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Previous Topic:XText 2.0 and Eclipse 3.6.1
Next Topic:when is "pushed to master" fixes available in nightly ?
Goto Forum:
  


Current Time: Thu Apr 25 14:19:07 GMT 2024

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

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

Back to the top