Class CommandLine

java.lang.Object
com.nomagic.magicdraw.commandline.CommandLine
Direct Known Subclasses:
ProjectCommandLine

@OpenApiAll public abstract class CommandLine extends Object
MagicDraw commandline launcher.
Extend it and implement execute() method.

Code sample:

public class TestCommandLine extends CommandLine
 {
        public static void main(String[] args)
     {
                new TestCommandLine().launch(args);
     }

        protected void execute()
     {
                // load project
                File fileToLoad = new File("myProject.mdzip");
                ProjectDescriptor descriptor = ProjectDescriptorsFactory.createProjectDescriptor(fileToLoad.toURI());
                ProjectsManager projectsManager = Application.getInstance().getProjectsManager();
                projectsManager.loadProject(descriptor, true);

                Project project = Application.getInstance().getProject();

                // "save as" project
                File fileToSave = new File("myProject2.mdzip");
                ProjectDescriptor localProjectDescriptor = ProjectDescriptorsFactory.createLocalProjectDescriptor(project, fileToSave);
                projectsManager.saveProject(localProjectDescriptor, true);
     }
 }

Check documentation ("Running programs in batch mode") on how to start command line.

  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    protected abstract byte
    Override this method to execute your custom task(s) in running MagicDraw environment.
    final void
    launch(String[] args)
    Launch MagicDraw in commandline mode (without GUI).
    Method starts MagicDraw application, calls execute() method, and shuts down the application.
    protected void
    parseArgs(String[] args)
    Override to parse arguments before launching MagicDraw.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • CommandLine

      public CommandLine()
  • Method Details

    • launch

      public final void launch(String[] args) throws InstantiationException
      Launch MagicDraw in commandline mode (without GUI).
      Method starts MagicDraw application, calls execute() method, and shuts down the application.
      Parameters:
      args - command line arguments passed to MagicDraw.
      Throws:
      InstantiationException - if the failed return code needs to be indicated
    • parseArgs

      protected void parseArgs(String[] args) throws Exception
      Override to parse arguments before launching MagicDraw.
      Parameters:
      args - program arguments
      Throws:
      Exception - if arguments are not correct and MagicDraw should not be started
    • execute

      protected abstract byte execute()
      Override this method to execute your custom task(s) in running MagicDraw environment. Do not explicitly call this method - call launch(String[]) to launch the commandline.
      Returns:
      application exit status