file Obtaining all elements that have a certain stereotype

4 years 7 months ago #3458 by ebr
Hi ua,

Do you mean with some java code, a script or the gui?

I attached a search example below. BTW only ModelElement can be stereotyped.



Regards
Attachments:

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

4 years 7 months ago #3461 by ua138
I referred to the code. I have solved as I share below. But I still wonder if it is possible to obtain all the stereotypes defined in the system or in a module. I have read in the documentation that you can get the stereotypes from the method getStereotype from IMetamodelExtensions class, but the methods require to explicitly give at least the stereotype name. Is there any way of obtaining all the existing requirements in the system withoy specifying concrete names?

	public ArrayList<MObject> getElementsByStereotype(
			ArrayList<Stereotype> stereotypeVector) {
		ArrayList<MObject> selection= new ArrayList<MObject>();

		for (Stereotype stereotype : stereotypeVector) {
			selection= getAllElementsStereotypedAs(linesHeader,
					stereotype.getName());
		}

		return selection;
	}

	public ArrayList<MObject> getAllElementsStereotypedAs(
			ArrayList<MObject> list, String stereotype) {
		ArrayList<MObject> allElements = getAllElements();
		for (MObject object : allElements) {
			if (((ModelElement) object).isStereotyped(
					IRCasePeerModule.MODULE_NAME, stereotype))
				list.add(object);
		}

		return list;
	}

public ArrayList<MObject> getAllElements() {
		ArrayList<MObject> vector = new ArrayList<MObject>();
		IModelingSession session = Modelio.getInstance().getModelingSession();
		for (MObject rootObj : session.getModel().getModelRoots()) {

			if (((rootObj instanceof GeneralClass) || (rootObj instanceof Project))
					&& (!rootObj.getName().equals("LocalModule"))) {

				for (MObject child : rootObj.getCompositionChildren()) {
					vector = getElementsFromMObject(vector, child);
				}

			}
		}
		return vector;
	}


Thank you very much for the response

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

4 years 7 months ago - 4 years 7 months ago #3463 by ebr
Do you want to obtain all elements stereotyped by a specific stereotype or all requirements?

If you want to find all elements stereotyped by a given stereotype, you have to specify somehow this stereotype, right? So you can select your stereotype in the GUI and then launch your search or you can obtain this stereotype thanks to its name and its module owner and then launch your search.Does it helps? Do you see another usecase/way?

EBR

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

4 years 7 months ago #3464 by ua138
When you program the module.xml file, you are able to declare certain stereotypes, e.g.:
 <Stereotype name="My Stereotype" metaclass="UseCase" is-hidden="false" label="Use Case" uid="3de1e727-2eaa-446e-a61f-4df78ee9ec09">
                <Icon path="res/icons/usecase_16.png"/>
                <Image path="res/icons/usecase_16.png"/>
<TagTypes/>
</Stereotype>

I would like to get all the stereotypes that the system have, without specifying that i want "My Stereotype". I want all stereotypes of the system. Is it possible to obtain that?

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

4 years 7 months ago #3467 by ebr
I am a little bit lost here but if you want all available stereotype the following line of code should be enough.
Collection<Stereotype> allstereotype = Modelio.getInstance().getModelingSession().findByClass(Stereotype.class);

Regards,

EBR

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

4 years 7 months ago #3468 by ua138
Thank you very much for your response!

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

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