|
Re: Loading a resource [message #639371 is a reply to message #639116] |
Tue, 16 November 2010 09:53   |
Jan Koehnlein Messages: 760 Registered: July 2009 Location: Hamburg |
Senior Member |
|
|
Are you running your code from within Eclipse (not in a separate JVM)?
If so, you shouldn't call the DomainmodelStandaloneSetup. Otherwise, use
a debugger to make sure the line
Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap( ).put( "dmodel",
resourceFactory);
in DomainmdodelStandaloneSetupGenerated is called. This is where the
resource factory should be registered.
Am 15.11.10 12:16, schrieb Robin:
> Hi,
>
> I was trying to play around with the code given in the xtext Tutorial
> under Processing Xtext Models, Loading a Resource
> ( http://www.eclipse.org/Xtext/documentation/latest/xtext.html #processing_Xtext_models),
> but I cannot get it to work.
>
>
> // DomainmodelStandaloneSetup.doSetup();
> new DomainmodelStandaloneSetup().createInjectorAndDoEMFRegistrat ion();
>
> ResourceSet rs = new ResourceSetImpl();
> File file = new
> File("C:/runtime-EclipseApplication/gettingstarted/my2.dmodel ");
> Resource resource =
> rs.getResource(URI.createURI(file.toURI().toString()), true);
> // Resource resource = rs.getResource(URI.createURI("./my2.dmodel"), true);
> EObject eobject = resource.getContents().get(0);
>
> DomainModel domainModel = (DomainModel) eobject;
> EList<AbstractElement> elements = domainModel.getElements();
> for (AbstractElement abstractElement : elements) {
> if (abstractElement instanceof Entity) {
> Entity entity = ((Entity)abstractElement);
> System.out.println("entity "
> + entity.getName()
> + " extends "
> + entity.getSuperType().getName());
> }
> }
>
>
> I get this error:
>
> Exception in thread "main" java.lang.RuntimeException: Cannot create a
> resource for
> 'file:/C:/runtime-EclipseApplication/gettingstarted/my2.dmod el'; a
> registered resource factory is needed
> at
> org.eclipse.emf.ecore.resource.impl.ResourceSetImpl.getResou rce(ResourceSetImpl.java:394)
>
> at org.eclipse.xtext.example.Test.main(Test.java:26)
>
>
> from the line:
>
> Resource resource =
> rs.getResource(URI.createURI(file.toURI().toString()), true);
>
>
> I created the Java file in the org.eclipse.xtext.example.domainmodel
> project, in the package org.eclipse.xtext.example.
>
> What am I missing?? :?
> Regard, Robin
--
Need professional support for Eclipse Modeling?
Go visit: http://xtext.itemis.com
---
Get professional support from the Xtext committers at www.typefox.io
|
|
|
|
|
|
|
|
Re: Loading a resource [message #646770 is a reply to message #646769] |
Thu, 30 December 2010 22:15   |
|
hello robin,
can you post your complete code loading the model. seems you are not callling standalonesetup.
this code works nicely for me
import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.ecore.resource.ResourceSet;
import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
import org.eclipse.xtext.example.DomainmodelStandaloneSetup;
import org.eclipse.xtext.example.domainmodel.DomainModel;
public class Test {
public static void main(String[] args) {
new DomainmodelStandaloneSetup().createInjectorAndDoEMFRegistration();
ResourceSet rs = new ResourceSetImpl();
Resource resource = rs.getResource(URI.createURI("./src/test.dmodel"), true);
DomainModel model = (DomainModel) resource.getContents().get(0);
System.out.println(model.getElements().size());
}
}
~Christian
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
|
|
|
|
|
|
Re: Loading a resource [message #654957 is a reply to message #654820] |
Thu, 17 February 2011 18:18   |
|
Hi,
the problem is simple but hard to find you file extension is "dmodel " (ending with a blank) but your files have od course the extension "dmodel". so changing your workflow to
var grammarURI = "classpath:/org/eclipse/xtext/example/Domainmodel.xtext"
var file.extensions = "dmodel"
var projectName = "org.eclipse.xtext.example.domainmodel"
var runtimeProject = "../${projectName}"
might solve the problems Note: you may have to merge plugin.xml and plugin.xml_gen
Feel free to file an enhancement request for a validation rule that complains on whitespace in the file extension.
~Christian
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
[Updated on: Thu, 17 February 2011 18:19] Report message to a moderator
|
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.03178 seconds