Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Cross-references to external EMF models
Cross-references to external EMF models [message #542733] Fri, 25 June 2010 18:25 Go to next message
Andreas  is currently offline Andreas Friend
Messages: 1
Registered: June 2010
Junior Member
I would like to define cross-references to elements in external EMF model files. The external EMF models there are defined by external ecore metamodels (here using 'mydsl.ecore' as example).

In Xtext 0.7.2 this worked fine but I don't get it run with Xtext 1.0. In Xtext 1.0 I'm using the ImportURIScopingFragment and the SimpleNamesFragment (as proposed in previous postings like message #521601) but it still does not work.

In the xtext file:

import "platform:/resource/mydsl/model/mydsl.ecore" as myDSL

[...]

Import :
  'import' importURI=STRING ';'
;


Ref: 
  'ref' referencedObject=[myDSL::MyClass]
;


In the mwe2 file:
// generates Java API for the generated EPackages 
fragment = ecore.EcoreGeneratorFragment {
	referencedGenModels = "platform:/resource/mydsl/model/mydsl.genmodel"
}
...

// scoping and exporting API
fragment = scoping.ImportURIScopingFragment {}
fragment = exporting.SimpleNamesFragment {}

// scoping and exporting API 
//fragment = scoping.ImportNamespacesScopingFragment {}
//fragment = exporting.QualifiedNamesFragment {}




On runtime I use the 'import' statement in my xtext model to refer to the external EMF model file (here: "test1.mydsl") and I then get the following error:
java.lang.IllegalStateException: No IResourceServiceProvider found in registry for uri test1.mydsl

The analogous steps worked fine in xtext 0.7.2. Do you have any hint what could be missing for xtext 1.0?
Re: Cross-references to external EMF models [message #542899 is a reply to message #542733] Sun, 27 June 2010 11:07 Go to previous messageGo to next message
Sebastian Zarnekow is currently offline Sebastian ZarnekowFriend
Messages: 2961
Registered: July 2009
Senior Member
Hi Andreas,

I guess you are affected by this one:
https://bugs.eclipse.org/bugs/show_bug.cgi?id=307481

Xtext 1.0 introduces the concept of a IResourceServiceProvider which
exposes several interesting components for resource type. You have to
provide an implementation for your resource type similar to what's done
in the org.eclipse.xtext.ecore bundle.

I scheduled the ticket for SR1.

Sorry for any inconvenience,
Sebastian
--
Need professional support for Eclipse Modeling?
Go visit: http://xtext.itemis.com

Am 25.06.10 20:25, schrieb Andreas:
> I would like to define cross-references to elements in external EMF
> model files. The external EMF models there are defined by external ecore
> metamodels (here using 'mydsl.ecore' as example).
>
> In Xtext 0.7.2 this worked fine but I don't get it run with Xtext 1.0.
> In Xtext 1.0 I'm using the ImportURIScopingFragment and the
> SimpleNamesFragment (as proposed in previous postings like message
> #521601) but it still does not work.
>
> In the xtext file:
>
>
> import "platform:/resource/mydsl/model/mydsl.ecore" as myDSL
>
> [...]
>
> Import :
> 'import' importURI=STRING ';'
> ;
>
>
> Ref: 'ref' referencedObject=[myDSL::MyClass]
> ;
>
>
> In the mwe2 file:
>
> // generates Java API for the generated EPackages fragment =
> ecore.EcoreGeneratorFragment {
> referencedGenModels = "platform:/resource/mydsl/model/mydsl.genmodel"
> }
> ...
>
> // scoping and exporting API
> fragment = scoping.ImportURIScopingFragment {}
> fragment = exporting.SimpleNamesFragment {}
>
> // scoping and exporting API //fragment =
> scoping.ImportNamespacesScopingFragment {}
> //fragment = exporting.QualifiedNamesFragment {}
>
>
>
>
> On runtime I use the 'import' statement in my xtext model to refer to
> the external EMF model file (here: "test1.mydsl") and I then get the
> following error: java.lang.IllegalStateException: No
> IResourceServiceProvider found in registry for uri test1.mydsl
>
> The analogous steps worked fine in xtext 0.7.2. Do you have any hint
> what could be missing for xtext 1.0?
Re: Cross-references to external EMF models [message #555897 is a reply to message #542733] Mon, 30 August 2010 06:53 Go to previous messageGo to next message
Michael Frey is currently offline Michael FreyFriend
Messages: 48
Registered: August 2010
Member
Hi,

I've searched my xtext project for IResourceServiceProvider and I've only find a usage in src-gen/ in the class <Language>StandaloneSetupGenerated. So where exactely do I have to provide an implementation of IResourceServiceProvider for using an existing ecore model?

Thanks in advance!
Best regards,
Michael

Update: There is a posting by Christian Dietrich in another thread which might be helpful. I will have look at it.

[Updated on: Mon, 30 August 2010 09:10]

Report message to a moderator

Re: Cross-references to external EMF models [message #555958 is a reply to message #542733] Mon, 30 August 2010 11:43 Go to previous messageGo to next message
Michael Frey is currently offline Michael FreyFriend
Messages: 48
Registered: August 2010
Member
Hi,

I want to use an owl ecore model which resides in a directory "ressources/" in my project. Thus I've wrote in my xtext file:

import "platform:/ressources/owl.ecore" as myDSL


But the editor says "couldn't resolve reference to EPackage 'platform:/ressources/owl.ecore'".

I've followed the instructions in this posting. So far, I added to the UI Plugin.xml

	<extension point="org.eclipse.xtext.extension_resourceServiceProvider">
        <resourceServiceProvider
            class="de.hs_rm.cs.vs.dsm.ui.FlowExecutableExtensionFactory:org.eclipse.xtext.ui.resource.IResourceUIServiceProvider"
            uriExtension="flow">
        </resourceServiceProvider>
		<!-- Not sure if that's working, text below is new -->
        <resourceServiceProvider
            class="de.hs_rm.cs.vs.dsm.ui.FlowExecutableExtensionFactory:org.eclipse.xtext.ui.resource.IResourceUIServiceProvider"
            uriExtension="owl">
        </resourceServiceProvider>

    </extension>


and added in <Lang>StandAloneSetup.java


import com.google.inject.Injector;

/**
 * Initialization support for running Xtext languages 
 * without equinox extension registry
 */
public class FlowStandaloneSetup extends FlowStandaloneSetupGenerated{

	public static void doSetup() {
		new FlowStandaloneSetup().createInjectorAndDoEMFRegistration();
	}
	
	@Override
	public void register(Injector injector) {
		super.register(injector);
		org.eclipse.xtext.resource.IResourceServiceProvider serviceProvider = injector.getInstance(org.eclipse.xtext.resource.IResourceServiceProvider.class);
		org.eclipse.xtext.resource.IResourceServiceProvider.Registry.INSTANCE.getExtensionToFactoryMap().put("owl", serviceProvider);
	}

}



I've also created a ressource provider

import org.eclipse.emf.common.util.URI;
import org.eclipse.xtext.resource.impl.DefaultResourceServiceProvider;

public class FlowRessourceProvider extends DefaultResourceServiceProvider {
	@Override
	public boolean canHandle(URI uri) {
		if (uri.toPlatformString(true).endsWith("owl")) {
			return true;
		}
		return super.canHandle(uri);
	}
}


and finally added that information to the runtime module


import org.eclipse.xtext.resource.IResourceServiceProvider;

/**
 * Use this class to register components to be used at runtime / without the Equinox extension registry.
 */
public class FlowRuntimeModule extends de.hs_rm.cs.vs.dsm.AbstractFlowRuntimeModule {

	public Class<? extends IResourceServiceProvider> bindIResourceServiceProvider() {
		return FlowRessourceProvider.class;
	}

}


I've also added to the *.mwe2 file

// Added
fragment = org.eclipse.xtext.generator.ecore.EcoreGeneratorFragment {
 genModels = "platform:/resource/owl.genmodel"
}


It's not working. So probably somebody has an idea?

Regards,
Michael

P.S.: I've created an genmodel from the ecore model and removed the import statement from the xtext file and I'm getting the following exception.

0    [main] INFO  lipse.emf.mwe.utils.StandaloneSetup  - Registering platform uri '/home/michael/Desktop/Projekte'
3100 [main] WARN  erator.ecore.EcoreGeneratorFragment  - The property 'genModels' is deprecated. Please use 'referencedGenModels' instead.
3122 [main] INFO  ipse.emf.mwe.utils.DirectoryCleaner  - Cleaning /home/michael/Desktop/Projekte/de.hs_rm.cs.vs.dsm.flow/../de.hs_rm.cs.vs.dsm.flow/src-gen
3150 [main] INFO  ipse.emf.mwe.utils.DirectoryCleaner  - Cleaning /home/michael/Desktop/Projekte/de.hs_rm.cs.vs.dsm.flow/../de.hs_rm.cs.vs.dsm.flow.ui/src-gen
3587 [main] INFO  ipse.xtext.generator.LanguageConfig  - generating infrastructure for de.hs_rm.cs.vs.dsm.Flow with fragments : ImplicitRuntimeFragment, ImplicitUiFragment, GrammarAccessFragment, EcoreGeneratorFragment, ParseTreeConstructorFragment, ResourceFactoryFragment, XtextAntlrGeneratorFragment, JavaValidatorFragment, ImportNamespacesScopingFragment, QualifiedNamesFragment, BuilderIntegrationFragment, FormatterFragment, LabelProviderFragment, TransformerFragment, OutlineNodeAdapterFactoryFragment, QuickOutlineFragment, QuickfixProviderFragment, JavaBasedContentAssistFragment, XtextAntlrUiGeneratorFragment, EcoreGeneratorFragment
48148 [main] INFO  or.validation.JavaValidatorFragment  - executing generate for org.eclipse.xtext.generator.validation.JavaValidatorFragment
59058 [main] ERROR erator.ecore.EcoreGeneratorFragment  - Couldn't find genmodel for uri 'platform:/resource/owl.genmodel'
java.lang.RuntimeException: java.lang.StringIndexOutOfBoundsException: String index out of range: -2
	at org.eclipse.xtext.generator.ecore.EcoreGeneratorFragment.loadReferencedGenModels(EcoreGeneratorFragment.java:191)
	at org.eclipse.xtext.generator.ecore.EcoreGeneratorFragment.generate(EcoreGeneratorFragment.java:160)
	at org.eclipse.xtext.generator.CompositeGeneratorFragment.generate(CompositeGeneratorFragment.java:81)
	at org.eclipse.xtext.generator.LanguageConfig.generate(LanguageConfig.java:69)
	at org.eclipse.xtext.generator.Generator.generate(Generator.java:296)
	at org.eclipse.xtext.generator.Generator.invokeInternal(Generator.java:106)
	at org.eclipse.emf.mwe.core.lib.AbstractWorkflowComponent.invoke(AbstractWorkflowComponent.java:126)
	at org.eclipse.emf.mwe.core.lib.Mwe2Bridge.invoke(Mwe2Bridge.java:34)
	at org.eclipse.emf.mwe.core.lib.AbstractWorkflowComponent.invoke(AbstractWorkflowComponent.java:201)
	at org.eclipse.emf.mwe2.runtime.workflow.AbstractCompositeWorkflowComponent.invoke(AbstractCompositeWorkflowComponent.java:31)
	at org.eclipse.emf.mwe2.runtime.workflow.Workflow.run(Workflow.java:19)
	at org.eclipse.emf.mwe2.launch.runtime.Mwe2Runner.run(Mwe2Runner.java:80)
	at org.eclipse.emf.mwe2.launch.runtime.Mwe2Runner.run(Mwe2Runner.java:52)
	at org.eclipse.emf.mwe2.launch.runtime.Mwe2Launcher.run(Mwe2Launcher.java:74)
	at org.eclipse.emf.mwe2.launch.runtime.Mwe2Launcher.main(Mwe2Launcher.java:35)
Caused by: java.lang.StringIndexOutOfBoundsException: String index out of range: -2
	at java.lang.String.substring(String.java:1937)
	at org.eclipse.emf.ecore.plugin.EcorePlugin.resolvePlatformResourcePath(EcorePlugin.java:133)
	at org.eclipse.emf.ecore.resource.impl.PlatformResourceURIHandlerImpl.createInputStream(PlatformResourceURIHandlerImpl.java:452)
	at org.eclipse.emf.ecore.resource.impl.ExtensibleURIConverterImpl.createInputStream(ExtensibleURIConverterImpl.java:301)
	at org.eclipse.emf.ecore.resource.impl.ResourceImpl.load(ResourceImpl.java:1254)
	at org.eclipse.emf.ecore.resource.impl.ResourceSetImpl.demandLoad(ResourceSetImpl.java:255)
	at org.eclipse.emf.ecore.resource.impl.ResourceSetImpl.demandLoadHelper(ResourceSetImpl.java:270)
	at org.eclipse.emf.ecore.resource.impl.ResourceSetImpl.getResource(ResourceSetImpl.java:397)
	at org.eclipse.xtext.generator.ecore.EcoreGeneratorFragment$1.getResource(EcoreGeneratorFragment.java:432)
	at org.eclipse.xtext.generator.ecore.EcoreGeneratorFragment.loadReferencedGenModels(EcoreGeneratorFragment.java:182)
	... 14 more
59517 [main] INFO  .emf.mwe2.runtime.workflow.Workflow  - D

[Updated on: Mon, 30 August 2010 12:18]

Report message to a moderator

Re: Cross-references to external EMF models [message #555963 is a reply to message #555897] Mon, 30 August 2010 11:59 Go to previous messageGo to next message
Sven Efftinge is currently offline Sven EfftingeFriend
Messages: 1771
Registered: July 2009
Senior Member
Am 8/30/10 8:53 AM, schrieb Michael Frey:
> Hi,
>
> I've searched my xtext project for IResourceServiceProvider and I've
> only find a usage in src-gen/ in the class
> <Language>StandaloneSetupGenerated. So where exactely do I have to
> provide an implementation of IResourceServiceProvider for using an
> existing ecore model?
>
> Thanks in advance!
> Best regards,
> Michael

IResourceServiceProviders are registered per language (per file
extension). In eclipse you use an extension point :

<extension point="org.eclipse.xtext.extension_resourceServiceProvider" >
<resourceServiceProvider class="my.special.FooResourceServiceProvider"
uriExtension="myLang">
</resourceServiceProvider>
</extension>

At runtime (i.e. without extension registry) you need to add your
implementation to the
org.eclipse.xtext.resource.IResourceServiceProvider.Registry .INSTANCE
programmatically.

Sven


--
--
Need professional support for Xtext or other Eclipse Modeling technologies?
Go to: http://xtext.itemis.com
Twitter : @svenefftinge
Blog : http://blog.efftinge.de


--
Need professional support on Xtext or Xtend?
Mail to: xtext (at) itemis.com
Twitter : @svenefftinge
Blog : blog.efftinge.de
Re: Cross-references to external EMF models [message #555971 is a reply to message #555958] Mon, 30 August 2010 12:29 Go to previous messageGo to next message
Sven Efftinge is currently offline Sven EfftingeFriend
Messages: 1771
Registered: July 2009
Senior Member
Am 8/30/10 1:43 PM, schrieb Michael Frey:
> Hi,
>
> I want to use an owl ecore model which resides in a directory
> "ressources/" in my project. Thus I've wrote in my xtext file:
>
> import "platform:/ressources/owl.ecore" as myDSL


The correct URI would be

platform:/resource/project.name/ressources/owl.ecore


Sven

--
--
Need professional support for Xtext or other Eclipse Modeling technologies?
Go to: http://xtext.itemis.com
Twitter : @svenefftinge
Blog : http://blog.efftinge.de


--
Need professional support on Xtext or Xtend?
Mail to: xtext (at) itemis.com
Twitter : @svenefftinge
Blog : blog.efftinge.de
Re: Cross-references to external EMF models [message #556419 is a reply to message #542733] Wed, 01 September 2010 09:20 Go to previous messageGo to next message
Michael Frey is currently offline Michael FreyFriend
Messages: 48
Registered: August 2010
Member
Hi,

so far I've changed the path and the model is found. I can select elements of the external ecore model and everything seems fine. After I've generated the xtext artifacts some files in src-gen/ complain that they cannot resolve the type. Precisely this are the elements of my language which are using elements of the external ecore model. Maybe I'm missing the point but I've thought I have only to provide the ecore model and a genmodel created by EMF. Maybe somebody could point me into the right direction? Thanks in advance!

Regards,
Michael

P.S.: This question is not up to hundred percent related to the topic, but I think it's best to keep it in this thread.
Re: Cross-references to external EMF models [message #556420 is a reply to message #556419] Wed, 01 September 2010 09:22 Go to previous message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 6550
Registered: July 2009
Senior Member
Hi,

just add your.external.emf.metamodel.modelclasses plugin to the plugin dependencies of your xtext plugin project. (you have to generate model code from the gemodel)

Regards
Christian

[Updated on: Wed, 01 September 2010 09:23]

Report message to a moderator

Previous Topic:Can't use Cross-References to imported DataTypes with compatible return values
Next Topic:Using external ecore models
Goto Forum:
  


Current Time: Sat Dec 20 22:31:30 GMT 2014

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

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