Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » Loading XMI files in Eclipse Indigo
Loading XMI files in Eclipse Indigo [message #854377] Mon, 23 April 2012 23:10 Go to next message
Juan Castel is currently offline Juan CastelFriend
Messages: 20
Registered: April 2012
Junior Member
Hi, everybody.

I'm trying to load XMI files in order to create and XMI that is made out of Ecore elements of some xxx.ecore model. I cannot do it through ATL as M2M because ATL won't let me import as IN parameters arbitrary XMI files (one discovered by MoDisco and another exported by Enterprise Architect).

When I try to load an ecore file in EMF it gives null pointer or tells me some epackage is not registered.

ResourceSet resourceSet = new ResourceSetImpl();
		Resource rs = resourceSet.createResource(URI.createFileURI(file.getAbsolutePath()));
		System.out.println("rs: " + rs);
		//ResourceSet resourceSet = new ResourceSetImpl();

		EPackage.Registry reg1;
		reg1 = resourceSet.getPackageRegistry();
		System.out.println("registry: " + reg1);
		System.out.println("EcorePackage.eNS_URI: " + EcorePackage.eNS_URI);
		System.out.println("EcorePackage.eINSTANCE: " + URI.createFileURI("c:/Users/USUARIO/workspace/archivol/archivol.ecore"));
		reg1.put(EcorePackage.eNS_URI, URI.createFileURI("c:/Users/USUARIO/workspace/archivol/archivol.ecore"));



Rs is always null.

What is it that I'm doing wrong??

Thank you!
Re: Loading XMI files in Eclipse Indigo [message #854624 is a reply to message #854377] Tue, 24 April 2012 05:23 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33136
Registered: July 2009
Senior Member
<html>
<head>
<meta content="text/html; charset=UTF-8" http-equiv="Content-Type">
</head>
<body bgcolor="#FFFFFF" text="#000000">
Juan,<br>
<br>
Comments below.<br>
<br>
On 24/04/2012 1:10 AM, Juan Castel wrote:
<blockquote cite="mid:jn4nh9$j13$1@xxxxxxxxe.org" type="cite">Hi,
everybody.
<br>
<br>
I'm trying to load XMI files in order to create and XMI that is
made out of Ecore elements of some xxx.ecore model.</blockquote>
Have you generated the model for this?<br>
<blockquote cite="mid:jn4nh9$j13$1@xxxxxxxxe.org" type="cite"> I
cannot do it through ATL as M2M because ATL won't let me import as
IN parameters arbitrary XMI files (one discovered by MoDisco and
another exported by Enterprise Architect).
<br>
<br>
When I try to load an ecore file in EMF it gives null pointer or
tells me some epackage is not registered.
<br>
</blockquote>
If you really need to <br>
<blockquote cite="mid:jn4nh9$j13$1@xxxxxxxxe.org" type="cite">
<br>
<br>
ResourceSet resourceSet = new ResourceSetImpl();
<br>
</blockquote>
When running stand alone, you need to register a resource factory. 
Like EcoreResourceFactoryImpl for "ecore" extension or
XMIResourceFactoryImpl for extensions of files containing XMI
instances.<br>
<blockquote cite="mid:jn4nh9$j13$1@xxxxxxxxe.org" type="cite">       
Resource rs =
resourceSet.createResource(URI.createFileURI(file.getAbsolutePath()));
<br>
        System.out.println("rs: " + rs);
<br>
        //ResourceSet resourceSet = new ResourceSetImpl();
<br>
<br>
        EPackage.Registry reg1;
<br>
        reg1 = resourceSet.getPackageRegistry();
<br>
        System.out.println("registry: " + reg1);
<br>
        System.out.println("EcorePackage.eNS_URI: " +
EcorePackage.eNS_URI);
<br>
        System.out.println("EcorePackage.eINSTANCE: " +
URI.createFileURI("c:/Users/USUARIO/workspace/archivol/archivol.ecore"));<br>
        reg1.put(EcorePackage.eNS_URI,
URI.createFileURI("c:/Users/USUARIO/workspace/archivol/archivol.ecore"));<br>
</blockquote>
The value of a registry's map should be the EPackage instance. If
you really want to do this with a dynamic model rather then
generating code for archivol.ecore you should read:<br>
<blockquote> <a target="_dw"
href="http://www.ibm.com/developerworks/library/os-eclipse-dynamicemf/">Build
metamodels with dynamic EMF</a></blockquote>
<blockquote cite="mid:jn4nh9$j13$1@xxxxxxxxe.org" type="cite">
<br>
<br>
<br>
Rs is always null.
<br>
<br>
What is it that I'm doing wrong??
<br>
<br>
Thank you!
<br>
</blockquote>
</body>
</html>


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Loading XMI files in Eclipse Indigo [message #858941 is a reply to message #854624] Fri, 27 April 2012 11:25 Go to previous messageGo to next message
Olaf Burdziakowski is currently offline Olaf BurdziakowskiFriend
Messages: 46
Registered: April 2012
Member
I use such a code fr EMF:

EPackage.Registry.INSTANCE.put(CreConfigDirPackage.eNS_URI, CreConfigDirPackage.eINSTANCE);
Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().put("xml",new CreConfigDirResourceFactoryImpl());

ResourceSet rs = new ResourceSetImpl();
rs.getResourceFactoryRegistry().getExtensionToFactoryMap().put("xml", new CreConfigDirResourceFactoryImpl());
String sFile = "c:\\Users\\Olaf\\ORGA\\Java\\DeployToDatabase\\cre\\config.dir.xml";
URI resourceURI = URI.createURI("file:/" + sFile);
XMLResourceImpl res = (XMLResourceImpl) rs.createResource(resourceURI);

HashMap options = new HashMap();
options.put("LAX_FEATURE_PROCESSING", Boolean.TRUE);

//open Stream
m_pFIS = new FileInputStream(sFile);
//load xml
res.load(m_pFIS, options);
// close stream
m_pFIS.close();

CreConfigDir.DocumentRoot rootCCD = (CreConfigDir.DocumentRoot) res.getContents().get(0);
ListType list = rootCCD.getList();
EList<FileType>eList=list.getFile();
Re: Loading XMI files in Eclipse Indigo [message #859233 is a reply to message #858941] Fri, 27 April 2012 14:22 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 33136
Registered: July 2009
Senior Member
Olaf,

Comments below.

On 27/04/2012 1:25 PM, Olaf Burdziakowski wrote:
> I use such a code fr EMF:
>
> EPackage.Registry.INSTANCE.put(CreConfigDirPackage.eNS_URI,
> CreConfigDirPackage.eINSTANCE);
>
> Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().put("xml",new
> CreConfigDirResourceFactoryImpl());
>
> ResourceSet rs = new ResourceSetImpl();
>
> rs.getResourceFactoryRegistry().getExtensionToFactoryMap().put("xml",
> new CreConfigDirResourceFactoryImpl());
> String sFile =
> "c:\\Users\\Olaf\\ORGA\\Java\\DeployToDatabase\\cre\\config.dir.xml";
> URI resourceURI = URI.createURI("file:/" + sFile);
Better to use URI.createFileURI because this approach doesn't convert \
to / and \ isn't a segment separator in a URI so you're likely to have
problems with any relative cross document references.
> XMLResourceImpl res = (XMLResourceImpl)
> rs.createResource(resourceURI);
> HashMap options = new HashMap();
> options.put("LAX_FEATURE_PROCESSING", Boolean.TRUE);
> //open Stream
> m_pFIS = new FileInputStream(sFile);
> //load xml
> res.load(m_pFIS, options);
> // close stream
> m_pFIS.close();
It's also much easier to use rs.getResource(resourceURI, true) than
doing all these manual steps. You can put default options in
rs.getLoadOptions().
> CreConfigDir.DocumentRoot rootCCD =
> (CreConfigDir.DocumentRoot) res.getContents().get(0);
> ListType list = rootCCD.getList();
> EList<FileType>eList=list.getFile();


Ed Merks
Professional Support: https://www.macromodeling.com/
Previous Topic:Serializing Model data to XML
Next Topic:EObject resource detached
Goto Forum:
  


Current Time: Fri Apr 19 03:40:24 GMT 2024

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

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

Back to the top