How to import a module from OpenAPI

MagicDraw OpenAPI, scripting related questions and discussions

Moderator: Moderators

How to import a module from OpenAPI

Postby Thomas Zimber » Fri May 25, 2007 1:53 am

I'm trying to import a project file in an existing project using the
following lines of code:

ProjectsManager manager = Application.getInstance().getProjectsManager();
ProjectDescriptor importDescriptor =
ProjectDescriptorsFactory.createLocalProjectDescriptor(null, importFile);
try {
manager.importModule(manager.getActiveProject(), importDescriptor);
} catch (ReadOnlyElementException e) {
e.printStackTrace();
}

I've tried also:

ProjectsManager manager = Application.getInstance().getProjectsManager();
Project importProject = manager.createProject();
ProjectDescriptor importDescriptor =
ProjectDescriptorsFactory.createLocalProjectDescriptor(importProject,
importFile);
try {
manager.importModule(manager.getActiveProject(), importDescriptor);
} catch (ReadOnlyElementException e) {
e.printStackTrace();
}

The result is allways the same:
java.lang.IllegalArgumentException: module not found
at
com.nomagic.magicdraw.core.project.ProjectsManager.importModule(ProjectsManager.java:633)

The same file can be imported using the Menu entry 'Import MagicDraw Project
...' works fine.



Thomas Zimber
 
Posts Rating:

Re: How to import a module from OpenAPI

Postby Martynas Lelevicius » Sun May 27, 2007 10:27 pm

Hello,

Unfortunately MagicDraw project importing through OpenAPI is not possible.

ProjectsManager.importModule() method imports the module used by project.
So you receive exception, because the project does not have the module you
specify.

Sorry for the inconveniences.
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

Martynas Lelevicius
 
Posts Rating:

Re: How to import a module from OpenAPI

Postby Thomas Zimber » Sun Jun 10, 2007 3:27 am

I have trie now to import the file by first loading the file as a module,
unsing the following lines of code:

ProjectsManager manager = Application.getInstance().getProjectsManager();
Project activeProject = manager.getActiveProject();
ProjectDescriptor importDescriptor =
ProjectDescriptorsFactory.createLocalProjectDescriptor(null, importFile);
try {
ModuleDescriptor importedModule =
activeProject.getMountTable().mountModule(importDescriptor);
SimpleProgressStatus progressStatus = new SimpleProgressStatus() {};
activeProject.getMountTable().addModule(importedModule);
activeProject.getMountTable().loadModule(importedModule, progressStatus);
activeProject.getMountTable().importModule(importedModule);
} catch (IOException e) {
e.printStackTrace();
}

but I got the following exception:
java.io.IOException: can not import not loaded module!
at com.nomagic.magicdraw.core.modules.a.f.importModule(f.java:190)

I've tried to wait for progressStatus.isCompleted() in a own thread, but I'm
running in an endless loop.

How can I load a file as a module into the current project?

"Martynas Lelevicius" <marte> wrote in message
news:13290530.1180332973034.JavaMail.tadjar@peleda...
> Hello,
>
> Unfortunately MagicDraw project importing through OpenAPI is not possible.
>
> ProjectsManager.importModule() method imports the module used by project.
> So you receive exception, because the project does not have the module you
> specify.
>
> Sorry for the inconveniences.
> 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
>


Thomas Zimber
 
Posts Rating:

Re: How to import a module from OpenAPI

Postby Martynas Lelevicius » Mon Jun 11, 2007 3:46 am

Try to import the module such way:

ProjectDescriptor module =
ProjectDescriptorsFactory.createProjectDescriptor(moduleProjectFile.toURI());
MountTable mountTable = project.getMountTable();

try
{
ModuleDescriptor moduleDescriptor = mountTable.mountModule(module);
mountTable.loadModule(moduleDescriptor, new SimpleProgressStatus());
mountTable.importModule(moduleDescriptor);
}
catch (IOException e)
{
e.printStackTrace();
}


Do not forget that module project must share at least one package.

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

Martynas Lelevicius
 
Posts Rating:


Return to Programmatic Extendibility

Who is online

Users browsing this forum: No registered users and 1 guest