Possible Bug, or is it a Feature?

MagicDraw OpenAPI, scripting related questions and discussions

Moderator: Moderators

Possible Bug, or is it a Feature?

Postby Kristina Hildebrand » Thu Dec 22, 2005 10:32 am

I just discovered that ElementFinder.find(Element root,
Class type,
String name,
Collection results,
boolean searchInChildren)

Will not find, for example, an Operation, if you pass it a type of

I needed to look for either Properties or Operations (in my model, the
chances of NamedElements within a Class being anything else are slim to

//I had something sort of like this:
Collection items = new ArrayList();
ElementFinder.find(c, NamedElement.class, clientFunction, items, true);

//And, had to change it to something like this:
ElementFinder.find(c, Operation.class, clientFunction, items, true);
if (items.size() == 0)
ElementFinder.find(c, Property.class, clientFunction, items, true);

That's not my exact code, so I don't know if that works or not (I've got
a helper method of my own to do the call to ElementFinder and sort
through the resulting Collection), but I'm curious as to whether this is
the intended functionality, and if not, I wanted to let you guys know
about the potential bug.

I would think ElementFinder.find() should be able to find any
NamedElements under the root that have the given name, shouldn't it? I
would think that would be part of the point of having the option of
putting the results in a Collection, rather than returning just one
item. The first sample of code gave a collection of size 0. The second
sample finds the Operation or Property perfectly, with nothing else
having changed.

~Kristina Hildebrand
Kristina Hildebrand
Posts Rating:

RE: Possible Bug, or is it a Feature?

Postby Tomas Pugzlys » Fri Dec 23, 2005 7:28 am


>ElementFinder.find(c, NamedElement.class, clientFunction, items, true);
ElementFinder.find method searches for model elements instances with exact
type NamedElement.
Subtypes (such as Operation and Property types) are not included in search.

You may specify subtypes of NamedElement in the following way:
List subtypes = ClassTypes.getSubtypes(NamedElement.class);
java.lang.Class[] types = (java.lang.Class[]) subtypes.toArray(new
ElementFinder.find(c, types, clientFunction, items, true);

ElementFinder.find(...) methods are more optimized for searching large model

So you may get better performance by using the following methods:

>In my model, the chances of NamedElements within a Class being anything
else are slim to none
You may also need to consider that a class may have inner classes.

Tomas Pugzlys
No Magic Lithuanian Development Center
Savanoriu pr. 363, LT-49425, Kaunas
P.O. box 2166, LT-44011, Kaunas
Phone: +370 37 324032 Fax: +370 37 320670
e-mail : tomasp
WWW: http://www.magicdraw.com

Tomas Pugzlys
Posts Rating:

Return to Programmatic Extendibility

Who is online

Users browsing this forum: No registered users and 1 guest