How to find out the module in which an element is located

MagicDraw OpenAPI, scripting related questions and discussions

Moderator: Moderators

How to find out the module in which an element is located

Postby Thomas Zimber » Wed Jun 13, 2007 2:01 am

Is there any way to find out the module in which an element is located?

Project.getProject(BaseElement) returns the Project using the module.


Thomas Zimber
 
Posts Rating:

Re: How to find out the module in which an element is located

Postby Martynas Lelevicius » Thu Jun 14, 2007 1:37 am

Hello,

Here is the code sample:

/**
* Find given element's module.
* @param element
* @return module descriptor if element is in moule, otherwise - null.
*/
ModuleDescriptor getModuleDescriptor(Element element)
{
HashMap mountPointMap = new HashMap();
fillMap(Project.getProject(element), mountPointMap);
// find element in map
ModuleDescriptor module;
do
{
String id = element.getID();
module = (ModuleDescriptor) mountPointMap.get(id);
element = (Element) element.getOwner();
}
while(module == null && element != null);

return module;
}

/**
* Fill map recursively: module root id ==> module descriptor.
* @param modulesManager
* @param mountPointMap map to fill.
*/
void fillMap(ModulesManager modulesManager, Map mountPointMap)
{
Collection modules = modulesManager.getMountTable().getModules();
for (Iterator it = modules.iterator(); it.hasNext();)
{
ModuleDescriptor moduleDescriptor = (ModuleDescriptor) it.next();
if (!mountPointMap.values().contains(moduleDescriptor))
{
Collection mounts = moduleDescriptor.getMounts();
for (Iterator it2 = mounts.iterator(); it2.hasNext();)
{
MountInfo mountInfo = (MountInfo) it2.next();
mountPointMap.put(mountInfo.getMountPointID(), moduleDescriptor);
}
fillMap(moduleDescriptor, mountPointMap);
}
}
}

Regards,
--
Martynas Lelevicius
Programmer
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 : marte
WWW: http://www.magicdraw.com

----- Original Message -----
From: "nntp://news.nomagic.com/nomagic.products.magicdrawuml.openapi"
<tzimber>
To: "Martynas Lelevicius" <marlel>
Sent: Wednesday, June 13, 2007 11:06 AM
Subject: How to find out the module in which an element is located


> Is there any way to find out the module in which an element is located?
>
> Project.getProject(BaseElement) returns the Project using the module.
>

Martynas Lelevicius
 
Posts Rating:


Return to Programmatic Extendibility

Who is online

Users browsing this forum: No registered users and 1 guest