Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » MoDisco » How to process my KDM models
icon5.gif  How to process my KDM models [message #1005842] Mon, 28 January 2013 18:42 Go to next message
keynne Belle is currently offline keynne Belle
Messages: 21
Registered: January 2013
Junior Member
Hello.
I've learned a bit about KDM and i just downloaded the MoDisco distribution.
I generated a KDM model from a java project and then, i created my query set and my queries using the gui and i obtained the corresponding code in java. But i don't have a clue on what to put in the body of my queries in order to get the root of my model/extract specific dependencies/specific modules instead of the "return null;" instruction that is proposed by default.
Re: How to process my KDM models [message #1005850 is a reply to message #1005842] Mon, 28 January 2013 23:02 Go to previous messageGo to next message
keynne Belle is currently offline keynne Belle
Messages: 21
Registered: January 2013
Junior Member
In order to write a request that allows me to get the KDM segment associated to my java project, i searched examples on the web and then i wrote the following query:

public class GetSegment implements IJavaModelQuery<Annotation, Segment> {
public Segment evaluate(final Annotation context, final ParameterValueList parameterValues)
throws ModelQueryExecutionException {

ResourceSet resourceSet=new ResourceSetImpl();
resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put("*",
new XMIResourceFactoryImpl());

resourceSet.getPackageRegistry().put(Resource.Factory.Registry.DEFAULT_EXTENSION,new XMIResourceFactoryImpl());

File fichierKDM = new File(Test.getProjectPath());
URI uri = URI.createFileURI(fichierKDM.getAbsolutePath());

Resource modelResource=resourceSet.getResource(uri, true);

Segment segment = (Segment) modelResource.getContents().get(0);

return segment;
}
}

But unfortunately, i got the following exception and i don't know how to fix it:
Exception in thread "main" org.eclipse.emf.ecore.resource.impl.ResourceSetImpl$1DiagnosticWrappedException: org.eclipse.emf.ecore.xmi.PackageNotFoundException: Package with uri 'http://www.eclipse.org/MoDisco/kdm/kdm' not found. (file:/D:/MoDiscoWorkspace/MyModiscoProject/MyModiscoProject_kdm.xmi, 3, 16)
at org.eclipse.emf.ecore.resource.impl.ResourceSetImpl.handleDemandLoadException(ResourceSetImpl.java:315)
at org.eclipse.emf.ecore.resource.impl.ResourceSetImpl.demandLoadHelper(ResourceSetImpl.java:274)
at org.eclipse.emf.ecore.resource.impl.ResourceSetImpl.getResource(ResourceSetImpl.java:397)
at MyModiscoProject.GetSegment.evaluate(GetSegment.java:33)
at MyModiscoProject.Test.main(Test.java:16)
Caused by: org.eclipse.emf.ecore.xmi.PackageNotFoundException: Package with uri 'http://www.eclipse.org/MoDisco/kdm/kdm' not found. (file:/D:/MoDiscoWorkspace/MyModiscoProject/MyModiscoProject_kdm.xmi, 3, 16)
at org.eclipse.emf.ecore.xmi.impl.XMLHandler.getPackageForURI(XMLHandler.java:2591)
at org.eclipse.emf.ecore.xmi.impl.XMLHandler.getFactoryForPrefix(XMLHandler.java:2422)
at org.eclipse.emf.ecore.xmi.impl.XMLHandler.createObjectByType(XMLHandler.java:1299)
at org.eclipse.emf.ecore.xmi.impl.XMLHandler.createTopObject(XMLHandler.java:1468)
at org.eclipse.emf.ecore.xmi.impl.XMLHandler.processElement(XMLHandler.java:1019)
at org.eclipse.emf.ecore.xmi.impl.XMIHandler.processElement(XMIHandler.java:87)
at org.eclipse.emf.ecore.xmi.impl.XMLHandler.startElement(XMLHandler.java:1001)
at org.eclipse.emf.ecore.xmi.impl.XMLHandler.startElement(XMLHandler.java:712)
at org.eclipse.emf.ecore.xmi.impl.XMIHandler.startElement(XMIHandler.java:169)
at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.startElement(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanStartElement(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.next(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(Unknown Source)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(Unknown Source)
at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(Unknown Source)
at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(Unknown Source)
at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(Unknown Source)
at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl.parse(Unknown Source)
at org.eclipse.emf.ecore.xmi.impl.XMLLoadImpl.load(XMLLoadImpl.java:181)
at org.eclipse.emf.ecore.xmi.impl.XMLResourceImpl.doLoad(XMLResourceImpl.java:242)
at org.eclipse.emf.ecore.resource.impl.ResourceImpl.load(ResourceImpl.java:1511)
at org.eclipse.emf.ecore.resource.impl.ResourceImpl.load(ResourceImpl.java:1290)
at org.eclipse.emf.ecore.resource.impl.ResourceSetImpl.demandLoad(ResourceSetImpl.java:255)
at org.eclipse.emf.ecore.resource.impl.ResourceSetImpl.demandLoadHelper(ResourceSetImpl.java:270)
... 3 more
Re: How to process my KDM models [message #1006000 is a reply to message #1005850] Tue, 29 January 2013 09:13 Go to previous messageGo to next message
Hugo Bruneliere is currently offline Hugo Bruneliere
Messages: 600
Registered: July 2009
Senior Member
Hello,

The MoDisco Query Manager has been implemented in order to facilitate the creation of new queries in different languages, including notably Java.
Thus, when defining the body of the evaluate method, the context (i.e. the model element type the query is applied on) is already directly provided to you.
You don't have to implement any tentative access to files or EMF resources.
I encourage you to take a deeper look to the detailed MoDisco Reference Documentation (and its Query Manager section) to get more insights on this.
Generally, the MoDisco Documentation page (as available from the MoDisco homepage) is providing many different types of resources helping you to better understand the framework and its potential usages.

Best regards,

Hugo


------------------------------------------
Hugo Bruneliere - R&D Engineer
AtlanMod research team (Inria, EMN & LINA)
Ecole des Mines de Nantes
Nantes - France
------------------------------------------
Re: How to process my KDM models [message #1006090 is a reply to message #1006000] Tue, 29 January 2013 15:00 Go to previous messageGo to next message
keynne Belle is currently offline keynne Belle
Messages: 21
Registered: January 2013
Junior Member
Thank a lot for the answer. I just read the documentation which helps to make queries. Nevertheless, i think that if i follow that path, analysing 20 projects will oblige me to make 20 query sets. That's the reason why i want to write my queries programatically in order to make them enough general and give to each of them the path of any xmi file i want to process. Then, i'll use this path to get my model elements (segments, code models, compilationUnit, calls and so on). So, can you help me to fix my source code?
Re: How to process my KDM models [message #1006201 is a reply to message #1006090] Wed, 30 January 2013 07:42 Go to previous messageGo to next message
Hugo Bruneliere is currently offline Hugo Bruneliere
Messages: 600
Registered: July 2009
Senior Member
A QuerySet is defined among a given metamodel, but can be applied on as many models as you want as long as these models conform to that metamodel.
In your case, defining your QuerySet among the KDM metamodel, you will be able to use its queries on all the KDM models that you can get from the analyzed projects.

Hugo


------------------------------------------
Hugo Bruneliere - R&D Engineer
AtlanMod research team (Inria, EMN & LINA)
Ecole des Mines de Nantes
Nantes - France
------------------------------------------
Re: How to process my KDM models [message #1006328 is a reply to message #1006201] Wed, 30 January 2013 15:49 Go to previous messageGo to next message
keynne Belle is currently offline keynne Belle
Messages: 21
Registered: January 2013
Junior Member
Thanks for this quick answer. I have another concern: i would like to generate a single xmi file containing all my kdm models (inventory model, code model in the code package, code model in the action package, datamodel and so on). How can i do so?
I also noticed that there is no snippet in my kdm file. What jar files can i download in order to tackle this problem?
Re: How to process my KDM models [message #1006415 is a reply to message #1006328] Thu, 31 January 2013 05:02 Go to previous messageGo to next message
Hugo Bruneliere is currently offline Hugo Bruneliere
Messages: 600
Registered: July 2009
Senior Member
The current versions of the MoDisco Java & KDM discoverers only support the discovery from single projects.
The support for multiple projects as inputs may be developed and added in the future in MoDisco.
In the meantime, a quick fix is to specify yourself another KDM model simply referencing the root "Model" model elements coming from the different discovered models. Thus, loading this "integration" model should also load all the different referenced models.

Concerning your second point, KDM is defined to work at an abstraction level that is not going down to the method implementation details.
If you want models fully representing your projects (i.e. down to the methods internal implementation), you should rather use Java models obtained from the Java model discoverer.

Hugo


------------------------------------------
Hugo Bruneliere - R&D Engineer
AtlanMod research team (Inria, EMN & LINA)
Ecole des Mines de Nantes
Nantes - France
------------------------------------------
Re: How to process my KDM models [message #1006598 is a reply to message #1006415] Fri, 01 February 2013 01:48 Go to previous messageGo to next message
keynne Belle is currently offline keynne Belle
Messages: 21
Registered: January 2013
Junior Member
Hello. thanks again for the answers.
I'm working with the MoDisco distribution available with Eclipse Indigo. I attached a file showing all the discoverers that i found there. when i parse my kdm code model, i'm able to get some ActionElement of my java project. Nevertheless, when i invoke the "getOutBound" method on each of these ActionElement in order to get all their outgoing KDMRelationships, i always get a "null" value, whereas the MoDisco Model Browser indicates that my code model contains Calls going from the ActionElement contained in my project. So, i would like to know, if i'm not using the right method to get these outgoing KDMRelationships or if i there is an alternative to get them.

[Updated on: Fri, 01 February 2013 01:57]

Report message to a moderator

Re: How to process my KDM models [message #1006669 is a reply to message #1006598] Fri, 01 February 2013 06:27 Go to previous messageGo to next message
Hugo Bruneliere is currently offline Hugo Bruneliere
Messages: 600
Registered: July 2009
Senior Member
Looking to a KDM model opened into the MoDisco Model Browser, on an ActionElement the relationship to access to the Calls elements is named actionElement.
You could try to use this relation to get the Calls model elements.

Hugo


------------------------------------------
Hugo Bruneliere - R&D Engineer
AtlanMod research team (Inria, EMN & LINA)
Ecole des Mines de Nantes
Nantes - France
------------------------------------------
Re: How to process my KDM models [message #1008566 is a reply to message #1006669] Tue, 12 February 2013 23:20 Go to previous message
keynne Belle is currently offline keynne Belle
Messages: 21
Registered: January 2013
Junior Member
thank you for all your answers. they really helped.
Previous Topic:Help with KDM transformation
Next Topic:Small API break to be compatible with Helios
Goto Forum:
  


Current Time: Tue Jul 29 09:02:34 EDT 2014

Powered by FUDForum. Page generated in 0.02797 seconds