Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF "Technology" (Ecore Tools, EMFatic, etc)  » Resource
Resource [message #1767609] Fri, 07 July 2017 14:37 Go to next message
Banafsheh A is currently offline Banafsheh AFriend
Messages: 262
Registered: July 2016
Senior Member
Hi,

How can I set Resource variable of "org.eclipse.emf.ecore.resource.Resource"?
i.e., Resource mmResource = ?
I want to assign my ecore file to it.
Re: Resource [message #1767623 is a reply to message #1767609] Fri, 07 July 2017 18:44 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 29460
Registered: July 2009
Senior Member
Look at any generated editor, e.g. EcoreEditor. Typically you use a ResourceSet and call getResource(uri, true), to load it.
Re: Resource [message #1767814 is a reply to message #1767623] Tue, 11 July 2017 11:39 Go to previous messageGo to next message
Banafsheh A is currently offline Banafsheh AFriend
Messages: 262
Registered: July 2016
Senior Member
I am sorry, I cannot completely understand what should I do. e.g., I have an error with the below code:
ResourceSet rs = new ResourceSetImpl();
URI i = new URI("/Users/apple/Desktop/runtime-EclipseApplication/test/f2p.xmi"); 
Resource r = rs.getResource(i, true);

[Updated on: Tue, 11 July 2017 12:06]

Report message to a moderator

Re: Resource [message #1767816 is a reply to message #1767814] Tue, 11 July 2017 11:52 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 5980
Registered: July 2009
Senior Member
Hi

It would help to know what the error is. Could be that /external/images/media/470939 does not exist. Could be that it is not XML. Could just be that you neglected to register an appropriate resource factory, which is easier if you have a distinct file extension.

Regards

Ed Willink
Re: Resource [message #1767819 is a reply to message #1767816] Tue, 11 July 2017 12:04 Go to previous messageGo to next message
Banafsheh A is currently offline Banafsheh AFriend
Messages: 262
Registered: July 2016
Senior Member
I mistakenly set the address (I edited it), but the error not related to the address.
This is the error:
index.php/fa/29927/0/

[Updated on: Tue, 11 July 2017 12:07]

Report message to a moderator

Re: Resource [message #1767820 is a reply to message #1767819] Tue, 11 July 2017 12:10 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 5980
Registered: July 2009
Senior Member
Hi

This a simple Java problem. The error message explains that you have used the wrong URI class.

Regards

Ed Willink
Re: Resource [message #1767865 is a reply to message #1767820] Tue, 11 July 2017 17:16 Go to previous messageGo to next message
Banafsheh A is currently offline Banafsheh AFriend
Messages: 262
Registered: July 2016
Senior Member
Ok.
I changed the code as below:
ResourceSet rs = new ResourceSetImpl();
java.net.URI	i = null;
try {
	i = new java.net.URI("/Users/apple/Desktop/runtime-EclipseApplication/test/f2p.xmi");
	} catch (URISyntaxException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
org.eclipse.emf.common.util.URI emfURI = org.eclipse.emf.common.util.URI.createURI(i.toString());
Resource r = rs.getResource(emfURI, true);
	

This has the below error . It seems related to "org.eclipse.emf.common.util.URI emfURI = org.eclipse.emf.common.util.URI.createURI(i.toString());
".
index.php/fa/29930/0/
Re: Resource [message #1767867 is a reply to message #1767865] Tue, 11 July 2017 17:40 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 5980
Registered: July 2009
Senior Member
Hi

You really seem determined to make a simple problem hard. Debug a simple Java program before you add the complexities of Epsilon and a seemingly badly installed mychecker.

You have clipped the important part of the error message explaining the DiagnosticWrappedException.

Constructing a java.net.URI and then converting it to an EMF URI is dangerous. Why not just construct an EMF URI in the first place thereby ensuring that you declare the platform/resource aspect?

Your ongoing use of snippets ensures that yiou get less than helpful answers. You might find that https://wiki.eclipse.org/OCL/ForumNetiquette helps you request help in a way that gets a much faster response.

Regards

Ed Willink
Re: Resource [message #1767892 is a reply to message #1767867] Wed, 12 July 2017 04:54 Go to previous messageGo to next message
Banafsheh A is currently offline Banafsheh AFriend
Messages: 262
Registered: July 2016
Senior Member
Hi,
That is because I am new in java.:(
I changed my code. I attached my code and the file of errors.
I want to load my xmi model to a variable of type Resource to then be able to use another plugin. However, it has an error on line "Resource r = rs.getResource(emfURI, true);".
Re: Resource [message #1767920 is a reply to message #1767892] Wed, 12 July 2017 07:46 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 5980
Registered: July 2009
Senior Member
Hi

The fuller information makes it possible to see that the missing error message was

Resource '/Users/apple/Desktop/runtime-EclipseApplication/test/f2p.xmi' does not exist.

and that what appears to be a failed checker installation by an Epsilon launch is a misguided use of the Epsilon launcher for a simple Java application.

Try the attached using Run AS Java Application while selecting / editing the Java file.

Regards

Ed Willink
  • Attachment: aa.zip
    (Size: 4.38KB, Downloaded 42 times)
Re: Resource [message #1767934 is a reply to message #1767920] Wed, 12 July 2017 08:52 Go to previous messageGo to next message
Banafsheh A is currently offline Banafsheh AFriend
Messages: 262
Registered: July 2016
Senior Member
Thank you very much indeed. My problem was solved.
Re: Resource [message #1768482 is a reply to message #1767934] Wed, 19 July 2017 11:13 Go to previous messageGo to next message
Banafsheh A is currently offline Banafsheh AFriend
Messages: 262
Registered: July 2016
Senior Member
Hi,

How can I save this resource? When I write the below code nothing happened.
		Resource r = rs.getResource(emfURI, true);
		
try {
	r.save(null);
} catch (IOException e) {
	// TODO Auto-generated catch block
	e.printStackTrace();
}
Re: Resource [message #1768485 is a reply to message #1768482] Wed, 19 July 2017 11:34 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 29460
Registered: July 2009
Senior Member
How do you know thing happened? Have you debugged what happens?
Re: Resource [message #1768488 is a reply to message #1768485] Wed, 19 July 2017 12:32 Go to previous messageGo to next message
Banafsheh A is currently offline Banafsheh AFriend
Messages: 262
Registered: July 2016
Senior Member
Really, I don't know how can I save it correctly.
When we use save(null), where is it saved?:s
I want to save it to the special folder. I also try to pass arguments to it but I don't have an idea about its arguments specially second argument (OutputStream, Map<?,?>). I appreciate you if you provide an example.
Re: Resource [message #1768495 is a reply to message #1768488] Wed, 19 July 2017 13:28 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 29460
Registered: July 2009
Senior Member
It is saved to the URI you've specified when you loaded it. The options map can be null. They're just options. You could also set the URI of the resource to the URI at which you want it saved, and just call save(null) again.
Re: Resource [message #1768521 is a reply to message #1768495] Wed, 19 July 2017 16:30 Go to previous messageGo to next message
Banafsheh A is currently offline Banafsheh AFriend
Messages: 262
Registered: July 2016
Senior Member
Thank you very much.
Re: Resource [message #1768623 is a reply to message #1768521] Thu, 20 July 2017 16:39 Go to previous messageGo to next message
Banafsheh A is currently offline Banafsheh AFriend
Messages: 262
Registered: July 2016
Senior Member
Hi,

How can I register metamodel via java code? I have EPackage of the metamodel. Is the code bellow true?:s

public String test(EPackage metamodel){ 
Resource mmResource = metamodel.eResource();
mmResource.getResourceSet().setPackageRegistry(null);

[Updated on: Thu, 20 July 2017 16:40]

Report message to a moderator

Re: Resource [message #1768630 is a reply to message #1768623] Thu, 20 July 2017 18:06 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 29460
Registered: July 2009
Senior Member
Is it a generated model?
Re: Resource [message #1768633 is a reply to message #1768630] Thu, 20 July 2017 18:29 Go to previous messageGo to next message
Banafsheh A is currently offline Banafsheh AFriend
Messages: 262
Registered: July 2016
Senior Member
No, it is an ecore metamodel. e.g., I pass EPackage of Families.ecore metamodel from epsilon to Java.

[Updated on: Thu, 20 July 2017 18:30]

Report message to a moderator

Re: Resource [message #1768637 is a reply to message #1768633] Thu, 20 July 2017 20:30 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 29460
Registered: July 2009
Senior Member
Perhaps it's better to ask on the Epsilon forum: https://www.eclipse.org/forums/index.php/f/22/
Re: Resource [message #1768655 is a reply to message #1768637] Fri, 21 July 2017 05:27 Go to previous messageGo to next message
Banafsheh A is currently offline Banafsheh AFriend
Messages: 262
Registered: July 2016
Senior Member
I want to do it in java. OK.
Re: Resource [message #1769340 is a reply to message #1768655] Sun, 30 July 2017 10:27 Go to previous messageGo to next message
Banafsheh A is currently offline Banafsheh AFriend
Messages: 262
Registered: July 2016
Senior Member
Hi,

Is it the correct way to loading a "Resource"?
"path" is a type of "URI".
ResourceSet rs = new ResourceSetImpl();
rs.getResourceFactoryRegistry().getExtensionToFactoryMap().put("xmi", new XMIResourceFactoryImpl());
Resource r = rs.getResource(path, true);
try {
			r.load(rs.getResourceFactoryRegistry().getExtensionToFactoryMap());
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

[Updated on: Sun, 30 July 2017 10:28]

Report message to a moderator

Re: Resource [message #1769343 is a reply to message #1769340] Sun, 30 July 2017 11:26 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 5980
Registered: July 2009
Senior Member
Hi

The first three lines look plausible.
The true argument on the third means that it should load automatically.
The subsequent explicit load may go mad since you pass an ExtensionToFactoryMap where a load options map, possibly null was required.

Regards

Ed Willink
Re: Resource [message #1769349 is a reply to message #1769343] Sun, 30 July 2017 16:09 Go to previous messageGo to next message
Banafsheh A is currently offline Banafsheh AFriend
Messages: 262
Registered: July 2016
Senior Member
Thank you. I changed the explicit load statement to the bellow code. However, the model is still not loaded.
try {
			r.load(null);
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
Re: Resource [message #1769353 is a reply to message #1769349] Sun, 30 July 2017 18:46 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 29460
Registered: July 2009
Senior Member
ResourceSet.getResource(uri, true) will already load the resource, so no need for an explicit load call. Loading might throw and exception, e.g., if the uri doesn't point at something that really exists. How can you tell it's not loaded?
Re: Resource [message #1769390 is a reply to message #1769353] Mon, 31 July 2017 09:54 Go to previous messageGo to next message
Banafsheh A is currently offline Banafsheh AFriend
Messages: 262
Registered: July 2016
Senior Member
Thanks. I removed it. It still sometimes work and some other times not work.
I previously created a thread in Epsilon forum with a minimal example in https://www.eclipse.org/forums/index.php?t=msg&th=1087617&goto=1768571&#msg_1768571 . After I added the load statement, It worked correctly in few days ago. But yesterday, it doesn't work correctly.
when I remove the explicit load statement yesterday, it works correctly several times but today it doesn't work. I don't know what is the reason.

[Updated on: Mon, 31 July 2017 09:56]

Report message to a moderator

Re: Resource [message #1769402 is a reply to message #1769390] Mon, 31 July 2017 10:54 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 5980
Registered: July 2009
Senior Member
Hi

Your Epsilon example is a few comments old.

If you have an intermittent behavior I suspect that it is more likely to do with file accesses than flaky EMF. For instance, if you keep a debugger session running, it may lock its input files, inhibiting an auto-build and perhaps disrupting a subsequent access.

Regards

Ed Willink
Re: Resource [message #1769403 is a reply to message #1769390] Mon, 31 July 2017 10:54 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 29460
Registered: July 2009
Senior Member
Be sure to inspect Resource.getError() because failures to load will be recorded there. You didn't exactly answer the question "how can you tell it's not loaded?" Note tat I'll only look at an example that uses purely EMF core bundles. For Epsilon usage you'll have to rely on the Epsilon forum's help.
Re: Resource [message #1769414 is a reply to message #1769403] Mon, 31 July 2017 12:04 Go to previous messageGo to next message
Banafsheh A is currently offline Banafsheh AFriend
Messages: 262
Registered: July 2016
Senior Member
Ed Merks wrote on Mon, 31 July 2017 10:54

how can you tell it's not loaded?


because for example I have a A block that creates a model in EOL when I print the content of it in EOL it print the contents. Then I have a B block that called the Java function. When I print the content of the resource (System.out.print(r.getContents());) it returns "[]".
My Java code:
package test;

import java.util.ArrayList;


import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.ecore.resource.ResourceSet;
import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
import org.eclipse.emf.ecore.xmi.impl.XMIResourceFactoryImpl;

public class TestClass {
	
	public ArrayList<EObject> Test1(URI path) {

		ResourceSet rs = new ResourceSetImpl();
		rs.getResourceFactoryRegistry().getExtensionToFactoryMap().put("xmi", new XMIResourceFactoryImpl());
		Resource r = rs.getResource(path, true);
		
		System.out.print(r.getContents());
	
		ArrayList<EObject> expressions = new ArrayList<>();

		for (EObject i : r.getContents())
		{
			expressions.add(i);
		}
		return expressions;
		
	}
	
}


If it has Contents before I run my program it is printed but the new elements that are created in my program not shown. It seems contents not refreshed.

Ed Willink wrote on Mon, 31 July 2017 10:54
Hi

Your Epsilon example is a few comments old.

If you have an intermittent behavior I suspect that it is more likely to do with file accesses than flaky EMF. For instance, if you keep a debugger session running, it may lock its input files, inhibiting an auto-build and perhaps disrupting a subsequent access.

Regards

Ed Willink

What should I do?

[Updated on: Mon, 31 July 2017 12:20]

Report message to a moderator

Re: Resource [message #1769420 is a reply to message #1769414] Mon, 31 July 2017 12:41 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 29460
Registered: July 2009
Senior Member
Use the debugger. Inspect the instances involved in the Variables view. I can't know what URI you're using, nor what's actually at that location. In your zipped sample I do see ATExpression.model with these contents:
<?xml version="1.0" encoding="ASCII"?>
<xmi:XMI xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:ocl="http://www.eclipse.org/gmt/2005/OCL">

</xmi:XMI>
That's of course an empty resource, so if you load that, not surprisingly you'll have an empty resource.
Re: Resource [message #1769431 is a reply to message #1769420] Mon, 31 July 2017 13:28 Go to previous messageGo to next message
Banafsheh A is currently offline Banafsheh AFriend
Messages: 262
Registered: July 2016
Senior Member
The path contains "platform:/resource/test1/ATLExpression.model".
It is in test1 project.
At First it is an empty resource. But via EOL codes that I written in project.eol file, I created elements to it and I can see the elements after running code when I open the ATLExpression.model. But they are not printed in Java.

I use two eclipse. i.e., I imported "Test" plugin to eclipse. then I run it as "eclipse application". In the new eclipse, I imported test1 project and run project.launch.
I used the debugger for the EOL program, the "path" variable and variable "c" that contains the final result are shown in the attached picture.
Re: Resource [message #1769432 is a reply to message #1769431] Mon, 31 July 2017 14:00 Go to previous message
Ed Willink is currently offline Ed WillinkFriend
Messages: 5980
Registered: July 2009
Senior Member
Hi

You appear to be using at least ATL and EOL and Java and so you have ample opportunity for 'impossible' mistakes. Debug harder. Try putting printf into EMF construction methods printing out eClass().getName and System.identityHashCode so that you can discover what is really happening to your objects. Once you are happy that you are actually looking at the same Resources and EObjects use printf on set methods to find where a corruption occurs.

Regards

Ed Willink
Previous Topic:[Edapt] Format of resourceURI to get the Releases from the Migrator?
Next Topic:[EMF Forms] EClass from View model cannot be resolved
Goto Forum:
  


Current Time: Sun Jul 22 18:33:27 GMT 2018

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

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

Back to the top