Get all elements with stereotype X applied [message #797293] |
Mon, 13 February 2012 09:38 |
Michael Bob Messages: 29 Registered: February 2012 |
Junior Member |
|
|
Hi,
I am looking for a comfortable way to get all elements within a UML model with a certain stereotype X applied.
EList<Element> list = model.allOwnedElements();
for (Element e : list) {
if (e.isStereotypeApplied(X)) {
System.out.println(e);
}
}
Is this the only way? Or is there a more comfortable alternative?
Regards,
Michael
[Updated on: Mon, 13 February 2012 09:38] Report message to a moderator
|
|
|
|
|
Re: Get all elements with stereotype X applied [message #809224 is a reply to message #797293] |
Tue, 28 February 2012 16:04 |
Kenn Hussey Messages: 1620 Registered: July 2009 |
Senior Member |
|
|
Michael,
Your code won't actually find elements with the stereotype applied, but
rather the elements to which the stereotype is applicable (i.e., could
legally be applied). You'd want to use the
Element#isStereotypeApplied(Stereotype) operation.
Another more direct, and possibly more efficient, way of doing this (but
which relies more on the underlying implementation details) would be to
iterate over the contents of the resource(s) containing the elements,
looking for stereotype applications using UMLUtil#getStereotype(EObject)
and, upon finding ones that correspond to the stereotype in question,
retrieve (and rememeber) their "base" elements using
UMLUtil#getBaseElement(EObject).
Kenn
On 12-02-13 4:38 AM, Michael Gebhart wrote:
> Hi,
>
> I am looking for a comfortable way to get all elements within a UML
> model with a certain stereotype X applied.
> EList<Element> list = model.allOwnedElements();
> for (Element e : list) {
> if (e.isStereotypeApplicable(X)) {
> System.out.println(e);
> }
> }
>
>
> Is this the only way? Or is there a more comfortable alternative?
>
> Regards,
>
> Michael
|
|
|
Powered by
FUDForum. Page generated in 0.30627 seconds