Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » MoDisco » Loading java2kdm Models - Best Practices?
Loading java2kdm Models - Best Practices? [message #899847] Thu, 02 August 2012 14:56 Go to next message
Benjamin Klatt is currently offline Benjamin KlattFriend
Messages: 36
Registered: September 2010
Member
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 07:12 Go to previous messageGo to next message
Fabien Giquel is currently offline Fabien GiquelFriend
Messages: 138
Registered: July 2009
Senior Member
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);


----------------------------------------------------
Fabien GIQUEL
R&D Engineer
Mia-Software
4, rue du Ch√Ęteau de l'Eraudiere
44324 NANTES CEDEX 03
----------------------------------------------------
Re: Loading java2kdm Models - Best Practices? [message #900537 is a reply to message #900245] Tue, 07 August 2012 12:44 Go to previous messageGo to next message
Benjamin Klatt is currently offline Benjamin KlattFriend
Messages: 36
Registered: September 2010
Member
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 10:37 Go to previous message
Benjamin Klatt is currently offline Benjamin KlattFriend
Messages: 36
Registered: September 2010
Member
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: Wed Nov 26 10:40:24 GMT 2014

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

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