file [SOLVED]How to obtain IAssociationEnd from an IModelElement

5 years 9 months ago - 5 years 9 months ago #2835 by Nico42
Hello,

I'm using the Modelio 2.2 with the Java API.

I've been trying to understand how to identify which are the elements linked together, but my mind has been too confused with the not-updated documentation and/or not working examples.

So i have an IModelElement which is linked to another IModelElement with an IAssociation element.
ex: IModelElement A -> IAssociation -> IModelElement B

I know how to get every element separatly, but i can't identify which element is linked to this element.

Any idea ?

Thx

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

5 years 9 months ago - 5 years 9 months ago #2836 by ebr
Hi,

To obtain this kind of information please take a look at the Modelio 2.2 metamodel documentation as you will see the IAssociation elements connect IClassifier elements in the following way.
IClassifier A -> IAssociationEnd EndA -> IAssociation Link -> IAssociationEnd EndB -> IClassifier B

Hoping it helps,

EBR
The following user(s) said Thank You: Nico42

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

5 years 9 months ago #2837 by Nico42
Why i never found this bible ? :o

thx, will help a lot i guess.

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

5 years 9 months ago #2838 by Nico42
Well, my probleme stays the same, I can't get anything from my ModelElement, no know way to convert it to IClassifier, nothing in the getConnector, getConnectorEnd nor from any kind of get(list) method.

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

5 years 9 months ago - 5 years 9 months ago #2840 by ebr
I am a little bit confused you want to get all IModelElement B associated (and not linked) to an IModelElement A i.e. having an IAssociation and not an ILink between them, right?
if so please take a look at the following code
IModelElement A;

List<IModelElement> linkedB = new ArrayList<>();
			
//test type of IModelElement A
if (A instanceof IClassifier){
	//for each IAssociationEnd endAowned by A
	for (IAssociationEnd endA : ((IClassifier) A).getPart(IAssociationEnd.class)){
	 	//get endB the opposite end of endA 
		for (IAssociationEnd endB : endA.getOppositeEnds()){
			// return the endB owner
			IModelElement B = endB.getOwner();
			if (!linkedB.contains(B))
				linkedB.add(B);
			}
		}
	}
The following user(s) said Thank You: Nico42

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

5 years 9 months ago - 5 years 9 months ago #2841 by Nico42
Well done.

It's exactly what i need. I think i'm not used to what i can cast and what i cant, gotta learn the Modelio achitecture.

Nevertheless, Modelio's object are not intuitive at all for a beginner :D
I think i'll need your help again ebr !

Thx sir.

ps: btw i dont even know the difference between ILinks and IAssociation, but yea it was IAssociation, i edited my 1st post to avoid confusion

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

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