Skip to main content



      Home
Home » Modeling » TMF (Xtext) » Use Xtext infrastructure in standalone application
Use Xtext infrastructure in standalone application [message #831242] Wed, 28 March 2012 12:59 Go to next message
Eclipse UserFriend
Hi,

I defined a Ecore metamodel and created an Xtext grammar, that is importing it. Now I tried to create a standalone application that is able to load a file. When generating the metamodel from the grammar, it works just fine, but when importing a metamodel, there are issues with registering the generated model code.

I followed the suggestions in the Xtext FAQ ("How do I load my model in a standalone Java application?") and also tried to load the package and register the factory. However, after registering the factory, I get the following error:

Exception in thread "main" java.lang.ClassCastException:
  Test.impl.TestFactoryImpl cannot be cast to
  org.eclipse.emf.ecore.resource.Resource$Factory


The same problem seems to have been already discussed in the thread 657914
(sorry, the forum doesn't allow me to post links yet...)

Still, there's no solution. Trying the Impl versions of the classes results in the same issue. Right now the code for loading looks like this:
Injector injector = new TestDSLStandaloneSetup()
  .createInjectorAndDoEMFRegistration();
XtextResourceSet resourceSet = injector.getInstance(XtextResourceSet.class);
resourceSet.addLoadOption(XtextResource.OPTION_RESOLVE_ALL, Boolean.TRUE);

TestPackage.eINSTANCE.eClass();

Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap()
  .put("test", TestFactory.eINSTANCE);

Resource resource =
  resourceSet.getResource(URI.createURI("samples/test.test"), true);
System.out.println(resource.getContents().get(0));


I attached a minimum workspace including the 3 projects (metamodel, Xtext grammar and standalone application), to illustrate the issue. It doesn't inlcude the dependencies, due to the size limit (com.google.inject_3.0.0.no_aop.jar, org.eclipse.emf.ecore_2.7.0.v20120127-1122.jar, org.eclipse.emf.common_2.7.0.v20120127-1122.jar, org.eclipse.xtext_2.3.0.v201203201034.jar, org.eclipse.emf.ecore.xmi_2.7.0.v20120127-1122.jar)

Thanks
Re: Use Xtext infrastructure in standalone application [message #831248 is a reply to message #831242] Wed, 28 March 2012 13:07 Go to previous message
Eclipse UserFriend
Hi,

just make sure
- that you do NOT call Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().put("test", TestFactory.eINSTANCE);
- but call sth like EPackage.Registry.INSTANCE.put(MyDslPackage.eNS_URI, MyDslPackage.eINSTANCE); before calling the standalonesetup

~Christian
Previous Topic:Using xtext without eclipse
Next Topic:How to: xText-model->ecore model (?) -> generated text
Goto Forum:
  


Current Time: Wed Jul 23 23:36:28 EDT 2025

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

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

Back to the top