Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Read Xtext resource as EMF resource
Read Xtext resource as EMF resource [message #1065097] Mon, 24 June 2013 11:16 Go to next message
serhat gezgin is currently offline serhat gezginFriend
Messages: 243
Registered: January 2013
Location: Izmir
Senior Member
Hi all

I need to read Xtext resource and than manupulate it from another application. So how can i read Xtext resource as EMF resource

Regards

[Updated on: Mon, 24 June 2013 11:28]

Report message to a moderator

Re: Read Xtext resource as EMF resource [message #1065103 is a reply to message #1065097] Mon, 24 June 2013 11:38 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Hi,

i am not sure in which context you want to do this (standalone/from eclipse)
you may have a look at http://wiki.eclipse.org/Xtext/FAQ#How_do_I_load_my_model_in_a_standalone_Java_application.C2.A0.3F


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Read Xtext resource as EMF resource [message #1065158 is a reply to message #1065103] Mon, 24 June 2013 14:14 Go to previous messageGo to next message
serhat gezgin is currently offline serhat gezginFriend
Messages: 243
Registered: January 2013
Location: Izmir
Senior Member
Thanks

now i am adding new elements to resource but now i need to save resource and i try;

HashMap saveOptions = new HashMap();
		    saveOptions.put(XtextResource.OPTION_FORMAT, Boolean.TRUE);
		    try {
				resource.save(new FileOutputStream("deneme.user"), saveOptions);
			} catch (FileNotFoundException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}


This but i cant save resource. Can u help me

Regards
Re: Read Xtext resource as EMF resource [message #1065163 is a reply to message #1065158] Mon, 24 June 2013 14:33 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33140
Registered: July 2009
Senior Member
Is there a stack trace to share?

On 24/06/2013 4:14 PM, serhat gezgin wrote:
> Thanks
>
> now i am adding new elements to resource but now i need to save
> resource and i try;
>
>
> HashMap saveOptions = new HashMap();
> saveOptions.put(XtextResource.OPTION_FORMAT, Boolean.TRUE);
> try {
> resource.save(new FileOutputStream("deneme.user"),
> saveOptions);
> } catch (FileNotFoundException e) {
> // TODO Auto-generated catch block
> e.printStackTrace();
> } catch (IOException e) {
> // TODO Auto-generated catch block
> e.printStackTrace();
> }
>
>
> This but i cant save resource. Can u help me
>
> Regards


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Read Xtext resource as EMF resource [message #1065180 is a reply to message #1065163] Mon, 24 June 2013 15:51 Go to previous messageGo to next message
serhat gezgin is currently offline serhat gezginFriend
Messages: 243
Registered: January 2013
Location: Izmir
Senior Member
i dont get an error but my changes nor occur on deneme.user file why dont undestand?

my whole code is ; (just creating SitePermission but this element dont shown in deneme.user file)


ResourceSet rs = new ResourceSetImpl();
		SitePermission sitePermission= null;

Resource resource = rs.getResource(
					URI.createURI(userFile.toURI().toString()), true);

UserModel eobject = (UserModel) resource.getContents().get(0);

UserPackage.eINSTANCE.eClass();
		// Retrieve the default factory singleton
		UserFactory factory = UserFactory.eINSTANCE;
		// SitePermission
		SitePermission sitePermission = factory.createSitePermission();
		sitePermission.setName(name);
                //Other changes
userModel.getSitePermissions().add(sitePermission);

HashMap saveOptions = new HashMap();
		    saveOptions.put(XtextResource.OPTION_FORMAT, Boolean.TRUE);
		    try {
				resource.save(new FileOutputStream("deneme.user"), saveOptions);
			} catch (FileNotFoundException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} catch (Exception e) {
				// TODO: handle exception
				e.printStackTrace();
			}

[Updated on: Mon, 24 June 2013 18:26]

Report message to a moderator

Re: Read Xtext resource as EMF resource [message #1065194 is a reply to message #1065180] Mon, 24 June 2013 17:39 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Hmmm,

there must be something missing.
can you share a complete reproduceable example?


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Read Xtext resource as EMF resource [message #1065196 is a reply to message #1065194] Mon, 24 June 2013 18:07 Go to previous messageGo to next message
serhat gezgin is currently offline serhat gezginFriend
Messages: 243
Registered: January 2013
Location: Izmir
Senior Member
Hi,

i use 2 project one is User xtext Project, second is my content GMF project on GMF project when web created (on CreateWebCommand) above code triggered and on User file SitePermission element added. and Web element reference to it. (i have 2 file one is content another is user)

when i do this
i have got this error

Save Failed
No EObjectDescription could be found in Scope Web.sitePermission for UserModel.sitePermissions[0]->SitePermission'Serhat'
Semantic Object: ContentModel'CM'.ownedWeb->Web'fsdg'


Do you have any idea why the reference and element cannot be found on file please ?

[Updated on: Mon, 24 June 2013 18:28]

Report message to a moderator

Re: Read Xtext resource as EMF resource [message #1065201 is a reply to message #1065196] Mon, 24 June 2013 18:30 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Hi,

are both resources in the same resourceset?


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Read Xtext resource as EMF resource [message #1065202 is a reply to message #1065201] Mon, 24 June 2013 18:40 Go to previous messageGo to next message
serhat gezgin is currently offline serhat gezginFriend
Messages: 243
Registered: January 2013
Location: Izmir
Senior Member
i dont know much both 2 project are different. And each project have different metamodel and xtext gramer but content grammer imports user grammer because on web element its have referance to users sitePermission element

(content project synchronized with its GMF project)

[Updated on: Mon, 24 June 2013 18:41]

Report message to a moderator

Re: Read Xtext resource as EMF resource [message #1065203 is a reply to message #1065202] Mon, 24 June 2013 18:44 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Hi,

are you in eclipse? or standalone?
which of the dsl is xtext and which not.
standalone both have to be in the same resourceset.


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Read Xtext resource as EMF resource [message #1065204 is a reply to message #1065203] Mon, 24 June 2013 18:52 Go to previous messageGo to next message
serhat gezgin is currently offline serhat gezginFriend
Messages: 243
Registered: January 2013
Location: Izmir
Senior Member
i am on runtime-eclipse 2 project is firstly created as xtext and than on content

project its GMF project created and synchronized with content xtext (GMF uses xtext as

model). And the resourcesets are different
Re: Read Xtext resource as EMF resource [message #1065205 is a reply to message #1065204] Mon, 24 June 2013 18:59 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
HI,

i mean: how do you execute the code? java main?
are the metamodels different. if so do you provider a resourceserviceprovider for the gmf stuff?


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Read Xtext resource as EMF resource [message #1065206 is a reply to message #1065205] Mon, 24 June 2013 19:07 Go to previous messageGo to next message
serhat gezgin is currently offline serhat gezginFriend
Messages: 243
Registered: January 2013
Location: Izmir
Senior Member
I execute Code from GMF's Web create Command. (not on main method)

But i dont provide resourceserviceprovider how can i done this dont know
Re: Read Xtext resource as EMF resource [message #1065207 is a reply to message #1065206] Mon, 24 June 2013 19:13 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Sorry i dont know about gmf.
here is an example on how to reference non xtext emf models from xtext models
http://christiandietrich.wordpress.com/2011/07/17/xtext-2-0-and-uml/


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Read Xtext resource as EMF resource [message #1065208 is a reply to message #1065207] Mon, 24 June 2013 19:35 Go to previous messageGo to next message
serhat gezgin is currently offline serhat gezginFriend
Messages: 243
Registered: January 2013
Location: Izmir
Senior Member
Hi

I have user project and its grammer is;


UserModel returns UserModel:
	('sitePermissions' '{' sitePermissions+=SitePermission (sitePermissions+=SitePermission)* '}' )?
;

SitePermission returns SitePermission:
	'sitePermission' name = QualifiedName '{'
		'webGUID' '=' webGUID=STRING
	'}'
;



and I have content project and its grammer is;

ContentModel returns ContentModel:
	'ContentModel'
	name=QualifiedName
	'{'
		'webApplicaitonName' '=' webApplicataionName = STRING
		'siteCollectionName' '=' siteCollectionName = STRING
		('description' '=' description=STRING)?
		ownedWeb=Web
	'}';

Web returns Web:
	'Web'
	name=QualifiedName
	'{'
                 'sitePermission' '=' sitePermission = [user::SitePermission|QualifiedName]
		('Webs' '{' ownedWeb+=Web (ownedWeb+=Web)* '}' )?
	'}';


I can create 2 project well and they work greate. (i follow http://christiandietrich.wordpress.com/2012/08/07/xtext-referencing-elements-of-one-dsl-from-another-dsl/)

But i just want to on contents Diagram project (XText and GMF project shares Contents EMF classes (ex ContentPackage, ContentFactory ..)) when Web created i must add a SitePermission element to created.user file

and i must do this on content xtext project too when web created i must add SitePermission to created.user file too

can i explain more ?

Regards

[Updated on: Mon, 24 June 2013 20:09]

Report message to a moderator

Re: Read Xtext resource as EMF resource [message #1065215 is a reply to message #1065208] Mon, 24 June 2013 19:58 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
HI,

if you have dsl for both you want to reference from one dsla file to another dslb file?
then simply make sure that both are in the same container
(resourceset standalone, iproject in eclipse)


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Read Xtext resource as EMF resource [message #1065231 is a reply to message #1065215] Mon, 24 June 2013 22:49 Go to previous messageGo to next message
serhat gezgin is currently offline serhat gezginFriend
Messages: 243
Registered: January 2013
Location: Izmir
Senior Member
yes they are on same container but when dsla creates web element dslb must create SitePermission element and web element must referance this SitePermission on its attribute

automaticly

[Updated on: Mon, 24 June 2013 23:01]

Report message to a moderator

Re: Read Xtext resource as EMF resource [message #1065246 is a reply to message #1065231] Tue, 25 June 2013 06:14 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
As I said if you use the same resourceset....

--
Need training, onsite consulting or any other kind of help for Xtext?
Go visit http://xtext.itemis.com or send a mail to xtext at itemis dot de


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Read Xtext resource as EMF resource [message #1065247 is a reply to message #1065246] Tue, 25 June 2013 06:14 Go to previous message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
P.s. but I still don't know enough context to give more advice

--
Need training, onsite consulting or any other kind of help for Xtext?
Go visit http://xtext.itemis.com or send a mail to xtext at itemis dot de


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Previous Topic:XtextEditor manipulation
Next Topic:Grammar equivalent for Java interface
Goto Forum:
  


Current Time: Wed Apr 24 23:51:46 GMT 2024

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

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

Back to the top