Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Creating new Xtext resource through code(Creating new Xtext resource through code)
icon5.gif  Creating new Xtext resource through code [message #1238459] Sat, 01 February 2014 12:14 Go to next message
Arshad Adavani is currently offline Arshad AdavaniFriend
Messages: 163
Registered: July 2013
Location: Bangalore
Senior Member
Hi all,
I am actually trying to create a new xtext resource through code.
For e.g I have created a project in my xtext tool (as dsl needs to be contained in a project) and under this project I am trying to create a xtext resource, add content and save it. What I have done actually is:

private Resource createandSaveResource(String path, MyModel Obj){
ResourseSet rs=new ResourseSetImpl();
Resource resource= rs.createResource(URI.createURI(path), true);
resource.getContents().add(obj);
[b]resource.save(Collections.EMPTY_MAP);[/b]
return resource;
}



Is it enough code to create the resource and add, save content to it.
rs.save(Collections.EMPTY_MAP) throws me a MalformedException: Unknown protocol d

How do I resolve it?
Can someone suggest me?

Thanks in advance Smile


Arshad

[Updated on: Sat, 01 February 2014 12:16]

Report message to a moderator

Re: Creating new Xtext resource through code [message #1238482 is a reply to message #1238459] Sat, 01 February 2014 13:54 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
How does path look like?

--
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: Creating new Xtext resource through code [message #1238487 is a reply to message #1238482] Sat, 01 February 2014 14:06 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
and from which context do you execute this code?

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
icon5.gif  Re: Creating new Xtext resource through code [message #1238495 is a reply to message #1238487] Sat, 01 February 2014 14:40 Go to previous messageGo to next message
Arshad Adavani is currently offline Arshad AdavaniFriend
Messages: 163
Registered: July 2013
Location: Bangalore
Senior Member
Hi Christian,
In my case I have already a xtext editor in the project. On right click in the editor I have provided an option, which imports some data from the file. So I am making use of this xtext resource to get the path so the I can create new xtext resources.

My requirement is that: I have a xtext editor already. On right click , I select an option to import data. Now some data should be filled in this editor and rest data should go in newly created resources. So here its needed for me to create the resources.


Thanks in advance for your help Smile


Arshad
Re: Creating new Xtext resource through code [message #1238499 is a reply to message #1238495] Sat, 01 February 2014 14:50 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
so once more how das the path look like?

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
icon5.gif  Re: Creating new Xtext resource through code [message #1238503 is a reply to message #1238499] Sat, 01 February 2014 15:02 Go to previous messageGo to next message
Arshad Adavani is currently offline Arshad AdavaniFriend
Messages: 163
Registered: July 2013
Location: Bangalore
Senior Member
Hi Christian,
The path is something like:
"D:/Arshad/Mymodel.dmodel". This is the path that I am getting through my code and not the hardcoded one.

If I create a file with the same path then I am able to create it. But getting problem with resource as explained above.


Thanks and regards,
Arshad


Arshad
Re: Creating new Xtext resource through code [message #1238506 is a reply to message #1238503] Sat, 01 February 2014 15:06 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
dud you try to call createFileURI instead

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Creating new Xtext resource through code [message #1238507 is a reply to message #1238506] Sat, 01 February 2014 15:08 Go to previous messageGo to next message
Arshad Adavani is currently offline Arshad AdavaniFriend
Messages: 163
Registered: July 2013
Location: Bangalore
Senior Member
Hi Christian,
No, I did not try that one!
Do you think that's causing me the problem?


Regards,
Arshad


Arshad
Re: Creating new Xtext resource through code [message #1238512 is a reply to message #1238507] Sat, 01 February 2014 15:22 Go to previous message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
yes

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Previous Topic:Problems xText - RCP integration
Next Topic:on OnChangeEvictingCache and JvmModelInferrer
Goto Forum:
  


Current Time: Fri Mar 29 09:35:18 GMT 2024

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

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

Back to the top