Skip to main content



      Home
Home » Modeling » TMF (Xtext) » Read Xtext resource as EMF resource
Read Xtext resource as EMF resource [message #1065097] Mon, 24 June 2013 07:16 Go to next message
Eclipse UserFriend
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 07:28] by Moderator

Re: Read Xtext resource as EMF resource [message #1065103 is a reply to message #1065097] Mon, 24 June 2013 07:38 Go to previous messageGo to next message
Eclipse UserFriend
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
Re: Read Xtext resource as EMF resource [message #1065158 is a reply to message #1065103] Mon, 24 June 2013 10:14 Go to previous messageGo to next message
Eclipse UserFriend
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 10:33 Go to previous messageGo to next message
Eclipse UserFriend
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
Re: Read Xtext resource as EMF resource [message #1065180 is a reply to message #1065163] Mon, 24 June 2013 11:51 Go to previous messageGo to next message
Eclipse UserFriend
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 14:26] by Moderator

Re: Read Xtext resource as EMF resource [message #1065194 is a reply to message #1065180] Mon, 24 June 2013 13:39 Go to previous messageGo to next message
Eclipse UserFriend
Hmmm,

there must be something missing.
can you share a complete reproduceable example?
Re: Read Xtext resource as EMF resource [message #1065196 is a reply to message #1065194] Mon, 24 June 2013 14:07 Go to previous messageGo to next message
Eclipse UserFriend
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 14:28] by Moderator

Re: Read Xtext resource as EMF resource [message #1065201 is a reply to message #1065196] Mon, 24 June 2013 14:30 Go to previous messageGo to next message
Eclipse UserFriend
Hi,

are both resources in the same resourceset?
Re: Read Xtext resource as EMF resource [message #1065202 is a reply to message #1065201] Mon, 24 June 2013 14:40 Go to previous messageGo to next message
Eclipse UserFriend
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 14:41] by Moderator

Re: Read Xtext resource as EMF resource [message #1065203 is a reply to message #1065202] Mon, 24 June 2013 14:44 Go to previous messageGo to next message
Eclipse UserFriend
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.
Re: Read Xtext resource as EMF resource [message #1065204 is a reply to message #1065203] Mon, 24 June 2013 14:52 Go to previous messageGo to next message
Eclipse UserFriend
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 14:59 Go to previous messageGo to next message
Eclipse UserFriend
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?
Re: Read Xtext resource as EMF resource [message #1065206 is a reply to message #1065205] Mon, 24 June 2013 15:07 Go to previous messageGo to next message
Eclipse UserFriend
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 15:13 Go to previous messageGo to next message
Eclipse UserFriend
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/
Re: Read Xtext resource as EMF resource [message #1065208 is a reply to message #1065207] Mon, 24 June 2013 15:35 Go to previous messageGo to next message
Eclipse UserFriend
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 16:09] by Moderator

Re: Read Xtext resource as EMF resource [message #1065215 is a reply to message #1065208] Mon, 24 June 2013 15:58 Go to previous messageGo to next message
Eclipse UserFriend
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)
Re: Read Xtext resource as EMF resource [message #1065231 is a reply to message #1065215] Mon, 24 June 2013 18:49 Go to previous messageGo to next message
Eclipse UserFriend
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 19:01] by Moderator

Re: Read Xtext resource as EMF resource [message #1065246 is a reply to message #1065231] Tue, 25 June 2013 02:14 Go to previous messageGo to next message
Eclipse UserFriend
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
Re: Read Xtext resource as EMF resource [message #1065247 is a reply to message #1065246] Tue, 25 June 2013 02:14 Go to previous message
Eclipse UserFriend
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
Previous Topic:XtextEditor manipulation
Next Topic:Grammar equivalent for Java interface
Goto Forum:
  


Current Time: Sun Jul 06 21:28:30 EDT 2025

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

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

Back to the top