Skip to main content



      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 07:14 Go to next message
Eclipse UserFriend
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

[Updated on: Sat, 01 February 2014 07:16] by Moderator

Re: Creating new Xtext resource through code [message #1238482 is a reply to message #1238459] Sat, 01 February 2014 08:54 Go to previous messageGo to next message
Eclipse UserFriend
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
Re: Creating new Xtext resource through code [message #1238487 is a reply to message #1238482] Sat, 01 February 2014 09:06 Go to previous messageGo to next message
Eclipse UserFriend
and from which context do you execute this code?
icon5.gif  Re: Creating new Xtext resource through code [message #1238495 is a reply to message #1238487] Sat, 01 February 2014 09:40 Go to previous messageGo to next message
Eclipse UserFriend
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
Re: Creating new Xtext resource through code [message #1238499 is a reply to message #1238495] Sat, 01 February 2014 09:50 Go to previous messageGo to next message
Eclipse UserFriend
so once more how das the path look like?
icon5.gif  Re: Creating new Xtext resource through code [message #1238503 is a reply to message #1238499] Sat, 01 February 2014 10:02 Go to previous messageGo to next message
Eclipse UserFriend
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
Re: Creating new Xtext resource through code [message #1238506 is a reply to message #1238503] Sat, 01 February 2014 10:06 Go to previous messageGo to next message
Eclipse UserFriend
dud you try to call createFileURI instead
Re: Creating new Xtext resource through code [message #1238507 is a reply to message #1238506] Sat, 01 February 2014 10:08 Go to previous messageGo to next message
Eclipse UserFriend
Hi Christian,
No, I did not try that one!
Do you think that's causing me the problem?


Regards,
Arshad
Re: Creating new Xtext resource through code [message #1238512 is a reply to message #1238507] Sat, 01 February 2014 10:22 Go to previous message
Eclipse UserFriend
yes
Previous Topic:Problems xText - RCP integration
Next Topic:on OnChangeEvictingCache and JvmModelInferrer
Goto Forum:
  


Current Time: Wed Jul 23 16:00:48 EDT 2025

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

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

Back to the top