Skip to main content

Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » UML2 » How to load and use MARTE profile(Use MARTE stereotypes in a standalone Java application)
How to load and use MARTE profile [message #1805653] Fri, 19 April 2019 16:57
daniele di pompeo is currently offline daniele di pompeoFriend
Messages: 20
Registered: February 2015
Junior Member
Hi everyone,
I'm trying to use MARTE profile in a standalone java application.

First of all, I register all needed packages and factories into the registries as follows:

ResourceSet set = UMLResourcesUtil.init(new ResourceSetImpl());
set.getPackageRegistry().put(UMLPackage.eNS_URI, UMLPackage.eINSTANCE);
set.getPackageRegistry().put(StandardPackage.eNS_URI, StandardPackage.eINSTANCE);
set.getPackageRegistry().put(MARTEPackage.eNS_URI, MARTEPackage.eINSTANCE);
set.getPackageRegistry().put(GQAMPackage.eNS_URI, GQAMPackage.eINSTANCE);

By analyzing the registry, I'm sure that it contains all stereotypes, thus I cannot understand where is the problem.

Then, I load the UML model as follows:

UMLResource umlResource = (UMLResource) getResourceSet().getResource(manager.string2FileUri(sourcePath.toString()), true);
return (Model) EcoreUtil.getObjectByType(umlResource.getContents(), UMLPackage.Literals.MODEL);

Thus, I use OCL programmatically to retrieve objects with a specific MARTE stereotype from the model, here a query example:

String query = "Node.allInstances()->select(node : Node | node.getAppliedStereotypes()->exists(s | = 'GaExecHost'))->size()"

//Query is the OCL query and contextualElement is the model Root (i.e., a Model)
public Object evaluateOCL(String query, Model contextualElement) throws ParserException {
	// create an OCL instance for Ecore
	OCL<?, EClassifier, ?, ?, ?, ?, ?, ?, ?, Constraint, EClass, EObject> ocl;
	ocl = OCL.newInstance(EcoreEnvironmentFactory.INSTANCE);
	// create an OCL helper object
	OCLHelper<EClassifier, ?, ?, Constraint> helper = ocl.createOCLHelper();
	// helper.setInstanceContext(UMLPackage.eINSTANCE.getClass_());
	OCLExpression<EClassifier> oclExpression = helper.createQuery(query);
	Query<EClassifier, EClass, EObject> oclQuery = ocl.createQuery(oclExpression);
	//this should return the number of Nodes stereotyped with GaExecHost (it should be 8, but it always returns 0
	return oclQuery.evaluate(contextualElement);

I have also installed the OCL plugin in Eclipse to try the query that works well. Hence, I think that the problem is related to the profile registration.

My configuration is:
-- I have created the model with MagicDraw.
-- I'm using Eclipse for RCP and RAP Developers Oxygen 4.7.0
-- Java 8
-- I build the project with Maven
-- I don't know if it is relevant, but I'm using JUnit 4.

I would like to share the project with you, but it is a big project.
Please find attached the UML model.

Any suggestion?
  • Attachment:
    (Size: 1.24MB, Downloaded 72 times)
Previous Topic:Tag elements of a sequence diagram in an emx file (UML2)
Next Topic:Profiles doesn't work correctly in XMI-serialized UML
Goto Forum:

Current Time: Fri Aug 12 15:37:12 GMT 2022

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

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

Back to the top