| Generate qvtr file programmatically [message #1069206] |
Mon, 15 July 2013 08:15  |
Goood Guy Messages: 122 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 09:04   |
Ed Willink Messages: 3446 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 #1110652 is a reply to message #1110495] |
Tue, 17 September 2013 02:32  |
Ed Willink Messages: 3446 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
|
|
|
Powered by
FUDForum. Page generated in 0.02140 seconds