Reading Xtext model file in Java Apps [message #62206] |
Wed, 22 July 2009 04:08  |
Eclipse User |
|
|
|
Originally posted by: ilyas.keser.gmail.com
Hi @all,
how can I access a Xtext model file in a java application? I am trying
to read it with:
@SuppressWarnings("unused")
ConfDSLPackage confDSLPackage = onfDSLPackage.eINSTANCE;
ResourceSet resourceSet = new ResourceSetImpl();
resourceSet.getResourceFactoryRegistry().getExtensionToFacto ryMap().put( ".conf",
new ConfDSLFactoryImpl());
URI uri =
URI.createURI(" platform:/resource/myproject/src/de/test/mydsl/Configuration .conf ");
Resource resource = resourceSet.createResource(uri);
try {
resource.load(null);
Configuration conf = (Configuration)resource.getContents().get(0);
} catch (Exception e) {
System.out.println("Failed to read " + uri);
}
resource.load(null) throws an exception. Any ideas?
Thanks
Ilyas
|
|
|
|
|
|
Re: Reading Xtext model file in Java Apps [message #62379 is a reply to message #62306] |
Wed, 22 July 2009 05:29   |
Eclipse User |
|
|
|
Hi Ilyas,
the ConfDSLFactoryImpl is not a ResourceFactory but an EFactory. It is
not intendent to put an EFactory into the FactoryToExtensionMap.
Please try Knut's suggestion. It should work fine.
Hope that helps,
Sebastian
--
Need professional support for Eclipse Modeling?
Go visit: http://xtext.itemis.com
Am 22.07.2009 10:50 Uhr, schrieb Ilyas Keser:
> Hi Sebastian,
>
> the thrown exception is a NPE and resourceSet.createResource(uri)
> returns null.
>
> ConfDSLFactoryImpl is generated by Xtext and is in the package
> .../src-gen/de/test/mydsl/confDSL.impl.
>
> I am using a Xtext grammar to define a configuration file. After
> generating the Xtext artefacts, I created a model file with generated
> DSL editor. Just, I am trying to read/access this model file in a Java
> Application.
>
> Regards,
> ILyas
>
>
>
> Sebastian Zarnekow schrieb:
>> Hi Ilyas,
>>
>> maybe you want to be more specific about the exception that you catch.
>> Otherwise it is hardly possible to answer your question.
>>
>> Where does the class ConfDSLFactoryImpl come from? Do you mix up an
>> Editor that was generated by EMF and an Xtext-based DSL file?
>>
>> Regards,
>> Sebastian
|
|
|
|
Re: Reading Xtext model file in Java Apps [message #62427 is a reply to message #62403] |
Wed, 22 July 2009 07:34  |
Eclipse User |
|
|
|
Hi Ilyas,
please feel free to update the wiki.
Thanks,
Sebastian
--
Need professional support for Eclipse Modeling?
Go visit: http://xtext.itemis.com
Am 22.07.2009 12:03 Uhr, schrieb Ilyas Keser:
> Sebastian & Knut, thanks for your replies. It works for me.
>
> The method createInjectorAndDoEMFRegistration() isn't static anymore. Is
> it OK, if I modify the first line of the snippet (in wiki) as follows:
>
> Injector injector = new
> ConfDSLStandaloneSetup().createInjectorAndDoEMFRegistration( );
>
> Regards,
> ILyas
>
>
> Sebastian Zarnekow schrieb:
>> Hi Ilyas,
>>
>> the ConfDSLFactoryImpl is not a ResourceFactory but an EFactory. It is
>> not intendent to put an EFactory into the FactoryToExtensionMap.
>> Please try Knut's suggestion. It should work fine.
>>
>> Hope that helps,
>> Sebastian
|
|
|
Powered by
FUDForum. Page generated in 0.06496 seconds