Skip to main content



      Home
Home » Modeling » MoDisco » Loading java2kdm Models - Best Practices?
Loading java2kdm Models - Best Practices? [message #899847] Thu, 02 August 2012 10:56 Go to next message
Eclipse UserFriend
Hi,

we are using the Java and Inventory Discoverer to get complete models of our java projects.
For the further processing in our tools we use the following code to load the _java2kdm.xmi model and to ensure that all referenced submodels are resolved:

JavaapplicationPackage.eINSTANCE.eClass();
JavaPackage.eINSTANCE.eClass();
ResourceSet resourceSet = new ResourceSetImpl();
resourceSet.eAdapters().add(new ECrossReferenceAdapter());
EObject model = ModelUtils.load(java2kdmModelFile, resourceSet);


However, the ModelUtils class comes from the EMFCompare project and as you can see we need to explicitly reference the packages to ensure they are registered before the model is loaded.

Is there any recommended way or any utility offered by MoDisco to simplify loading java2kdm models and resolving all references? Could you provide some example code how this can be done better and even without any dependency on EMF Compare?

Thanks a lot
Benjamin
Re: Loading java2kdm Models - Best Practices? [message #900245 is a reply to message #899847] Mon, 06 August 2012 03:12 Go to previous messageGo to next message
Eclipse UserFriend
Hello Benjamin,

you may try the resolveAll services from org.eclipse.emf.ecore.EcoreUtil.


For Example :

ResourceSet rs = new ResourceSetImpl();
Resource r = rs.createResource(URI.createFileURI("D:/myPath/my_java2kdm.xmi"));
r.load(null);
EcoreUtil.resolveAll(rs);
Re: Loading java2kdm Models - Best Practices? [message #900537 is a reply to message #900245] Tue, 07 August 2012 08:44 Go to previous messageGo to next message
Eclipse UserFriend
Hi Fabien,

thanks for your reply.

Trying your code, I end up with nullpointer exception because no resource is returned.
I veryfied that the filepath is valid. Btw. I am trying to run this code within a unit test. So would this be an issue?

Cheers
Benjamin
Re: Loading java2kdm Models - Best Practices? [message #900731 is a reply to message #900537] Wed, 08 August 2012 06:37 Go to previous message
Eclipse UserFriend
Ok, I found the issue.
Due to the JUnit test environment (not a Junit Plugin Test), there was no default resource factory registered.

Explicitly registering the resource solved the problem:

// load the required meta class packages
JavaapplicationPackage.eINSTANCE.eClass();
JavaPackage.eINSTANCE.eClass();

// register the factory to be able to read xmi files
Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap()
  .put(Resource.Factory.Registry.DEFAULT_EXTENSION,new XMIResourceFactoryImpl());
	    
// load the resource and resolve the proxies
ResourceSet rs = new ResourceSetImpl();
Resource r = rs.createResource(URI.createFileURI(java2kdmModelFile.getAbsolutePath()));
r.load(null);
EcoreUtil.resolveAll(rs)
;
Previous Topic:PHP discoverer
Next Topic:Ignoring Elements completely in custom Match and Diff Engine
Goto Forum:
  


Current Time: Fri May 23 02:13:22 EDT 2025

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

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

Back to the top