file How to access the root package in modelio 3.3

4 years 11 months ago - 4 years 11 months ago #3249 by ua138
How can the root package be accessed in Modelio 3.3? I am not able to find any documentation related to it.

The following line is outdated:
IPackage root = session.getModel().getRoot();

I have tried to do
Package root = (Package) session.getModel().getRoot(null)
But it gives a null pointer exception.


In the documentation says that getRoot() method of the IUMLModel class needs as imput and returns MObject. So I have also tried:
for (MObject rootObj : session.getModel().getModelRoots()) {
	    	    if (rootObj instanceof Project) {
	    	 
	    	         // Get the root package
	    	         Package root =  ((Project) rootObj).getModel();

But it does not work to.

What can I do to obtain the main package in Modelio 3.3?

Please Log in or Create an account to join the conversation.

4 years 11 months ago - 4 years 11 months ago #3250 by ebr
Hi ua138,

If we imagine that you have the following structure.



The following line will give you acces to the package named project1
print modelingSession.getModel().getModelRoots().get(0).getModel()

Hoping it helps,

EBR
Attachments:

Please Log in or Create an account to join the conversation.

4 years 5 months ago - 4 years 5 months ago #3596 by asefth
Hi,

I'm surprised not to be able to do very simple things.
As concepts are clear for me, I must be on a wrong way with using incorrect syntax.

e.g. model navigation:

I can get the session in an object session
IModelingSession session = Modelio.getInstance().getModelingSession();

But I can't get the root package for navigating in the model, with the following code:
Package root = session.getModel().getRoot();

As exactly expressed in the wiki Developer Manual-API :
http://forge.modelio.org/projects/modelio3-moduledevelopersmanuals-api/wiki/Model_services

The same with
getModel().getModelRoots().get(0).getModel()

as described in
Modelio Dev Manual API

Can you pls. indicate me what is the right way for doing that and where is the reference up-to-date documentation (API, reference examples, targeted tutorials)?
EDIT : API is fine. Small validated examples with clear indication about the setup used for the example would be appreciated.
(purpose: developping a module)

Thanks
Regards

Please Log in or Create an account to join the conversation.

4 years 5 months ago - 4 years 5 months ago #3597 by ua138
.
The following user(s) said Thank You: asefth

Please Log in or Create an account to join the conversation.

4 years 5 months ago #3598 by pan
Hi asefth,

It's pretty random to use get($i) because we don't know necessarily the position of the target model.

I suggest you to test the name of the project.
IModelingSession session = Modelio.getInstance().getModelingSession();

for rootObj in session.getModel().getModelRoots(){
	if (rootObj instanceof Project) {
		root = rootObj.getModel();
		if (root.getName().equals("A Project name")) {
			//Do something
		}
	}
}

Hope this helps

Please Log in or Create an account to join the conversation.

4 years 5 months ago - 4 years 5 months ago #3601 by asefth
Hi pan,

starting from your code, I finally get to the following with no error (with the relevant import org.***)
import org.modelio.api.model.*;
import org.modelio.api.modelio.Modelio;
import org.modelio.metamodel.mda.Project;
import org.modelio.metamodel.uml.statik.Package;
import org.modelio.vcore.smkernel.mapi.MObject;

public class Test {
	
	public static void getRootOfMyModel() {
		IModelingSession session = Modelio.getInstance().getModelingSession();
		for (MObject rootObj : session.getModel().getModelRoots() ) {
			if (rootObj instanceof Project) {
				Package root = ((Project) rootObj).getModel();
				if (root.getName().equals("A Project name")) {
					//Do something
				}
			}
		}
	}
}

PS : 'for' requires parenthesis in my seutp (it may be a meaningless error in your quick example; or you have a library that allows not to use parenthesis!)

So, it appears to be a problem that could be avoided thanks to:
- an accurate knowledge about the top elements (I understand: Project and Models and Models'root within Modelio)
- the strict respect of object's type declaration (e.g. MObjet rootObj instead of rootObj)
- and about the required packages (which is the easiest requirement)

In order to avoid to lose time with that kind of problem, what is the "central point" to look at ?
Is it the Metamodel user guide ?

Thanks
Regards

Please Log in or Create an account to join the conversation.

Moderators: tmachmaab
Time to create page: 0.153 seconds
^ Back to Top