Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » QVT-Relations » Generate qvtr file programmatically
Generate qvtr file programmatically [message #1069206] Mon, 15 July 2013 12:15 Go to next message
Simon Schwichtenberg is currently offline Simon SchwichtenbergFriend
Messages: 127
Registered: September 2011
Senior Member
Hi,

I want to generate a simple qvtr file programmatically. My idea was to exploit the qvtd Xtext editor: I want to make changes to the in-memory representation of the ecore model and use the xtext serialization to write the model to a file.

I am using QVTd 0.9.0 since I am on Juno (in 0.9.0 the import declaration cause parse errors, that why they are in comments)

In a first step, I load a template file and try to make a copy of it, which fails.

--import requester:'requester.ecore'::requester;
--import provider:'provider.ecore'::provider;


transformation model2requester(source:provider, target:requester){

}


my code is as follows:

private TopLevelCS root;
private RelationModel rm;
private URI uri;
private void initialize(){
//new VTrelationStandaloneSetup().createInjectorAndDoEMFRegistration();
		
		QVTrelationStandaloneSetup.doSetup();
		
		URI templateUri = URI.createPlatformPluginURI("/"+Activator.ID+"/qvtr/template.qvtr",true);
		
		ResourceSet rs = new ResourceSetImpl();
		
		Resource templateResource = rs.getResource(templateUri, true);
		
		root = (TopLevelCS) templateResource.getContents().get(0);
		
		rm = (RelationModel) root.getPivot();
		org.eclipse.ocl.examples.pivot.Package pack = rm.getNestedPackage().get(0);

		ResourceSet rs = new ResourceSetImpl();
		XtextResource r = (XtextResource) rs.createResource(uri);
		r.getContents().add(rm);
		r.setValidationDisabled(true);
		
		SaveOptions.Builder b = SaveOptions.newBuilder();
		b.noValidation();
		b.format();
		
		Map options = b.getOptions().toOptionsMap();
		
		try {
			r.save(options);
		} catch (IOException e2) {
			// TODO Auto-generated catch block
			e2.printStackTrace();
		}
}


What I get is:

org.eclipse.xtext.parsetree.reconstr.XtextSerializationException: Serialization failed
<# of serialized tokens>: <EObject path> "<serializable fragment, starting from the end>":
-> <possible reasons for not continuing>
1:RelationModel'template.qvtr': "'template.qvtr'":
-> StringLiteralExpCS_NameAssignment: NamedElement(RelationModel).name is not set.
-> Can not leave rule 'StringLiteralExpCS' since the current object 'RelationModel' has features with unconsumed values: 'nestedPackage':1
at org.eclipse.xtext.parsetree.reconstr.impl.AbstractParseTreeConstructor.serialize(AbstractParseTreeConstructor.java:686)
at org.eclipse.xtext.parsetree.reconstr.impl.AbstractParseTreeConstructor.serialize(AbstractParseTreeConstructor.java:693)
at org.eclipse.xtext.parsetree.reconstr.impl.AbstractParseTreeConstructor.serializeSubtree(AbstractParseTreeConstructor.java:716)
at org.eclipse.xtext.parsetree.reconstr.Serializer.serialize(Serializer.java:61)
at org.eclipse.xtext.parsetree.reconstr.Serializer.serialize(Serializer.java:67)
at org.eclipse.xtext.resource.XtextResource.doSave(XtextResource.java:316)
at org.eclipse.emf.ecore.resource.impl.ResourceImpl.save(ResourceImpl.java:1417)
at org.eclipse.emf.ecore.resource.impl.ResourceImpl.save(ResourceImpl.java:986)
...


The error message confuses me, because RelationModel.name is set. How can I solve this?


Regards,
Simon


Re: Generate qvtr file programmatically [message #1069226 is a reply to message #1069206] Mon, 15 July 2013 13:04 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
Registered: July 2009
Senior Member
Hi

Sorry. The Pivot2CS functionality is really only implemented for OCL,
where it is critical to the Ecore->Pivot->Text for the OCLinEcore editor
and is also used by an API-less UML->Pivot->OCLcs CompleteOCLSplitter
facility.

The QVT extensions to OCL do not differ dramatically between AS and CS
so it shouldn't be that hard to emulate for instance the two classes in
org.eclipse.ocl.examples.xtext.oclinecore.pivot2cs to realize
org.eclipse.qvtd.xtext.qvtrelation.pivot2cs. However while the Xtext
serialization capability is powerful, it can also be troublesome. There
is no problem in multiple concrete syntazes producing the same abstract
syntax. In the reverse direction the serializer can be obscure while
warning you that it doesn't know how to resolve an ambiguity. Sometimes
the Xtext grammar exposition has to be revised.

Doing this is low on my priority list because there is separate work on
auto-generating the AS <> CS mappings and so any manual contribution now
will be discarded in a year or so.

Regards

Ed Willink


On 15/07/2013 13:15, Goood Guy wrote:
> Hi,
>
> I want to generate a simple qvtr file programmatically. My idea was to
> exploit the qvtd Xtext editor: I want to make changes to the in-memory
> representation of the ecore model and use the xtext serialization to
> write the model to a file.
>
> I am using QVTd 0.9.0 since I am on Juno (in 0.9.0 the import
> declaration cause parse errors, that why they are in comments)
>
> In a first step, I load a template file and try to make a copy of it,
> which fails.
>
>
> --import requester:'requester.ecore'::requester;
> --import provider:'provider.ecore'::provider;
>
>
> transformation model2requester(source:provider, target:requester){
>
> }
>
>
> my code is as follows:
>
>
> private TopLevelCS root;
> private RelationModel rm;
> private URI uri;
> private void initialize(){
> //new VTrelationStandaloneSetup().createInjectorAndDoEMFRegistration();
>
> QVTrelationStandaloneSetup.doSetup();
>
> URI templateUri =
> URI.createPlatformPluginURI("/"+Activator.ID+"/qvtr/template.qvtr",true);
>
> ResourceSet rs = new ResourceSetImpl();
>
> Resource templateResource = rs.getResource(templateUri, true);
>
> root = (TopLevelCS) templateResource.getContents().get(0);
>
> rm = (RelationModel) root.getPivot();
> org.eclipse.ocl.examples.pivot.Package pack =
> rm.getNestedPackage().get(0);
>
> ResourceSet rs = new ResourceSetImpl();
> XtextResource r = (XtextResource) rs.createResource(uri);
> r.getContents().add(rm);
> r.setValidationDisabled(true);
>
> SaveOptions.Builder b = SaveOptions.newBuilder();
> b.noValidation();
> b.format();
>
> Map options = b.getOptions().toOptionsMap();
>
> try {
> r.save(options);
> } catch (IOException e2) {
> // TODO Auto-generated catch block
> e2.printStackTrace();
> }
> }
>
>
> What I get is:
>
> org.eclipse.xtext.parsetree.reconstr.XtextSerializationException:
> Serialization failed
> <# of serialized tokens>: <EObject path> "<serializable fragment,
> starting from the end>":
> -> <possible reasons for not continuing>
> 1:RelationModel'template.qvtr': "'template.qvtr'":
> -> StringLiteralExpCS_NameAssignment:
> NamedElement(RelationModel).name is not set.
> -> Can not leave rule 'StringLiteralExpCS' since the current object
> 'RelationModel' has features with unconsumed values: 'nestedPackage':1
> at
> org.eclipse.xtext.parsetree.reconstr.impl.AbstractParseTreeConstructor.serialize(AbstractParseTreeConstructor.java:686)
> at
> org.eclipse.xtext.parsetree.reconstr.impl.AbstractParseTreeConstructor.serialize(AbstractParseTreeConstructor.java:693)
> at
> org.eclipse.xtext.parsetree.reconstr.impl.AbstractParseTreeConstructor.serializeSubtree(AbstractParseTreeConstructor.java:716)
> at
> org.eclipse.xtext.parsetree.reconstr.Serializer.serialize(Serializer.java:61)
> at
> org.eclipse.xtext.parsetree.reconstr.Serializer.serialize(Serializer.java:67)
> at
> org.eclipse.xtext.resource.XtextResource.doSave(XtextResource.java:316)
> at
> org.eclipse.emf.ecore.resource.impl.ResourceImpl.save(ResourceImpl.java:1417)
> at
> org.eclipse.emf.ecore.resource.impl.ResourceImpl.save(ResourceImpl.java:986)
> ...
>
>
> The error message confuses me, because RelationModel.name is set. How
> can I solve this?
>
>
> Regards,
> Simon
>
>
>
Re: Generate qvtr file programmatically [message #1069253 is a reply to message #1069226] Mon, 15 July 2013 14:16 Go to previous messageGo to next message
Simon Schwichtenberg is currently offline Simon SchwichtenbergFriend
Messages: 127
Registered: September 2011
Senior Member
Thanks. I guess the next most clean way is to use a M2T transformation (e.g. xpand) instead of the xtext serialization.
Re: Generate qvtr file programmatically [message #1069279 is a reply to message #1069253] Mon, 15 July 2013 15:28 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
Registered: July 2009
Senior Member
Hi

xpand has been merged into xtend.

The Xtext serialization mostly does a good job of the M2T. Its the AS to
CS M2M that's missing, so if you did M2T directly from the AS you would
have to do the trivial QVT AS to CS but also the much less trivial OCL
AS to CS as well.

Regards

Ed Willink


On 15/07/2013 15:16, Goood Guy wrote:
> Thanks. I guess the next most clean way is to use a M2T transformation
> (e.g. xpand) instead of the xtext serialization.
Re: Generate qvtr file programmatically [message #1071180 is a reply to message #1069279] Fri, 19 July 2013 14:04 Go to previous messageGo to next message
Simon Schwichtenberg is currently offline Simon SchwichtenbergFriend
Messages: 127
Registered: September 2011
Senior Member
ok, my plan now is to create the QVTrelation programmatically and create the qvtr file via an xtend transformation (my transformations are very basic, so I do not need to cover complete QVT/OCL):

root = QVTrelationFactory.eINSTANCE.createRelationModel();
transformation = QVTrelationFactory.eINSTANCE.createRelationalTransformation();
root.getNestedPackage().add(transformation);

providerPackage = PivotFactory.eINSTANCE.createPackage();
providerPackage.setName("providerPackage");
		
requesterPackage = PivotFactory.eINSTANCE.createPackage();
requesterPackage.setName("requesterPackage");
...


I think to create the Packages programmatically is no good idea respectively its hopefully unnecessary:

How can I load an Ecore model to create a Pivot model instance that contains the types from the ecore model?

Re: Generate qvtr file programmatically [message #1071219 is a reply to message #1071180] Fri, 19 July 2013 15:20 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
Registered: July 2009
Senior Member
Hi

org.eclipse.ocl.examples.pivot.ecore.Ecore2Pivot does the work.

org.eclipse.ocl.examples.pivot.manager.MetaModelmanager.loadResource
generally supports loading and loader discovery.

Search the references, for examples of usage.

Regards

Ed Willink


On 19/07/2013 15:04, Goood Guy wrote:
> ok, my plan now is to create the QVTrelation programmatically and
> create the qvtr file via an xtend transformation (my transformations
> are very basic, so I do not need to cover complete QVT/OCL):
>
>
> root = QVTrelationFactory.eINSTANCE.createRelationModel();
> transformation =
> QVTrelationFactory.eINSTANCE.createRelationalTransformation();
> root.getNestedPackage().add(transformation);
>
> providerPackage = PivotFactory.eINSTANCE.createPackage();
> providerPackage.setName("providerPackage");
>
> requesterPackage = PivotFactory.eINSTANCE.createPackage();
> requesterPackage.setName("requesterPackage");
> ...
>
>
> I think to create the Packages programmatically is no good idea
> respectively its hopefully unnecessary:
> How can I load an Ecore model to create a Pivot model instance that
> contains the types from the ecore model?
>
>
Re: Generate qvtr file programmatically [message #1078053 is a reply to message #1071219] Fri, 02 August 2013 13:28 Go to previous messageGo to next message
Simon Schwichtenberg is currently offline Simon SchwichtenbergFriend
Messages: 127
Registered: September 2011
Senior Member
I wonder if there is an easier way to navigate from an EObject to the corresponding Pivot object.

At the moment I am using this code, but I hope that I can randomly access a corresponding Pivot object. But how can I do it?

private org.eclipse.ocl.examples.pivot.Type getType(org.eclipse.ocl.examples.pivot.Package p, EObject e){
		
		for(org.eclipse.ocl.examples.pivot.Type t:p.getOwnedType()){
			
			URI uriFromEcore = EcoreUtil.getURI(e);
			URI uriFromPivot = EcoreUtil.getURI(t.getETarget());
			if(uriFromEcore.equals(uriFromPivot)){
				return t;
			}
		}
		return null;
		
	}
Re: Generate qvtr file programmatically [message #1078163 is a reply to message #1078053] Fri, 02 August 2013 16:14 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
Registered: July 2009
Senior Member
Hi

MetaModelManager.getPivotOf() will cope with UML or Ecore or ... as the
source

MetaModelManager.getPivotOfEcore() is only Ecore.

Regards

Ed Willink

On 02/08/2013 14:28, Goood Guy wrote:
> I wonder if there is an easier way to navigate from an EObject to the
> corresponding Pivot object.
>
> At the moment I am using this code, but I hope that I can randomly
> access a corresponding Pivot object. But how can I do it?
>
>
> private org.eclipse.ocl.examples.pivot.Type
> getType(org.eclipse.ocl.examples.pivot.Package p, EObject e){
>
> for(org.eclipse.ocl.examples.pivot.Type t:p.getOwnedType()){
>
> URI uriFromEcore = EcoreUtil.getURI(e);
> URI uriFromPivot = EcoreUtil.getURI(t.getETarget());
> if(uriFromEcore.equals(uriFromPivot)){
> return t;
> }
> }
> return null;
>
> }
>
Re: Generate qvtr file programmatically [message #1110210 is a reply to message #1078163] Mon, 16 September 2013 14:45 Go to previous messageGo to next message
Simon Schwichtenberg is currently offline Simon SchwichtenbergFriend
Messages: 127
Registered: September 2011
Senior Member
Hi,

when I run my application as standalone outside of Eclipse, the following code causes an error:

requesterPackage = (Package) Ecore2Pivot.importFromEcore(requesterMMManager, "", requester);


Quote:
Exception in thread "main" org.eclipse.ocl.examples.pivot.utilities.IllegalLibraryException: No OCL Standard Library content available
at org.eclipse.ocl.examples.pivot.manager.PivotStandardLibrary.getRequiredLibraryType(PivotStandardLibrary.java:278)
at org.eclipse.ocl.examples.pivot.manager.PivotStandardLibrary.resolveRequiredSimpleType(PivotStandardLibrary.java:377)
at org.eclipse.ocl.examples.pivot.manager.PivotStandardLibrary.getBooleanType(PivotStandardLibrary.java:127)
at org.eclipse.ocl.examples.pivot.ecore.Ecore2Pivot.initializeEcore2PivotMap(Ecore2Pivot.java:482)
at org.eclipse.ocl.examples.pivot.ecore.Ecore2Pivot.getEcore2PivotMap(Ecore2Pivot.java:326)
at org.eclipse.ocl.examples.pivot.ecore.Ecore2Pivot.resolveDataType(Ecore2Pivot.java:615)
at org.eclipse.ocl.examples.pivot.ecore.Ecore2Pivot.resolveType(Ecore2Pivot.java:670)
at org.eclipse.ocl.examples.pivot.ecore.Ecore2Pivot.update(Ecore2Pivot.java:752)
at org.eclipse.ocl.examples.pivot.ecore.Ecore2Pivot.importObjects(Ecore2Pivot.java:467)
at org.eclipse.ocl.examples.pivot.ecore.Ecore2Pivot.getPivotRoot(Ecore2Pivot.java:412)
at org.eclipse.ocl.examples.pivot.ecore.Ecore2Pivot.importFromEcore(Ecore2Pivot.java:208)


I think I have to register something what is usually done by the Eclipse platform.
So what do I have to do to run the Ecore2Pivot in standalone mode?
Re: Generate qvtr file programmatically [message #1110219 is a reply to message #1110210] Mon, 16 September 2013 14:59 Go to previous messageGo to next message
Simon Schwichtenberg is currently offline Simon SchwichtenbergFriend
Messages: 127
Registered: September 2011
Senior Member
Sorry, I should read http://help.eclipse.org/kepler/index.jsp?topic=%2Forg.eclipse.ocl.doc%2Fhelp%2FPivotStandalone.html first
Re: Generate qvtr file programmatically [message #1110495 is a reply to message #1110219] Tue, 17 September 2013 00:32 Go to previous messageGo to next message
Simon Schwichtenberg is currently offline Simon SchwichtenbergFriend
Messages: 127
Registered: September 2011
Senior Member
Ok, now I execute the following code:
		    org.eclipse.ocl.examples.pivot.OCL.initialize(resourceSet);
		    org.eclipse.ocl.examples.pivot.model.OCLstdlib.install();
		    org.eclipse.ocl.examples.pivot.delegate.OCLDelegateDomain.initialize(resourceSet);


In general, this works when I execute my program as standalone.

However, I want to execute my program in terms of a 3rd party evaluation tool. The tool loads the jar files of my program dynamically. But then, I got this strange error:

Exception in thread "main" java.lang.ExceptionInInitializerError
at org.eclipse.ocl.common.internal.options.CommonOptions.<clinit>(CommonOptions.java:25)
at org.eclipse.ocl.examples.pivot.delegate.OCLDelegateDomain.initialize(OCLDelegateDomain.java:80)
at org.eclipse.ocl.examples.pivot.delegate.OCLDelegateDomain.initialize(OCLDelegateDomain.java:63)
at de.upb.swt.rsdl.data.matcher.evaluation.Owl2Ecore.setup(Owl2Ecore.java:129)
at de.upb.swt.rsdl.data.matcher.evaluation.Owl2Ecore.<init>(Owl2Ecore.java:65)
at de.upb.swt.rsdl.data.matcher.evaluation.Bridge.align(Bridge.java:101)
at eu.sealsproject.omt.client.Client.match(Client.java:318)
at eu.sealsproject.omt.client.Client.<init>(Client.java:244)
at eu.sealsproject.omt.client.Client.main(Client.java:117)
Caused by: java.lang.NullPointerException
at org.eclipse.ocl.common.OCLConstants.<clinit>(OCLConstants.java:22)
... 9 more

See http://git.eclipse.org/c/mdt/org.eclipse.ocl.git/tree/plugins/org.eclipse.ocl.common/src/org/eclipse/ocl/common/internal/options/CommonOptions.java and http://git.eclipse.org/c/mdt/org.eclipse.ocl.git/tree/plugins/org.eclipse.ocl.common/src/org/eclipse/ocl/common/OCLConstants.java.

So, OCLConstants.class.getPackage() returns null. I've exported my plugin as a runnable jar file to include all dependencies. Maybe the problem arises from a repackaging. On the other hand maybe the dependencies cannot be loaded by the evaluation tool. Does anyone have an idea what is going wrong?
Or the
Re: Generate qvtr file programmatically [message #1110652 is a reply to message #1110495] Tue, 17 September 2013 06:32 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
Registered: July 2009
Senior Member
Hi

<clinit> is often a bad class initialization.

I'm a bit confused that

public interface OCLConstants
{
public static final String PLUGIN_ID =
OCLConstants.class.getPackage().getName();

can go wrong. I can only suggest that you help the Java init out by invoking

OCLConstants.class.getName() yourself before referencing any of its content.

Regards

Ed Willink


On 17/09/2013 01:32, Goood Guy wrote:
> Ok, now I execute the following code:
>
> org.eclipse.ocl.examples.pivot.OCL.initialize(resourceSet);
> org.eclipse.ocl.examples.pivot.model.OCLstdlib.install();
> org.eclipse.ocl.examples.pivot.delegate.OCLDelegateDomain.initialize(resourceSet);
>
>
> In general, this works when I execute my program as standalone.
>
> However, I want to execute my program in terms of a 3rd party
> evaluation tool. The tool loads the jar files of my program
> dynamically. But then, I got this strange error:
>
> Exception in thread "main" java.lang.ExceptionInInitializerError
> at
> org.eclipse.ocl.common.internal.options.CommonOptions.<clinit>(CommonOptions.java:25)
> at
> org.eclipse.ocl.examples.pivot.delegate.OCLDelegateDomain.initialize(OCLDelegateDomain.java:80)
> at
> org.eclipse.ocl.examples.pivot.delegate.OCLDelegateDomain.initialize(OCLDelegateDomain.java:63)
> at
> de.upb.swt.rsdl.data.matcher.evaluation.Owl2Ecore.setup(Owl2Ecore.java:129)
> at
> de.upb.swt.rsdl.data.matcher.evaluation.Owl2Ecore.<init>(Owl2Ecore.java:65)
> at
> de.upb.swt.rsdl.data.matcher.evaluation.Bridge.align(Bridge.java:101)
> at eu.sealsproject.omt.client.Client.match(Client.java:318)
> at eu.sealsproject.omt.client.Client.<init>(Client.java:244)
> at eu.sealsproject.omt.client.Client.main(Client.java:117)
> Caused by: java.lang.NullPointerException
> at
> org.eclipse.ocl.common.OCLConstants.<clinit>(OCLConstants.java:22)
> ... 9 more
>
> See
> http://git.eclipse.org/c/mdt/org.eclipse.ocl.git/tree/plugins/org.eclipse.ocl.common/src/org/eclipse/ocl/common/internal/options/CommonOptions.java
> and
> http://git.eclipse.org/c/mdt/org.eclipse.ocl.git/tree/plugins/org.eclipse.ocl.common/src/org/eclipse/ocl/common/OCLConstants.java.
>
> So, OCLConstants.class.getPackage() returns null. I've exported my
> plugin as a runnable jar file to include all dependencies. Maybe the
> problem arises from a repackaging. On the other hand maybe the
> dependencies cannot be loaded by the evaluation tool. Does anyone have
> an idea what is going wrong?
> Or the
Re: Generate qvtr file programmatically [message #1854019 is a reply to message #1110652] Thu, 28 July 2022 08:41 Go to previous message
pere joseph rodríguez is currently offline pere joseph rodríguezFriend
Messages: 51
Registered: October 2014
Member
JFYI I tried years ago and had the same issues with all the OCL pivots and stuff

The goal was to generate a qvtr to copy models elements in a model (It is not easy with QVTR or at least it was not years ago), based on the publication https://github.com/perelengo/qvtr-copy-paterns/blob/master/Refinement_Transformation_Support_for_QVT_Relational_Transformations.pdf
, so in the end i resolved by generating an QVT AST with XSL. And then print the AST to QVTR with a XSL printer:
https://github.com/perelengo/qvtr-copy-paterns/blob/master/ecore_metamodel_to_copy_qvtr.qvtr -> This takes the ecore schema and generates the QVTR AST
https://github.com/perelengo/qvtr-copy-paterns/blob/master/qvt-pretty-printer.xsl -> this gets the AST and prints the QVTR

Maybe helps having a side solution.
Previous Topic:Developing plugins that use qvt-r
Next Topic:Drops and Updates are now Builds
Goto Forum:
  


Current Time: Fri Apr 19 07:01:58 GMT 2024

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

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

Back to the top