Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » MoDisco » How can i persist a new created KDM model?
How can i persist a new created KDM model? [message #1221971] Thu, 19 December 2013 02:23 Go to next message
keynne Belle is currently offline keynne BelleFriend
Messages: 30
Registered: January 2013
Member
Hi.
I have discovered a java project to generate its KDM representation using the KDM code model discoverer. The segment of this KDM representation comprises 3 models (2 code models and an inventory model). I then created a new structure model and added it to this segment, but the new structure model is not persisted in the segment. Which instructions should i add to the ones below in order to persist the new structure model?
StructureModel structureModel = StructureFactory.eINSTANCE.createStructureModel();
//Retrieve all the models contained in the segment
EList<KDMModel> allTheProjectModels = segment.getModel();
allTheProjectModels.add(structureModel);
Thanks in advance.
Re: How can i persist a new created KDM model? [message #1222086 is a reply to message #1221971] Thu, 19 December 2013 16:31 Go to previous messageGo to next message
Hugo Bruneliere is currently offline Hugo BruneliereFriend
Messages: 674
Registered: July 2009
Senior Member
Hello,

When doing calling to allTheProjectModels.add(structureModel);, you're just adding your "structure" model to a variable storing a list of KDM models.
But you are not adding this "structure" model to any particular element of an EMN Resource that you could then save/serialize.


--------------------------------------------------------
Hugo Bruneliere, PhD
NaoMod team (IMT Atlantique & LS2N-CNRS)
Nantes - France
--------------------------------------------------------
Re: How can i persist a new created KDM model? [message #1222087 is a reply to message #1222086] Thu, 19 December 2013 16:34 Go to previous messageGo to next message
Hugo Bruneliere is currently offline Hugo BruneliereFriend
Messages: 674
Registered: July 2009
Senior Member
To complement my previous post, you should take a look to the structure of the KDM metamodel in order to identify which reference of which model element you have to use in order to actually "add" your newly created model element into the KDM model.

--------------------------------------------------------
Hugo Bruneliere, PhD
NaoMod team (IMT Atlantique & LS2N-CNRS)
Nantes - France
--------------------------------------------------------
Re: How can i persist a new created KDM model? [message #1222202 is a reply to message #1222087] Thu, 19 December 2013 22:27 Go to previous messageGo to next message
keynne Belle is currently offline keynne BelleFriend
Messages: 30
Registered: January 2013
Member
Thank you. Your explanations really helped me to persist my structure model.
I have another question about the StructureModel. I have populated my structure model with components and I created and saved the 9 structure relationships between these components. However, when i open my KDM representation with the MoDisco browser, i see the 9 structure relationships among the Types but i do not see these relationships among the Instances of my segment (in the tree viewer). I have attached a file to illustrate my problem. Below are the main instructions i use to create a structure relationship between two components. Could you help me figure out what is wrong with my code?

//create a new structure model
//populate the structure model with new components
//use the method below in a loop to create the structure relationships

private void createAStructureRelationship(Resource resourceModel, Component startComponent,
Component endComponent){
StructureRelationship structureRelation = StructureFactory.eINSTANCE.createStructureRelationship();
structureRelation.setFrom(startComponent);
structureRelation.setTo(endComponent);
EList<AbstractStructureRelationship> outgoingRelations = startComponent.getStructureRelationship();
outgoingRelations.add(structureRelation);
//add the structure relationship to the resource
resourceModel.getContents().add(structureRelation);

}

//add the structure model to the KDM segment
//add the KDM segment to the resource model
//save the resource model using the instruction : resourceModel.save(null);

[Updated on: Thu, 19 December 2013 22:39]

Report message to a moderator

Re: How can i persist a new created KDM model? [message #1222357 is a reply to message #1222202] Fri, 20 December 2013 08:27 Go to previous messageGo to next message
Hugo Bruneliere is currently offline Hugo BruneliereFriend
Messages: 674
Registered: July 2009
Senior Member
It seems you are not adding the outgoingRelations to the correct element in the model.
You have to add these elements to the structureRelationship property of a Component model element.
Adding them at the root of the model (this is what you are doing when calling to resourceModel.getContents()) is not correct.


--------------------------------------------------------
Hugo Bruneliere, PhD
NaoMod team (IMT Atlantique & LS2N-CNRS)
Nantes - France
--------------------------------------------------------
Re: How can i persist a new created KDM model? [message #1222457 is a reply to message #1222357] Fri, 20 December 2013 13:29 Go to previous message
keynne Belle is currently offline keynne BelleFriend
Messages: 30
Registered: January 2013
Member
Thank you so much for your help. I deleted the instruction resourceModel.getContents().add(structureRelation); and i directly added the structure relationship to the start component as follow and it worked Smile

private void createAStructureRelationship(Resource resourceModel, Component startComponent,
Component endComponent){
StructureRelationship structureRelation = StructureFactory.eINSTANCE.createStructureRelationship();
structureRelation.setFrom(startComponent);
structureRelation.setTo(endComponent);
//add the structure Relationship to the component
startComponent.getStructureRelationship().add(structureRelation);

}
Previous Topic:How can i generate a KDM code model programatically?
Next Topic:enable discoverers' stack-trace / activity-logging
Goto Forum:
  


Current Time: Thu Mar 28 10:37:43 GMT 2024

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

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

Back to the top