| 
| Generate qvtr file programmatically [message #1069206] | Mon, 15 July 2013 08:15  |  | 
| Eclipse User  |  |  |  |  | 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 09:04   |  | 
| Eclipse User  |  |  |  |  | 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
 >
 >
 >
 |  |  |  | 
|  | 
|  | 
|  | 
|  | 
|  | 
|  | 
|  | 
|  | 
|  | 
|  | 
|  | 
Powered by 
FUDForum. Page generated in 0.05751 seconds