Failed to load Papyrus model with MARTE Stereotypes in standalone application [message #899662] |
Wed, 01 August 2012 17:36 |
Alfredo Motta Messages: 41 Registered: June 2012 |
Member |
|
|
Hello everybody,
I have a standalone application that is trying to use UML2 library to load a Papyrus model with MARTE stereotypes. I am working on this since a couple of days, hope someone could help
The model is a toy model, with one class and one stereotype applied to it. It's already a couple of days that I am trying to solve the problem without success, wondering if you could help me.
The model is the one attacched containing one class with one MARTE stereotype applied. Here is the code I am using to load the model in the standalone app.
public static Model getModel(String pathToModel){
//A collection of related persistent documents.
ResourceSet set = new ResourceSetImpl();
//Register the UML Package
set.getPackageRegistry().put(UMLPackage.eNS_URI, UMLPackage.eINSTANCE);
set.getResourceFactoryRegistry().getExtensionToFactoryMap().put(UMLResource.FILE_EXTENSION, UMLResource.Factory.INSTANCE);
//Register the MARTE package
set.getPackageRegistry().put(org.eclipse.papyrus.MARTE.MARTE_Foundations.Time.TimePackage.eNS_URI, org.eclipse.papyrus.MARTE.MARTE_Foundations.Time.TimePackage.eINSTANCE);
set.getResourceFactoryRegistry().getExtensionToFactoryMap().put(UMLResource.PROFILE_FILE_EXTENSION, UMLResource.Factory.INSTANCE);
//Define Location for marte
set.getURIConverter().getURIMap().put(URI.createURI("pathmap://Papyrus_PROFILES/MARTE.profile.uml"), URI.createFileURI(new File("input/MARTE.profile.uml").getAbsolutePath()));
//Add the model file to the resource set
URI uri = URI.createFileURI(pathToModel);
set.createResource(uri);
Resource r = set.getResource(uri, true);
LOGGER.info("Printing the content of the model resouce");
for(EObject o: r.getContents()){
LOGGER.info(o);
EcoreUtil.resolveAll(o);
}
Model m=(Model)EcoreUtil.getObjectByType(r.getContents(), UMLPackage.eINSTANCE.getModel());
return m;
}
and this is the code printing the stereotypes applied to the elements. I would expect the retrieve the MARTE ClockType stereotype from the class, but this is not the case.
LOGGER.info("Load the model");
Model m=ModelDecorator.getModel(model_file);
LOGGER.info("Printing applied profiles");
LOGGER.info(m.getAppliedProfiles());
LOGGER.info("Printing stereotypes");
for(Element e: m.allOwnedElements()){
LOGGER.info("Element " + e + " has the following stereotypes");
LOGGER.info(e.getAppliedStereotypes());
}
This is the corresponding output
Printing the content of the model resouce
org.eclipse.uml2.uml.internal.impl.ModelImpl@7215fb38 (name: model, visibility: <unset>) (URI: null) (viewpoint: <unset>)
org.eclipse.papyrus.MARTE.MARTE_Foundations.Time.impl.ClockTypeImpl@664310d0 (nature: discrete, isLogical: false)
Printing applied profiles
[org.eclipse.uml2.uml.internal.impl.ProfileImpl@395d601f (name: Time, visibility: <unset>) (URI: null)]
Printing model element stereotypes
Element org.eclipse.uml2.uml.internal.impl.ClassImpl@154e45b3 (name: RadarClock, visibility: <unset>) (isLeaf: false, isAbstract: false, isFinalSpecialization: false) (isActive: false) has the following stereotypes
[] --> this should have the ClockType Stereotype according to the model
Element org.eclipse.uml2.uml.internal.impl.ProfileApplicationImpl@75d252d (isStrict: false) has the following stereotypes
[]
Attached the model the and the MARTE profiles.
In order to get this work I changed in the MARTE profile the UML2 version from this xmlns:uml="http://www.eclipse.org/uml2/3.0.0/UML" to this xmlns:uml="http://www.eclipse.org/uml2/4.0.0/UML". Otherwise the types were not recognized correctly.
Thank you so much for your help
[Updated on: Wed, 01 August 2012 17:38] Report message to a moderator
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.06461 seconds