Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » Manual invocation of proxy resolution required?
Manual invocation of proxy resolution required? [message #1738846] Mon, 25 July 2016 12:31 Go to next message
HN Hindriks is currently offline HN HindriksFriend
Messages: 6
Registered: July 2016
Junior Member
Hello,

I have defined two models, PVA and PVAI.
Instances of the PVAI model can contain references to instances from the PVA model.

I am using the EMF generated Java classes, and have successfully serialized and deserialized my PVA model to and from XMI. It loads fine in the Eclipse dynamic instance viewer.

I also managed to serialize my PVAI instances, including their references to the PVA model. However, I am unable to correctly deserialize it. The referenced objects are instantiated as proxy objects with all fields 'null'.
The PVAI instance will also not correctly load in Eclipse, with the referenced fields being left blank.

The strange thing is, using a combination of the UnresolvedProxyCrossReferencer and EcoreUtil.resolve, I am able to replace the proxy objects by the concrete instances from the PVA instance.

Why is the XMI loader unable to automatically resolve my proxies? It seems to be able to find (and create) the resource of the corresponding PVA instance.

This is my current code (written in Kotlin, which compiles to JVM bytecode. If it is too confusing, if this is a problem, I will rewrite it to Java when asked):
fun loadPVAIfromXMI(location : File): PVAIContainer {
    println("Starting reading .pvai file")
    val outURI = URI.createFileURI(location.absolutePath)
    val resourceSet = ResourceSetImpl()

    val resource =  resourceSet.getResource(outURI,true)
    resource.load(null)

    //This doesn't do anything
    //EcoreUtil.resolveAll(resourceSet)

    //Fixes unresolved proxies by resolving them (somehow has to be done manually)
    EcoreUtil.UnresolvedProxyCrossReferencer.find(resource).forEach { unresolvedProxy ->
        unresolvedProxy.value.single().set(
                EcoreUtil.resolve(unresolvedProxy.key,resourceSet)
        )
    }

    val result = resource.contents.first() as PVAIContainer

    println("Finished reading .pvai file")
    return result
}
Re: Manual invocation of proxy resolution required? [message #1738878 is a reply to message #1738846] Mon, 25 July 2016 16:37 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 31910
Registered: July 2009
Senior Member
Comments below.


On 25.07.2016 18:15, HN Hindriks wrote:
> Hello,
>
> I have defined two models, PVA and PVAI.
> Instances of the PVAI model can contain references to instances from
> the PVA model.
>
> I am using the EMF generated Java classes, and have successfully
> serialized and deserialized my PVA model to and from XMI. It loads
> fine in the Eclipse dynamic instance viewer.
>
> I also managed to serialize my PVAI instances, including their
> references to the PVA model. However, I am unable to correctly
> deserialize it. The referenced objects are instantiated as proxy
> objects with all fields 'null'.
> The PVAI instance will also not correctly load in Eclipse, with the
> referenced fields being left blank.
Yes, sounds like an unresolved proxy. What is the eProxyURI of that object?
>
> The strange thing is, using a combination of the
> UnresolvedProxyCrossReferencer and EcoreUtil.resolve, I am able to
> replace the proxy objects by the concrete instances from the PVA
> instance.
That shouldn't be necessary.
>
> Why is the XMI loader unable to automatically resolve my proxies?
Proxies aren't resolving during loading. They're created and later
resolved upon first access.
> It seems to be able to find (and create) the resource of the
> corresponding PVA instance.
>
> This is my current code (written in Kotlin, which compiles to JVM
> bytecode. If it is too confusing, if this is a problem, I will rewrite
> it to Java when asked):
>
> fun loadPVAIfromXMI(location : File): PVAIContainer {
> println("Starting reading .pvai file")
> val outURI = URI.createFileURI(location.absolutePath)
> val resourceSet = ResourceSetImpl()
>
> val resource = resourceSet.getResource(outURI,true)
> resource.load(null)
The load call is redundant. The resource is already loaded at this point.
>
> //This doesn't do anything
> //EcoreUtil.resolveAll(resourceSet)
>
> //Fixes unresolved proxies by resolving them (somehow has to be
> done manually)
> EcoreUtil.UnresolvedProxyCrossReferencer.find(resource).forEach {
> unresolvedProxy ->
> unresolvedProxy.value.single().set(
> EcoreUtil.resolve(unresolvedProxy.key,resourceSet)
What is the "key"?
> )
> }
>
> val result = resource.contents.first() as PVAIContainer
>
> println("Finished reading .pvai file")
> return result
> }
>


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Manual invocation of proxy resolution required? [message #1738924 is a reply to message #1738878] Tue, 26 July 2016 07:46 Go to previous message
HN Hindriks is currently offline HN HindriksFriend
Messages: 6
Registered: July 2016
Junior Member
Hi Ed,
Again, thank you for your reply!

I agree that manually replacing the objects shouldn't be necessary.
Actually, I also implemented the same loading operation using Eclipse Epsilon (using the EmfModel class), which correctly resolves the references in the PVAI model.
However, I also require that Eclipse is able to correctly load my .pvai files.

Before mentioning all kinds of URIs, it might be worthwhile to mention that I have my models at the following locations on my drive:
C:/.../<working_dir>/CalculationTest_1.pva
C:/.../<working_dir>/CalculationTest_1.pvai

The URI of the PVAI model resource is
file:/C:/.../<working_dir>/CalculationTest_1.pvai


The eProxyURI of the object in the PVAI model with the 'null' fields is as follows:
file:/C:/.../<working_dir>/CalculationTest_1.pva#6325842526577706469


Where the number is an existing ID in the PVA instance.
<templateTypes ... UUID="6325842526577706469" ...>



The proxies show up with 'null' fields in my debugger. I also tried printing the contents (and accessing the fields through the respective getX() methods), but this yielded the same result.


On to the code comments:
Quote:
The load call is redundant. The resource is already loaded at this point.

Thank you for pointing this out, I interpreted the getResource() method as being lazy-loaded, and tried to force loading through this instruction.

Quote:

> //Fixes unresolved proxies by resolving them (somehow has to be
> done manually)
> EcoreUtil.UnresolvedProxyCrossReferencer.find(resource).forEach {
> unresolvedProxy ->
> unresolvedProxy.value.single().set(
> EcoreUtil.resolve(unresolvedProxy.key,resourceSet)
What is the "key"?
> )
> }

The UnresolvedProxyCrossReferencer returns a map of pairs (a,b) where a is an unresolved proxy, and b the object containing the proxy.

In this specific case the resulting map consists of 10 elements, all being references to the PVA model. Including the proxy with the uri mentioned earlier in this post.


The fact that Epsilon is able to correctly load this model leads me to think that I may have made some mistakes on setting up the ResourceSet, however the only difference is that I load the PVA model as well. I tried manually loading the PVA model, but this didn't help in the resolution of the proxies. Another interesting fact is that the PVA model gets added to the resourceSet after invocation of the line
EcoreUtil.resolve(unresolvedProxy.key,resourceSet)


Do you have any other clues on what might be wrong?

[Updated on: Tue, 26 July 2016 07:54]

Report message to a moderator

Previous Topic:property sheet value
Next Topic:Very basic question to first use of EEF
Goto Forum:
  


Current Time: Sun Jun 20 15:29:41 GMT 2021

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

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

Back to the top