Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » UML2 » Get all elements with stereotype X applied
Get all elements with stereotype X applied [message #797293] Mon, 13 February 2012 09:38 Go to next message
Michael Bob is currently offline Michael BobFriend
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 #797455 is a reply to message #797293] Mon, 13 February 2012 14:03 Go to previous messageGo to next message
Peter Mising name is currently offline Peter Mising nameFriend
Messages: 95
Registered: July 2009
Member
Hi Michael,
maybe not more comfortable but faster is this way:

for (EObject ob : resourceModel.getContents()) {
if (ob instanceof DynamicEObjectImpl) {
if (((DynamicEObjectImpl)ob).eClass().getName().equals("X")) {
for (EObject feature : ob.eClass().getEAllStructuralFeatures()) {
if (feature instanceof EReference) {
if (((EReference)
feature).getName().startsWith(Extension.METACLASS_ROLE_PREFIX)) {
Object appliedUMLElement = ob.eGet((EStructuralFeature) feature);
if (appliedUMLElement != null) {
System.out.println(appliedUMLElement); }
else{
System.out.println("broken Stereotype "+ob);
}break;
}
}

}
}
}
}

Am 13.02.2012 10:38, schrieb Michael Gebhart:
> 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
Re: Get all elements with stereotype X applied [message #797577 is a reply to message #797293] Mon, 13 February 2012 17:00 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
Registered: July 2009
Senior Member
Hi Michael

This doesn't help you today, but I consider many of the difficulties in
the use of profiles to be a bug in at least Eclipse OCL and probably the
OMG OCL specification too. The OCL model loading environment should make
models available in a form that makes navigation easy for OCL and for
tools that can exploit OCL.

Regards

Ed Willink


On 13/02/2012 09:38, 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
Re: Get all elements with stereotype X applied [message #809224 is a reply to message #797293] Tue, 28 February 2012 16:04 Go to previous message
Kenn Hussey is currently offline Kenn HusseyFriend
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
Previous Topic:Sources for current Indigo 3.2.100 version in git
Next Topic:URI.createURI
Goto Forum:
  


Current Time: Tue Apr 16 12:24:31 GMT 2024

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

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

Back to the top