|
Re: Loading a resource [message #639371 is a reply to message #639116] |
Tue, 16 November 2010 04:53   |
Eclipse User |
|
|
|
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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Re: Loading a resource [message #901071 is a reply to message #901064] |
Thu, 09 August 2012 11:33  |
Eclipse User |
|
|
|
Having a trailing blank got a big mess with internal registries -
giving a blank as file extension does not work in most OS but in java
storing it as a key in a hash map does work well
--
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
|
|
|
Powered by
FUDForum. Page generated in 0.04607 seconds