Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » QVT-OML » Resolve EValues from a qvtotrace file
Resolve EValues from a qvtotrace file [message #940519] Thu, 11 October 2012 18:12 Go to next message
Simon Schwichtenberg is currently offline Simon SchwichtenbergFriend
Messages: 127
Registered: September 2011
Senior Member
Hi,
I would like to deserialize an QVTo file and access the source and the target model elements from the mappings. This is the code I've got so far:

URI uriTrace = URI.createURI("testModel/testmodel.qvtotrace");
ResourceSet resourcesSet = new ResourceSetImpl();		
Resource resource = resourcesSet.getResource(tracefileURI, true);
trace = (Trace) resource.getContents().get(0);

for(TraceRecord record : trace.getTraceRecords()){
 EMappingOperation mappingOperation = record.getMappingOperation();			
 EObject contextElement =null;
 EObject resultElement =null;
 try {
  contextElement = record.getContext().getContext().getValue().getModelElement();
				
  resultElement = record.getResult().getResult().get(0).getValue().getModelElement();


 } catch (NullPointerException e) {
  //do nothing, skip record
 }


But contextElement and resultElement always contains a EObjectImpl-Object with an eProxyURI that points to the element from the source/target model.

How can I resolve the proxy? I am not sure if this is an EMF related issue or QVTo specific.
Re: Resolve EValues from a qvtotrace file [message #940537 is a reply to message #940519] Thu, 11 October 2012 18:38 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7675
Registered: July 2009
Senior Member
Hi

EMF will generally resolve proxies when you reference them.

This is a lazy activity, so you can see unresolved proxies in the debugger.

You can use EcoreUtil.resolveAll() to force eager resolution.

If the proxies remain, you generally have a package registration problem
preventing loading of your models.

Regards

Ed Willink

On 11/10/2012 19:12, Goood Guy wrote:
> Hi,
> I would like to deserialize an QVTo file and access the source and the
> target model elements from the mappings. This is the code I've got so
> far:
>
>
> URI uriTrace = URI.createURI("testModel/testmodel.qvtotrace");
> ResourceSet resourcesSet = new ResourceSetImpl();
> Resource resource = resourcesSet.getResource(tracefileURI, true);
> trace = (Trace) resource.getContents().get(0);
>
> for(TraceRecord record : trace.getTraceRecords()){
> EMappingOperation mappingOperation = record.getMappingOperation();
> EObject contextElement =null;
> EObject resultElement =null;
> try {
> contextElement =
> record.getContext().getContext().getValue().getModelElement();
>
> resultElement =
> record.getResult().getResult().get(0).getValue().getModelElement();
>
>
> } catch (NullPointerException e) {
> //do nothing, skip record
> }
>
>
> But contextElement and resultElement always contains a
> EObjectImpl-Object with an eProxyURI that points to the element from
> the source/target model.
>
> How can I resolve the proxy? I am not sure if this is an EMF related
> issue or QVTo specific.
Re: Resolve EValues from a qvtotrace file [message #940548 is a reply to message #940537] Thu, 11 October 2012 18:54 Go to previous messageGo to next message
Simon Schwichtenberg is currently offline Simon SchwichtenbergFriend
Messages: 127
Registered: September 2011
Senior Member
Quote:
You can use EcoreUtil.resolveAll() to force eager resolution.
was not successful.

Quote:
If the proxies remain, you generally have a package registration problem
preventing loading of your models.
what does that mean exactly?

One more note: I cannot image why the following fact should be important, but I execute the code from a JUnit Plug-in test.
Re: Resolve EValues from a qvtotrace file [message #940978 is a reply to message #940537] Fri, 12 October 2012 05:37 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33224
Registered: July 2009
Senior Member
Comments below.

On 11/10/2012 8:38 PM, Ed Willink wrote:
> Hi
>
> EMF will generally resolve proxies when you reference them.
>
> This is a lazy activity, so you can see unresolved proxies in the
> debugger.
>
> You can use EcoreUtil.resolveAll() to force eager resolution.
If that still doesn't work, it's good to use the debugger to examine the
resource set's resource to see which set of URIs have been loaded and
looking in the contents of each of those to see if they have contents.
If one or more don't, you can look in ResourceImpl.errors to see why the
resource failed to load.
>
> If the proxies remain, you generally have a package registration
> problem preventing loading of your models.
Well, unresolved proxies are generally caused by failure to load the
referenced resource; that may be caused by the absence of a model by
which to interpret the contents of a resource, but that's not the only
reason.
>
> Regards
>
> Ed Willink
>
> On 11/10/2012 19:12, Goood Guy wrote:
>> Hi,
>> I would like to deserialize an QVTo file and access the source and
>> the target model elements from the mappings. This is the code I've
>> got so far:
>>
>>
>> URI uriTrace = URI.createURI("testModel/testmodel.qvtotrace");
This looks like asking for trouble. If the resource contains any
relative URIs, they're not going to be resolved (URI.resolve) because
this URI is not absolute (URI.isAbsolute).

Change this to be an absolute URI. I.e.,
platform:/resource/<project>/<path-to-IFile> or file:/<path-to-io.java.File.
>> ResourceSet resourcesSet = new ResourceSetImpl();
>> Resource resource = resourcesSet.getResource(tracefileURI, true);
>> trace = (Trace) resource.getContents().get(0);
>>
>> for(TraceRecord record : trace.getTraceRecords()){
>> EMappingOperation mappingOperation = record.getMappingOperation();
>> EObject contextElement =null;
>> EObject resultElement =null;
>> try {
>> contextElement =
>> record.getContext().getContext().getValue().getModelElement();
>>
>> resultElement =
>> record.getResult().getResult().get(0).getValue().getModelElement();
>>
>>
>> } catch (NullPointerException e) {
>> //do nothing, skip record
>> }
>>
>>
>> But contextElement and resultElement always contains a
>> EObjectImpl-Object with an eProxyURI that points to the element from
>> the source/target model.
>>
>> How can I resolve the proxy? I am not sure if this is an EMF related
>> issue or QVTo specific.
>


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Resolve EValues from a qvtotrace file [message #941008 is a reply to message #940548] Fri, 12 October 2012 06:20 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7675
Registered: July 2009
Senior Member
Hi

Executing from a JUnit non-Plugin test would require you to emulate
Eclipse startup registrations.

From a JUnit Plugin test you should find Eclipse startup registrations
happen automatically.

See Ed Merks' observation on your unwise file-paths.

Regards

Ed Willink


On 11/10/2012 19:54, Goood Guy wrote:
> Quote:
>> You can use EcoreUtil.resolveAll() to force eager resolution.
> was not successful.
>
> Quote:
>> If the proxies remain, you generally have a package registration problem
>> preventing loading of your models.
> what does that mean exactly?
> One more note: I cannot image why the following fact should be
> important, but I execute the code from a JUnit Plug-in test.
>
Re: Resolve EValues from a qvtotrace file [message #941709 is a reply to message #941008] Fri, 12 October 2012 19:40 Go to previous messageGo to next message
Simon Schwichtenberg is currently offline Simon SchwichtenbergFriend
Messages: 127
Registered: September 2011
Senior Member
platform:/resources/<plugin>/testModel/testmodel.qvtotrace does not work at all and with platform:/plugin/<plugin>/testModel/testmodel.qvtotrace I have still proxies.

That is the code I am using:
URI tracefileURI= URI.createURI("platform:/plugin/de.upb.swt.pgsafebots3.requirements.msd.sysml2ecore/testModel/testmodel.qvtotrace");
ResourceSet resourcesSet = new ResourceSetImpl();
Resource resource = resourcesSet.getResource(tracefileURI, true);
boolean isabolute = tracefileURI.hasAbsolutePath(); //true
boolean isabsolute2 = !tracefileURI.isRelative(); //true

try {
 resource.load(Collections.EMPTY_MAP);
	
} catch (IOException e1) {
// TODO Auto-generated catch block
 e1.printStackTrace();
}


contents of ResourceSet.resources (the uml file is the source model of the transformation and ecore is the target model):

org.eclipse.emf.ecore.xmi.impl.XMIResourceImpl@ffa991 uri='platform:/plugin/de.upb.swt.pgsafebots3.requirements.msd.sysml2ecore/testModel/testmodel.qvtotrace' (loaded)

org.eclipse.m2m.internal.qvt.oml.compiler.ExeXMIResource@f7016f uri='platform:/resource/de.upb.swt.pgsafebots3.requirements.msd.sysml2ecore/transforms/SysML2EcoreTransformation.qvtox' (not loaded)
Error: [org.eclipse.emf.ecore.resource.impl.ResourceSetImpl$1DiagnosticWrappedException: org.eclipse.core.internal.resources.ResourceException: Resource '/de.upb.swt.pgsafebots3.requirements.msd.sysml2ecore/transforms/SysML2EcoreTransformation.qvtox' does not exist.]

org.eclipse.uml2.uml.internal.resource.UMLResourceImpl@1497091 uri='platform:/resource/de.upb.swt.pgsafebots3.requirements.msd.sysml2ecore/testModel/testmodel.uml' (not loaded)
Error: [org.eclipse.emf.ecore.resource.impl.ResourceSetImpl$1DiagnosticWrappedException: org.eclipse.core.internal.resources.ResourceException: Resource '/de.upb.swt.pgsafebots3.requirements.msd.sysml2ecore/testModel/testmodel.uml' does not exist.]

org.eclipse.emf.ecore.xmi.impl.EcoreResourceFactoryImpl$1@c91f66 uri='platform:/resource/de.upb.swt.pgsafebots3.requirements.msd.sysml2ecore/testModel/testmodel.ecore' (not loaded)
Error:
[org.eclipse.emf.ecore.resource.impl.ResourceSetImpl$1DiagnosticWrappedException: org.eclipse.core.internal.resources.ResourceException: Resource '/de.upb.swt.pgsafebots3.requirements.msd.sysml2ecore/testModel/testmodel.ecore' does not exist.]

When I load the files for their own, they can be loaded.
What is this qvtox file?
Re: Resolve EValues from a qvtotrace file [message #942146 is a reply to message #941709] Sat, 13 October 2012 07:10 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7675
Registered: July 2009
Senior Member
Hi

You have not posted a reproducible example so I cannot really tell what
your problem is.

testmodel.qvtotrace seems to be loading which suggests you must have a
*.qvtotrace registration even though you haven't shown it; this suggests
you might be running as a plugin.

Ecore file loading seems to fail which seems to suggest you are not
running as a plugin.

So your report is contradictory to me. If you want help provide
something that allows me to help you; a zipped project with a launch
configuration.

*.qvtox is the compiled QVTo AST which is not persisted outside the QVTo
tooling.

Regards

Ed Willink




On 12/10/2012 20:40, Goood Guy wrote:
> platform:/resources/<plugin>/testModel/testmodel.qvtotrace does not
> work at all and with
> platform:/plugin/<plugin>/testModel/testmodel.qvtotrace I have still
> proxies.
>
> That is the code I am using:
>
> URI tracefileURI=
> URI.createURI("platform:/plugin/de.upb.swt.pgsafebots3.requirements.msd.sysml2ecore/testModel/testmodel.qvtotrace");
> ResourceSet resourcesSet = new ResourceSetImpl();
> Resource resource = resourcesSet.getResource(tracefileURI, true);
> boolean isabolute = tracefileURI.hasAbsolutePath(); //true
> boolean isabsolute2 = !tracefileURI.isRelative(); //true
>
> try {
> resource.load(Collections.EMPTY_MAP);
>
> } catch (IOException e1) {
> // TODO Auto-generated catch block
> e1.printStackTrace();
> }
>
>
> contents of ResourceSet.resources (the uml file is the source model of
> the transformation and ecore is the target model):
>
> mailto:org.eclipse.emf.ecore.xmi.impl.XMIResourceImpl@ffa991
> uri='platform:/plugin/de.upb.swt.pgsafebots3.requirements.msd.sysml2ecore/testModel/testmodel.qvtotrace'
> (loaded)
>
> mailto:org.eclipse.m2m.internal.qvt.oml.compiler.ExeXMIResource@f7016f
> uri='platform:/resource/de.upb.swt.pgsafebots3.requirements.msd.sysml2ecore/transforms/SysML2EcoreTransformation.qvtox'
> (not loaded)
> Error:
> [org.eclipse.emf.ecore.resource.impl.ResourceSetImpl$1DiagnosticWrappedException:
> org.eclipse.core.internal.resources.ResourceException: Resource
> '/de.upb.swt.pgsafebots3.requirements.msd.sysml2ecore/transforms/SysML2EcoreTransformation.qvtox'
> does not exist.]
>
> mailto:org.eclipse.uml2.uml.internal.resource.UMLResourceImpl@1497091
> uri='platform:/resource/de.upb.swt.pgsafebots3.requirements.msd.sysml2ecore/testModel/testmodel.uml'
> (not loaded)
> Error:
> [org.eclipse.emf.ecore.resource.impl.ResourceSetImpl$1DiagnosticWrappedException:
> org.eclipse.core.internal.resources.ResourceException: Resource
> '/de.upb.swt.pgsafebots3.requirements.msd.sysml2ecore/testModel/testmodel.uml'
> does not exist.]
>
> org.eclipse.emf.ecore.xmi.impl.EcoreResourceFactoryImpl$1@c91f66
> uri='platform:/resource/de.upb.swt.pgsafebots3.requirements.msd.sysml2ecore/testModel/testmodel.ecore'
> (not loaded)
> Error:
> [org.eclipse.emf.ecore.resource.impl.ResourceSetImpl$1DiagnosticWrappedException:
> org.eclipse.core.internal.resources.ResourceException: Resource
> '/de.upb.swt.pgsafebots3.requirements.msd.sysml2ecore/testModel/testmodel.ecore'
> does not exist.]
>
> When I load the files for their own, they can be loaded.
> What is this qvtox file?
Re: Resolve EValues from a qvtotrace file [message #942332 is a reply to message #942146] Sat, 13 October 2012 12:05 Go to previous messageGo to next message
Simon Schwichtenberg is currently offline Simon SchwichtenbergFriend
Messages: 127
Registered: September 2011
Senior Member
Plugin and launch configuration included: http://www.mediafire.com/?3zfctbtbyxw3mgr
The ecore and qvtotrace file were created using the qvto interpreter (do not consider TransformationExecutor.java or SysML2EcoreTransformationTest.java)

Take a look into SysML2EcoreTraceReader and SysML2EcoreTraceReaderTest

thanks for help!

[Updated on: Sat, 13 October 2012 12:11]

Report message to a moderator

Re: Resolve EValues from a qvtotrace file [message #942585 is a reply to message #942332] Sat, 13 October 2012 17:16 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7675
Registered: July 2009
Senior Member
Hi

Your code nominally fails with a CCE, which is because the unresolved
proxy cannot be cast as required. The resource targeted by the
unresolved proxy has a Resource.errors that contains an entry indicating
that testmodel.uml does not exist on a path that clearly does.

You are falling foul of one of my least favourite EMF features.
(https://bugs.eclipse.org/bugs/show_bug.cgi?id=219742).

The *.qvtotrace file was created in an Eclipse session in which your
models were in a project and so are referenced as platform:/resource/....

Subsequently your reader runs when your files are in plugins and so
could be accessed as platform:/plugin/...

EMF provides an ability to cross-resolve platform:/resource and
platform/plugin by invoking

resourceSet.getURIConverter().getURIMap().putAll(EcorePlugin.computePlatformURIMap());

Unfortunately EMF was designed for modellers who use Java and so have a
genmodel registration. Lightweight model-only modeling is not properly
supported and so since you have no genmodel registration you get no
cross-mapping.

In response to many related problems, I raised
https://bugs.eclipse.org/bugs/show_bug.cgi?id=361063. If you add

import org.eclipse.ocl.examples.domain.utilities.ProjectMap;
.....
ProjectMap projectMap = new ProjectMap();
projectMap.initializeResourceSet(resourcesSet);

you will get a complete (and costly) set of cross-resolution mappings.
(Cache the ProjectMap as a static if you need it again.)

The *.qvtox does not exist, so references will remain proxies. If you
need them, you should write code to at least extract the class name from
the proxy URI. [A patch may be submitted soon that makes the *.qvtox
accessible.]

With the ProjectMap, your code gives NPEs from the uninitialized maps.

Regards

Ed Willink

On 13/10/2012 13:05, Goood Guy wrote:
> Plugin and launch configuration included:
> http://www.mediafire.com/?3zfctbtbyxw3mgr
> The ecore and qvtotrace file were created using the qvto interpreter
> (do not consider TransformationExecutor.java or
> SysML2EcoreTransformationTest.java)
Re: Resolve EValues from a qvtotrace file [message #943127 is a reply to message #942585] Sun, 14 October 2012 07:01 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7675
Registered: July 2009
Senior Member
Hi

Of course, if you don't want the OCL dependency you can add the
uri-mapping manually that ProjectMap does automatically.

Regards

Ed Willink.

On 13/10/2012 18:16, Ed Willink wrote:
> Hi
>
> Your code nominally fails with a CCE, which is because the unresolved
> proxy cannot be cast as required. The resource targeted by the
> unresolved proxy has a Resource.errors that contains an entry
> indicating that testmodel.uml does not exist on a path that clearly does.
>
> You are falling foul of one of my least favourite EMF features.
> (https://bugs.eclipse.org/bugs/show_bug.cgi?id=219742).
>
> The *.qvtotrace file was created in an Eclipse session in which your
> models were in a project and so are referenced as platform:/resource/....
>
> Subsequently your reader runs when your files are in plugins and so
> could be accessed as platform:/plugin/...
>
> EMF provides an ability to cross-resolve platform:/resource and
> platform/plugin by invoking
>
> resourceSet.getURIConverter().getURIMap().putAll(EcorePlugin.computePlatformURIMap());
>
>
> Unfortunately EMF was designed for modellers who use Java and so have
> a genmodel registration. Lightweight model-only modeling is not
> properly supported and so since you have no genmodel registration you
> get no cross-mapping.
>
> In response to many related problems, I raised
> https://bugs.eclipse.org/bugs/show_bug.cgi?id=361063. If you add
>
> import org.eclipse.ocl.examples.domain.utilities.ProjectMap;
> .....
> ProjectMap projectMap = new ProjectMap();
> projectMap.initializeResourceSet(resourcesSet);
>
> you will get a complete (and costly) set of cross-resolution mappings.
> (Cache the ProjectMap as a static if you need it again.)
>
> The *.qvtox does not exist, so references will remain proxies. If you
> need them, you should write code to at least extract the class name
> from the proxy URI. [A patch may be submitted soon that makes the
> *.qvtox accessible.]
>
> With the ProjectMap, your code gives NPEs from the uninitialized maps.
>
> Regards
>
> Ed Willink
>
> On 13/10/2012 13:05, Goood Guy wrote:
>> Plugin and launch configuration included:
>> http://www.mediafire.com/?3zfctbtbyxw3mgr
>> The ecore and qvtotrace file were created using the qvto interpreter
>> (do not consider TransformationExecutor.java or
>> SysML2EcoreTransformationTest.java)
>
Re: Resolve EValues from a qvtotrace file [message #943590 is a reply to message #940519] Sun, 14 October 2012 17:01 Go to previous message
Simon Schwichtenberg is currently offline Simon SchwichtenbergFriend
Messages: 127
Registered: September 2011
Senior Member
Now, the proxies can be resolved. Thanks!
Previous Topic:[Announce] Eclipse QVT Operational 3.2.1 (Juno SR1) is now available
Next Topic:Possibility to generate Circular Referenced target model
Goto Forum:
  


Current Time: Sun Oct 06 13:44:55 GMT 2024

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

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

Back to the top