Connecting Xtext DSL to external Ecore model [message #547203] |
Thu, 15 July 2010 22:26 |
Mirko Raner Messages: 125 Registered: July 2009 Location: New York City, NY |
Senior Member |
|
|
Hi,
I think my question is similar to what was asked in message #543960 (http://www.eclipse.org/forums/index.php?t=msg&th=171098), but unfortunately that thread did not get resolved.
I am trying to connect two models: an Xtext language, let's call it "Interview", and an existing EMF model, let's call that "Template".
The Template is essentially a tree structure of items that is read from a set of binary files using custom a ResourceImpl and URIConverter. The Template works fine by itself and can be readily explored using the reflective Ecore editor.
The Interview language contains references into the binary model exposed by the Template. The Xtext grammar for the Interview language imports the Ecore model for the Template, and refers to Template data-types in various productions. The Xtext grammar translates without errors and seems to work fine in general.
I'm using a StateBasedContainerManager in conjunction with WorkspaceProjectsState to group all resources inside a single Eclipse project. The Template for the project is defined by a single properties file that points to the binary resources for the Template model (the custom ResourceImpl and URIConverter generate the actual resource from that properties file). The Template is simply defined by the file being present, none of the Interview language files make any direct reference to it (import, include, etc.). The assumption is that all Interview language files use the Template defined by the properties file in their project's root.
In my current set-up, I don't get any content assist, and I get resolution errors for any references into the Template model. Ctrl+Shift+F3 only shows me items from the Interview language, but no items from the Template.
When I set a breakpoint in the WorkspaceProjectsStateHelper, I noticed that only Interview resources get processed, but not the Template properties file. I experimented with customizing WorkspaceProjectsStateHelper, Storage2UriMapper, UriValidator, IResourceServiceProvider, and IScopeProvider, but so far with no success.
What do I need to do to bring the Template model into the scope of the Interview resources of a project? Any pointers are much appreciated!
I can't post any example snippets because we're talking about proprietary code here. I hope my description gives a decent idea of what I'm trying to achieve.
Thanks in advance!
Mirko
|
|
|
Re: Connecting Xtext DSL to external Ecore model [message #547241 is a reply to message #547203] |
Fri, 16 July 2010 05:06 |
Moritz Eysholdt Messages: 161 Registered: July 2009 Location: Kiel, Germany |
Senior Member |
|
|
Hi Mirko,
it's good to see you're on it again :)
> I think my question is similar to what was asked in message #543960
> (http://www.eclipse.org/forums/index.php?t=msg&th=171098), but
> unfortunately that thread did not get resolved.
>
> I am trying to connect two models: an Xtext language, let's call it
> "Interview", and an existing EMF model, let's call that "Template".
Sounds familiar :)
> The Template is essentially a tree structure of items that is read from
> a set of binary files using custom a ResourceImpl and URIConverter. The
> Template works fine by itself and can be readily explored using the
> reflective Ecore editor.
> The Interview language contains references into the binary model exposed
> by the Template. The Xtext grammar for the Interview language imports
> the Ecore model for the Template, and refers to Template data-types in
> various productions. The Xtext grammar translates without errors and
> seems to work fine in general.
>
> I'm using a StateBasedContainerManager in conjunction with
> WorkspaceProjectsState to group all resources inside a single Eclipse
> project. The Template for the project is defined by a single properties
> file that points to the binary resources for the Template model (the
> custom ResourceImpl and URIConverter generate the actual resource from
> that properties file). The Template is simply defined by the file being
> present, none of the Interview language files make any direct reference
> to it (import, include, etc.). The assumption is that all Interview
> language files use the Template defined by the properties file in their
> project's root.
Sounds just right so far.
How comes you need a custom URIConverter? For the most cases it's
sufficient to register a ResourceFactory for your (the template's) file
extension.
> In my current set-up, I don't get any content assist, and I get
> resolution errors for any references into the Template model.
> Ctrl+Shift+F3 only shows me items from the Interview language, but no
> items from the Template.
> When I set a breakpoint in the WorkspaceProjectsStateHelper, I noticed
> that only Interview resources get processed, but not the Template
> properties file. I experimented with customizing
> WorkspaceProjectsStateHelper, Storage2UriMapper, UriValidator,
> IResourceServiceProvider, and IScopeProvider, but so far with no success.
>
> What do I need to do to bring the Template model into the scope of the
> Interview resources of a project? Any pointers are much appreciated!
You'll have to make sure Xtext's builder processes the template models.
For this, you need to register an IResourceServiceProvider for your file
extension. This concept has been inspired by EMF's ResourceFactory.
As an example you can look at any Xtext-based language: For the
runtime-scenario the registration is done in the
MyLanguageStandaloneSetup. For the UI-Scenario, the registration is done
via the .ui-plugin's plugin.xml file.
Furthermore, the plugins org.eclipse.xtext.ecore and
org.eclipse.xtext.ecore make good examples. Both ship with Xtext.
It may be necessary to create a Guice-based Injector (and a
RuntimeModule and UIModule) for your template models, too.
hth,
Moritz
> I can't post any example snippets because we're talking about
> proprietary code here. I hope my description gives a decent idea of what
> I'm trying to achieve.
>
> Thanks in advance!
>
> Mirko
>
--
Need professional support for Eclipse Modeling?
Go visit: http://xtext.itemis.com
|
|
|
Re: Connecting Xtext DSL to external Ecore model [message #547433 is a reply to message #547241] |
Fri, 16 July 2010 18:36 |
Mirko Raner Messages: 125 Registered: July 2009 Location: New York City, NY |
Senior Member |
|
|
Thanks for the pointers, Moritz. I'll try what you suggested.
> it's good to see you're on it again
Yep, there have been another couple of changes in direction, but Xtext is just too promising to let go of.
> > I am trying to connect two models: an Xtext language, let's call it
> > "Interview", and an existing EMF model, let's call that "Template".
>
> Sounds familiar
I thought you might recognize it
> How comes you need a custom URIConverter? For the most cases it's
> sufficient to register a ResourceFactory for your (the template's) file
> extension.
There were a couple of difficulties. The actual Template data is not one file, but several (binary) files, all of which typically reside outside of the workspace. A native executable needs to be used to turn all of these binary files into XML that can be read into an Ecore model. In the workspace, the data for each project is represented by a single properties file that points to the Template location in the file system (and to the native executable to convert it). The content type is not registered by file extension, but by a specific file name ("Formset"). The custom URIConverter's createInputStream(URI, Map<?,?>) method reads the contents of the properties file, invokes the native executable, and returns an InputStream that represents the binary data as XML. Customizing the URIConverter seemed to be a good solution for representing the Template data as a file in the workspace, while the actual underlying data was stored outside the workspace.
|
|
|
|
Re: Connecting Xtext DSL to external Ecore model [message #681783 is a reply to message #681767] |
Thu, 09 June 2011 20:49 |
|
Hi,
i am not sure what you want to do with that import stuff. you say you want to access existing instances (e.g. of an EClass). this kind of access is usually done via a reference. the syntax for that reference looks like nameOfTheReference=[StuffYouWantToReference|RuleToParseTheNameThingLinkingIsDoneBy]. in your case this would be uidtToUse=[UID::UserInterfaceDiagramType|QualifiedName]. you default only elements in other Xtext based model and .ecore models are available out of the box. To you the referncing working for any other ecore based model you have to come up (as mentioned above) with an IResourceServiceProvider for your specific resource. Xtext does this already for .ecore files with the plugins org.eclipse.xtext.ecore and
org.eclipse.xtext.ui.ecore. you can play copycat there.
~Christian
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Re: Connecting Xtext DSL to external Ecore model [message #688249 is a reply to message #688230] |
Fri, 24 June 2011 09:00 |
Missing name Mising name Messages: 16 Registered: June 2011 |
Junior Member |
|
|
My use case is like:
I have a DSL (AutomatedFunctionalTest=AFT) which imports/references (UserInterfaceDiagram=UID) emf models.
generate automatedfunctionaltest "http://www.xxx.com/hpt/testrunner/aft/AutomatedFunctionalTest"
import "platform:/resource/com.xxx.hpt.testrunner/src/com/xxx/hpt/testrunner/uid/UserInterfaceDiagram.ecore" as UID
I have a click rule like:
Click: 'click' objectReference=[UID::DomObject|QualifiedName];
I have another emf model (ObjectMappingDiagram=OMD) which looks like:
<?xml version="1.0" encoding="UTF-8"?>
<objectmappingdiagram:ObjectMappingDiagram
name="HPT" xmlns:objectmappingdiagram="http://www.xxx.com/hpt/omd/objectmappingdiagram/1.0.0/"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.xxx.com/hpt/omd/objectmappingdiagram/1.0.0/ ObjectMappingDiagram.xsd">
<Map qualifiedname="TestFrontEndComponents.DefaultNavigation.Login.Submit" by="css">div.button</Map>
</objectmappingdiagram:ObjectMappingDiagram>
The qualifiedname attribute is the same as the qualified name of the click objectReference So my generated code for the click should look like:
selenium.click("TestFrontEndComponents.DefaultNavigation.Login.Submit");
I cant follow any reference because only UID models are referenced in the DSL.
[Updated on: Fri, 24 June 2011 09:01] Report message to a moderator
|
|
|
Re: Connecting Xtext DSL to external Ecore model [message #688251 is a reply to message #688249] |
Fri, 24 June 2011 09:10 |
|
Hi,
strange: you said
Quote:
the builder populates the index with all the namespaces found in *.omd files which can then be referenced in the DSL.
so do you refernce or don't you. if not it won't work out of the box with this Builder Based Code Generation.
What are the rules how these omd files should be taken into account. all files?
Maybe you can inject "The Index" aka IResourceDescriptions to the generator
and extract the index stuff from the .omd resources from there.
~Christian
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
|
|
|
Re: Connecting Xtext DSL to external Ecore model [message #688257 is a reply to message #688251] |
Fri, 24 June 2011 09:27 |
Missing name Mising name Messages: 16 Registered: June 2011 |
Junior Member |
|
|
Yes; I registered:
<extension point="org.eclipse.xtext.extension_resourceServiceProvider">
<resourceServiceProvider class="com.xxx.hpt.testrunner.omd.ui.ExecutableExtensionFactory:org.eclipse.xtext.ui.resource.generic.EmfResourceUIServiceProvider" uriExtension="omd" />
</extension>
but the OMD model is not imported into the grammar and there are no emf cross-reference from the UID model to the OMD model.
However if it's possible to inject the resourceDescriptions into the generator then that should do it.
Thanx,
Sorry about such a silly question
[Updated on: Fri, 24 June 2011 09:27] Report message to a moderator
|
|
|
Powered by
FUDForum. Page generated in 0.04668 seconds