Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » How to share model instanced between Xtext generated model and referred DomainModel
How to share model instanced between Xtext generated model and referred DomainModel [message #689024] Sun, 26 June 2011 15:00 Go to next message
Nidhi  is currently offline Nidhi Friend
Messages: 92
Registered: December 2009
Member

Hi,

This was my use case, I was writing a grammar for simple business rules:
"age > 18"

The rule for each comparison expression looks like this:
ComparisonExpression:
(variable=[Variable]) '>' INT

where 'age', 'gender' and 'DOB' are instances of [Variable] that come from a referenced Ecore model (MyDomainModel) in my workspace.

With a lot of help in my previous posts I was able to generate the ecore model "BusinessRulesModel", content assists etc from my grammar.

My next question is following:
In my runtime work bench MyDomainModel instances are created and hence instances of EClass "Variable" such as "age", "gender" and "DOB" are also created. I want to use these instances in my Xtext generated BusinessRuleModel.

How do I integrate the two. Thanks for any help.

Best Regards,
Nidhi
Re: How to share model instanced between Xtext generated model and referred DomainModel [message #689025 is a reply to message #689024] Sun, 26 June 2011 15:16 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Hi,

as i said before you need to come up with an ResourceServiceProvider for you existing metamodel. Such a ResourceServiceProvider "exports" the Variables from your MyDomainModel files
and thus makes then referencable from Xtext. Have a look at the code of the plugins org.eclipse.xtext.ecore and org.eclipse.xtext.ui.ecore to get an idea what to do (these contain a resourceserviceprovider for .ecore files)

~Christian


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: How to share model instanced between Xtext generated model and referred DomainModel [message #689072 is a reply to message #689025] Sun, 26 June 2011 18:05 Go to previous messageGo to next message
Nidhi  is currently offline Nidhi Friend
Messages: 92
Registered: December 2009
Member

Hi Christian,

I am sorry, but I dont understand this well.
Should my domain model extend the extension point:
<extension point="org.eclipse.xtext.extension_resourceServiceProvider">


and provide its own ResourceServiceProvider. Then I can use the same in my DSL plugin to get a handle of the my domain model resource.

Best Regards,
Nidhi
Re: How to share model instanced between Xtext generated model and referred DomainModel [message #689076 is a reply to message #689072] Sun, 26 June 2011 18:11 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Hi,

yes if you provide a ResourceServiceProvider through this extension point the stuff from your domainmodel files gets indexed and thus can be referenced from your dsl files.

~Christian


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de

[Updated on: Sun, 26 June 2011 18:15]

Report message to a moderator

Re: How to share model instanced between Xtext generated model and referred DomainModel [message #689080 is a reply to message #689076] Sun, 26 June 2011 18:46 Go to previous messageGo to next message
Nidhi  is currently offline Nidhi Friend
Messages: 92
Registered: December 2009
Member

Hi Christian,

I have created my own ResourceServiceProvider, ResourceDescription and ResourceDescriptionManager.
Have also overridden the computeExportedObjects() to identify the objects that need to be exported.

But am lost at this point. In the org.eclipse.xtext.core, I see 3 other classes implementing IWorkflowComponent, extends AbstractGenericModule and implements IEncodingProvider. I dont understand Google Guice as well.

Do I need these too or just identifying the the exported Objects is sufficient. Can you please help me understand this better. Is there any short tutorial you can point me to.

Best Regards,
Nidhi
Re: How to share model instanced between Xtext generated model and referred DomainModel [message #689081 is a reply to message #689080] Sun, 26 June 2011 18:48 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Hi,

as i said before: have a look at org.eclipse.xtext.ecore and org.eclipse.xtext.ui.ecore. turn into a copycat and create a copy & paste adaption for your domainmodel stuff.

~Christian


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: How to share model instanced between Xtext generated model and referred DomainModel [message #689097 is a reply to message #689081] Sun, 26 June 2011 20:18 Go to previous messageGo to next message
Nidhi  is currently offline Nidhi Friend
Messages: 92
Registered: December 2009
Member

Hi Christian,

I created an adaptation for my domain model. I extended the extension point
<extension point="org.eclipse.xtext.extension_resourceServiceProvider">
and created my own ResourceServiceProvider, etc in my domain model plugins.

Now in my DSL plugin should I do something with the content assist so that it gives me these instances exported from my domain model in the editor.

Best Regards,
Nidhi
Re: How to share model instanced between Xtext generated model and referred DomainModel [message #689101 is a reply to message #689097] Sun, 26 June 2011 20:38 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Hi,

first you should make sure that the stuff from you domain model files are exported. you can check this with crtl+shift+f3.
second if you have a reference in your dsl file you should get the Elements proposed automatically. (of cource the model files have to be in the same container than the dsl files e.g. in the classpath for java projects).

~Christian


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de

[Updated on: Sun, 26 June 2011 20:44]

Report message to a moderator

Re: How to share model instanced between Xtext generated model and referred DomainModel [message #689114 is a reply to message #689101] Sun, 26 June 2011 21:30 Go to previous messageGo to next message
Nidhi  is currently offline Nidhi Friend
Messages: 92
Registered: December 2009
Member

Hi Christian,

I would have been pleasantly surprised if this had worked Smile, I am sure I goofed up somewhere in the ResourceServiceProvider. I don't get anything either on ctrl+shift+f3 nor on ctrl+space in the editor.

Irrespective of that even if the domain model successfully exports the objects. Should not the xtext editor only show those model instances of the domain model to which it is bound.

In the sense, in my runtime workbench what would connect the new xtext file that I create (with my custom extension ".brDsl") to the domain model instance. Since I can create many instances of the domain model.

Thanks,
Best Regards,
Nidhi
Re: How to share model instanced between Xtext generated model and referred DomainModel [message #689115 is a reply to message #689114] Sun, 26 June 2011 21:38 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Hi,

can you post the classes you create around the resource service provider? the conntection between the dsl files and the domain model files is the name through wich the referencing is done. guess you have a grammar like "attr" attr=[domainmodel::Attribute] and and model like attr test then the reference goes to the attribute that is exported with the name test to the index,.

~Christian


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: How to share model instanced between Xtext generated model and referred DomainModel [message #689125 is a reply to message #689115] Sun, 26 June 2011 22:19 Go to previous messageGo to next message
Nidhi  is currently offline Nidhi Friend
Messages: 92
Registered: December 2009
Member

Hi Christian,

Please find details here:

I have 6 projects in my workspace:

1. com.test.domainmodel (contains my ecore domain model and EMF generated metamodel code)
2. com.test.domainmodel.editor (contains the EMF generated Editor code)
3. com.test.domainmodel.edit (contains the EMF generated Edit code)
4. com.test.mydsl (containing my grammar)
5. com.test.mydsl.generator (xtext generated)
6. com.test.mydsl.ui (xtext generated)

My domain model is persisted with a file extension ".xml".

In my com.test.domainmodel.editor I extend the extension point
   <extension
         point="org.eclipse.xtext.extension_resourceServiceProvider">
      <resourceServiceProvider
            class="com.test.domainmodel.MyResourceServiceProviderImpl"
            uriExtension="xml">
      </resourceServiceProvider>
   </extension>


In class MyResourceServiceProviderImpl I only change one method:
	public boolean canHandle(URI uri) {
		return "xml".equals(uri.fileExtension());
	}


In class MyResourceDescription I only change at 1 place:
private static final class Switch extends DomainModelSwitch<IEObjectDescription> {
		@Override
		public IEObjectDescription caseNamedServiceObject(NamedDomainObject object) {
			return new EObjectDescription(object.getName(), object, null);
		}
	}


In class MyRuntimeModule I only change one method:
public void configureFileExtensions(Binder binder) {
		binder.bind(String.class).annotatedWith(Names.named(Constants.FILE_EXTENSIONS)).toInstance("xml");
	}


The rest of the classes namely MyResourceDescriptionManager is exactly like EcoreResourceDescriptionManager, MySupport same as EcoreSupport and MyXMLEncodingProvider same as XMLEncodingProvider. These match the classes in the plugin org.eclipse.xtext.ecore.

Please find attached the 3 files I changed.

Also want to point out that ctrl+shift+f3 now shows all the model instances that are created in the runtime workbench Smile. But I dont see it in the content assist in the editor yet.

Best Regards,
Nidhi
  • Attachment: changes.rar
    (Size: 2.52KB, Downloaded 94 times)

[Updated on: Sun, 26 June 2011 22:33]

Report message to a moderator

Re: How to share model instanced between Xtext generated model and referred DomainModel [message #689128 is a reply to message #689125] Sun, 26 June 2011 22:46 Go to previous message
Nidhi  is currently offline Nidhi Friend
Messages: 92
Registered: December 2009
Member

Hi Christian,

It works Smile and this time I am not sure how I just redid the whole thing again.
Phew! And thanks a tonne Smile once again.

Now I have one more question Smile, you had mentioned if I want to do some customization on top of this,
such as if the type attribute of my referenced entity "age" ([domainmodel :: Variable]) is "java.lang.Integer" the RHS of
"age > 18" should be an integer too. You mentioned that this needs to be done in the content assist itself.

Best Regards,
Nidhi

Previous Topic:Xtext Grammar for comparison expressions
Next Topic:Using a "common" grammar from a separate plug-in
Goto Forum:
  


Current Time: Thu Apr 25 16:19:15 GMT 2024

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

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

Back to the top