Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » Read referenced resource programatically
icon5.gif  Read referenced resource programatically [message #634605] Fri, 22 October 2010 12:30 Go to next message
Kai Maschke is currently offline Kai MaschkeFriend
Messages: 16
Registered: October 2010
Junior Member
Hi there,

I figured out how to reference another ecore model inside an ecore model. the generated editor code works fine. I am able to use the editor to reference the other ecore instance.
But I want to load the instances programtically. All works fine for me as long as I load a simple instance which references no other one. If I try it like this below, the referenced instance content is not loaded.
File dir = new File(path);
File[] files = dir.listFiles();

List<Datasource> sources = new ArrayList<Datasource>();
		
for (File aFile : files) {
	try {
		if (!aFile.getAbsolutePath().toString().endsWith("datasource")) {
					continue;
		}

		@SuppressWarnings("unused")
		DatasourcePackage pack = DatasourcePackage.eINSTANCE;
		ResourceSet rs = new ResourceSetImpl();
				rs.getResourceFactoryRegistry().getExtensionToFactoryMap().put(
						"datasource", new XMIResourceFactoryImpl());
				URI fileURI = URI.createFileURI(new File(aFile
						.getAbsolutePath()).getAbsolutePath());

				
				Resource myPort = rs.getResource(fileURI, true);

				Datasource source = (Datasource) myPort.getContents().get(0);
				sources.add(source);
				
			} catch (Exception e) {
				e.printStackTrace();
			}

		}


So what do I have to do, to get the referenced content being loaded?

[Updated on: Fri, 22 October 2010 12:30]

Report message to a moderator

Re: Read referenced resource programatically [message #634619 is a reply to message #634605] Fri, 22 October 2010 12:58 Go to previous message
Kai Maschke is currently offline Kai MaschkeFriend
Messages: 16
Registered: October 2010
Junior Member
Got it myself!

Solution:
Load all instances, including the references ones, into one ResourceSet. After on run "EcoreUtil.resolveAll(resourceSet)". This will load all referenced instances.
Afterwards you can read the contents of the resources, including the referenced contents.
Previous Topic:Teneo
Next Topic:modify the semantic model in the table viewer
Goto Forum:
  


Current Time: Fri Nov 15 15:16:30 GMT 2019

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

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

Back to the top