Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » Object name instead of eProxyURI
Object name instead of eProxyURI [message #1846953] Sun, 10 October 2021 10:57 Go to next message
John Henbergs is currently offline John HenbergsFriend
Messages: 239
Registered: October 2020
Senior Member
Hello,

I have two metamodels A and B.
Metamodel A has class A, and one of the attributes is element: EObject.
I have created a model A conforming to metamodel A, and as element I have chosen one of the classes of metamodel B (After I loaded metamodel B as a resource).

Now I am using a Java code to print the name of the EObject in element, but every time I use getElement(), I get the eProxyURI, while I just want the name.

Here is an example. I get this:

[org.eclipse.emf.ecore.impl.EObjectImpl@b62d79 (eProxyURI: ../org.eclipse.example/plugins/test/metamodel/org.eclipse.example.test.building.model/model/building.ecore#//Building)]


While in fact I only want "Building".

Is there any way to achieve that?

Many thanks,
John
Re: Object name instead of eProxyURI [message #1846954 is a reply to message #1846953] Sun, 10 October 2021 11:25 Go to previous messageGo to next message
John Henbergs is currently offline John HenbergsFriend
Messages: 239
Registered: October 2020
Senior Member
This is what it says for getElement()

/**
	 * Returns the value of the '<em><b>Element</b></em>' reference list.
	 * The list contents are of type {@link org.eclipse.emf.ecore.EObject}.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @return the value of the '<em>Element</em>' reference list.
	 * @see exm.EXMPackage#getBlock_Input()
	 * @model
	 * @generated
	 */
	EList<EObject> getElement();



Do I need to modify this somehow to return the names or I can do something in the Java code where I print the names?
Re: Object name instead of eProxyURI [message #1846956 is a reply to message #1846954] Sun, 10 October 2021 13:52 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33251
Registered: July 2009
Senior Member
Always load a resource with an absolute URI otherwise relative paths within that resource cannot resolve and will remain proxies. If you see a proxy with a relative URI, as in your case above where it starts with ../ and not file:, platform: or http:, you know that you haven't done this properly. So don't ever do URI.createFileURI("myext.ecore") but rather do URI.createFileURI(new File("myext.ecore").getAbsolutePath()) to create an absolute URI for loading the resource.

Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Object name instead of eProxyURI [message #1846957 is a reply to message #1846956] Sun, 10 October 2021 15:06 Go to previous messageGo to next message
John Henbergs is currently offline John HenbergsFriend
Messages: 239
Registered: October 2020
Senior Member
Hi Ed,

Thanks for the info. I did the following:

   val resource = resourceSet.getResource(URI.createFileURI(new File(file).absolutePath), true)


And now I get the absolute path like this:

Quote:

[org.eclipse.emf.ecore.impl.EObjectImpl@b62d79 (eProxyURI: file:/Users/user/runtime-Instance/org.eclipse.example/plugins/test/metamodel/org.eclipse.example.test.building.model/model/building.ecore#//Building)]


However the issue is still the same. In model A that conforms to metamodel A I have this "Element" attribute , and I cross reference Building that is in metamodel B. However, as you can see I still get the path (i.e., file:/Users/user/runtime-Instance/org.eclipse.example/plugins/test/metamodel/org.eclipse.example.test.building.model/model/building.ecore#//Building)]), when I actually want to get the name (i.e., Building)
Re: Object name instead of eProxyURI [message #1846963 is a reply to message #1846957] Sun, 10 October 2021 17:29 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33251
Registered: July 2009
Senior Member
I am not a remote debugger. You should learn to use the debugger. It's your best friend and can answer questions faster than I can. Have you used it to see how proxy resolution works? Have you looked in your resource set to see what resources have been loaded? No doubt there is a resource with URI file:/Users/user/runtime-Instance/org.eclipse.example/plugins/test/metamodel/org.eclipse.example.test.building.model/model/building.ecore loaded in your resource set. Does that actual resource exist? Is there information in resource.getErrors for that resource? I.e., is there some reason it's failing to load that you've overlooked?

Surely you can't expect someone to guess what you've done wrong without even showing any code? I don't even know whether you have generated the model or not because you've not answer that question the last time I asked.


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Object name instead of eProxyURI [message #1846964 is a reply to message #1846963] Sun, 10 October 2021 18:53 Go to previous messageGo to next message
John Henbergs is currently offline John HenbergsFriend
Messages: 239
Registered: October 2020
Senior Member
Hi Ed,

No issues in the debugger. I have looked into the resource set, and there I have loaded model A and metamodel B. I used getErrors() for both of them and I get nothing, so I believe there are no errors.
When I check the resource set I get the following:
[org.eclipse.emf.ecore.xmi.impl.XMIResourceImpl@156b88f5 uri='file:/Users/user/runtime-Instance/Test1/modelA.exm', 
org.eclipse.emf.ecore.xmi.impl.EcoreResourceFactoryImpl$1@3bf9ce3e uri='file:/Users/user/runtime-Instance/Test1/metamodelB.ecore']


And when I try to print the name I get:
[org.eclipse.emf.ecore.impl.EObjectImpl@16610890 (eProxyURI: file:/Users/user/runtime-Instance/Test1/metamodelB.ecore#//Building)]


So the eProxyURI is same as the uri of the metamodel resource, but still it will not resolve.

Re: Object name instead of eProxyURI [message #1846965 is a reply to message #1846964] Sun, 10 October 2021 19:19 Go to previous messageGo to next message
John Henbergs is currently offline John HenbergsFriend
Messages: 239
Registered: October 2020
Senior Member
Ok so I used

resolved = EcoreUtil.resolve (m.element, resourceSet)

and now when I print "resolved" I get

org.eclipse.emf.ecore.impl.EClassImpl@16610890 (name: Building) (instanceClassName: null) (abstract: false, interface: false)

How can I now only print the name "Building"?

Thank you!
Re: Object name instead of eProxyURI [message #1846969 is a reply to message #1846965] Mon, 11 October 2021 05:03 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 33251
Registered: July 2009
Senior Member
Did you use the debugger to see why this is not automatically resolved? Something is still wrong if you need to do it manually. But without code, one can only guess.

If you used the debugger, you'd see there the name printed is from in the toString method, and you'd use Open Call Hierarchy on the 'name' field to see that there is a getName method on the implementation EClassImpl which you would see implements that same method declared in an inherited interface of EClass.


Ed Merks
Professional Support: https://www.macromodeling.com/
Previous Topic:Load EMF model instance with Xtend/Java
Next Topic:Reason for: A containment or bidirectional reference must be unique if its upper bound is different
Goto Forum:
  


Current Time: Fri Nov 01 00:10:55 GMT 2024

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

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

Back to the top