Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Register Xtext Resource Factory in Xtend
Register Xtext Resource Factory in Xtend [message #1851084] Sun, 27 March 2022 15:16 Go to next message
John Henbergs is currently offline John HenbergsFriend
Messages: 214
Registered: October 2020
Senior Member
Hi,

I am trying to use n Xtext file (the instance of my dsl), as input to Xtend to generate code. I am getting the following error:

Exception in thread "main" org.eclipse.emf.ecore.resource.impl.ResourceSetImpl$1DiagnosticWrappedException: org.xml.sax.SAXParseExceptionpublicId: file:/Users/User/runtime-Transf/tranform/A2B.mydsl; systemId: file:/Users/User/runtime-Transf/tranform/A2B.mydsl; lineNumber: 1; columnNumber: 1; Content is not allowed in prolog.
	at org.eclipse.emf.ecore.resource.impl.ResourceSetImpl.handleDemandLoadException(ResourceSetImpl.java:319)
	at org.eclipse.emf.ecore.resource.impl.ResourceSetImpl.demandLoadHelper(ResourceSetImpl.java:278)
	at org.eclipse.emf.ecore.resource.impl.ResourceSetImpl.getResource(ResourceSetImpl.java:406)
	at xtendpaxckage.transform.Setup(transform.java:195)
	....


From what I read, this usually occurs when there are issues with registering Resource Factories.
I know how to do that for Ecore or Xmi resource factories , but not for Xtext.

In this thread https://bugs.eclipse.org/bugs/show_bug.cgi?id=531399 I see it says I have to register by using doSetup and so I did.
In Xtend I have this now:

def Setup(){
resourceSet = new ResourceSetImpl();
resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put(Resource.Factory.Registry.DEFAULT_EXTENSION, new XMIResourceFactoryImpl());
resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put(Resource.Factory.Registry.DEFAULT_EXTENSION, new EcoreResourceFactoryImpl());
MyDslStandaloneSetup.doSetup
resource = resourceSet.getResource( URI.createFileURI(new File("A2B.mydsl").getAbsolutePath()), true); 
}


However, when I do this I get the following error:

Exception in thread "main" java.lang.NoClassDefFoundError: org/eclipse/xtext/ISetup
	at java.base/java.lang.ClassLoader.defineClass1(Native Method)
	at java.base/java.lang.ClassLoader.defineClass(ClassLoader.java:1017)
	at java.base/java.security.SecureClassLoader.defineClass(SecureClassLoader.java:174)
	at java.base/jdk.internal.loader.BuiltinClassLoader.defineClass(BuiltinClassLoader.java:800)
	at java.base/jdk.internal.loader.BuiltinClassLoader.findClassOnClassPathOrNull(BuiltinClassLoader.java:698)
	at java.base/jdk.internal.loader.BuiltinClassLoader.loadClassOrNull(BuiltinClassLoader.java:621)
	at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:579)
	at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
	at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:522)
	at java.base/java.lang.ClassLoader.defineClass1(Native Method)
	at java.base/java.lang.ClassLoader.defineClass(ClassLoader.java:1017)
	at java.base/java.security.SecureClassLoader.defineClass(SecureClassLoader.java:174)
	at java.base/jdk.internal.loader.BuiltinClassLoader.defineClass(BuiltinClassLoader.java:800)
	at java.base/jdk.internal.loader.BuiltinClassLoader.findClassOnClassPathOrNull(BuiltinClassLoader.java:698)
	at java.base/jdk.internal.loader.BuiltinClassLoader.loadClassOrNull(BuiltinClassLoader.java:621)
	at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:579)
	at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
	at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:522)


Am I doing something wrong in this last step, or is this not the correct way at all to register the resource correctly?

Thank you!
Re: Register Xtext Resource Factory in Xtend [message #1851086 is a reply to message #1851084] Sun, 27 March 2022 15:27 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14353
Registered: July 2009
Senior Member
This looks like an incomplete classpath
Usually you can also call new mydslstandalonesetup().cresteinjectoranddoemfregistration()
And then call getInstance(Resourceset.class) to get the resourceset to load


Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/it-services/methods-and-tools/xtext
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Register Xtext Resource Factory in Xtend [message #1851087 is a reply to message #1851086] Sun, 27 March 2022 16:42 Go to previous messageGo to next message
John Henbergs is currently offline John HenbergsFriend
Messages: 214
Registered: October 2020
Senior Member
Hi Christian,

Do you mean something like this?

resourceSet = new ResourceSetImpl();
resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put(Resource.Factory.Registry.DEFAULT_EXTENSION, new XMIResourceFactoryImpl());
resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put(Resource.Factory.Registry.DEFAULT_EXTENSION, new EcoreResourceFactoryImpl());
injector = new MyDslStandaloneSetup().createInjectorAndDoEMFRegistration;
injector.getInstance(resourceSet.class)
resourceSet.getPackageRegistry().put(MyDslPackage.eNS_URI, MyDslPackage.eINSTANCE);
resource = resourceSet.getResource( URI.createFileURI(new File("A2B.mydsl").getAbsolutePath()), true); 


Even when I run this one, I still get:

Exception in thread "main" org.eclipse.emf.ecore.resource.impl.ResourceSetImpl$1DiagnosticWrappedException: org.xml.sax.SAXParseExceptionpublicId: file:/Users/User/runtime-Transf/tranform/A2B.mydsl; systemId: file:/Users/User/runtime-Transf/tranform/A2B.mydsl; lineNumber: 1; columnNumber: 1; Content is not allowed in prolog.
	at org.eclipse.emf.ecore.resource.impl.ResourceSetImpl.handleDemandLoadException(ResourceSetImpl.java:319)
	at org.eclipse.emf.ecore.resource.impl.ResourceSetImpl.demandLoadHelper(ResourceSetImpl.java:278)
	at org.eclipse.emf.ecore.resource.impl.ResourceSetImpl.getResource(ResourceSetImpl.java:406)
	at xtendpaxckage.transform.Setup(transform.java:195)
Re: Register Xtext Resource Factory in Xtend [message #1851089 is a reply to message #1851087] Sun, 27 March 2022 17:53 Go to previous message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14353
Registered: July 2009
Senior Member
No Xtend code would be


val injector = new MyDslStandaloneSetup().createInjectorAndDoEMFRegistration;
val resourceSet = injector.getInstance(ResourceSet)

No messing with registry


Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/it-services/methods-and-tools/xtext
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de

[Updated on: Sun, 27 March 2022 17:54]

Report message to a moderator

Previous Topic:General Xtext question
Next Topic:Use Xtext Editor for a model field
Goto Forum:
  


Current Time: Mon Oct 03 01:34:59 GMT 2022

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

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

Back to the top