Resource [message #1767609] |
Fri, 07 July 2017 14:37 |
Banafsheh Azizi Messages: 328 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.
Member of MDSE Research Group
http://mdse.ui.ac.ir
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Re: Resource [message #1769340 is a reply to message #1768655] |
Sun, 30 July 2017 10:27 |
Banafsheh Azizi Messages: 328 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();
}
Member of MDSE Research Group
http://mdse.ui.ac.ir
[Updated on: Sun, 30 July 2017 10:28] Report message to a moderator
|
|
|
|
|
|
|
|
|
Re: Resource [message #1769414 is a reply to message #1769403] |
Mon, 31 July 2017 12:04 |
Banafsheh Azizi Messages: 328 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:54Hi
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?
Member of MDSE Research Group
http://mdse.ui.ac.ir
[Updated on: Mon, 31 July 2017 12:20] Report message to a moderator
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.10439 seconds