Search in sources :

Example 1 with CommandStack

use of org.yamcs.studio.commanding.stack.xml.CommandStack in project yamcs-studio by yamcs.

the class ImportCommandStackHandler method parseCommandStack.

public List<StackedCommand> parseCommandStack(String fileName) {
    try {
        final JAXBContext jc = JAXBContext.newInstance(org.yamcs.studio.commanding.stack.xml.CommandStack.class);
        final Unmarshaller unmarshaller = jc.createUnmarshaller();
        final org.yamcs.studio.commanding.stack.xml.CommandStack commandStack = (org.yamcs.studio.commanding.stack.xml.CommandStack) unmarshaller.unmarshal(new FileReader(fileName));
        List<StackedCommand> importedStack = new LinkedList<StackedCommand>();
        for (CommandStack.Command c : commandStack.getCommand()) {
            StackedCommand sc = new StackedCommand();
            CommandInfo mc = CommandingCatalogue.getInstance().getCommandInfo(c.getQualifiedName());
            if (mc == null) {
                MessageDialog.openError(Display.getCurrent().getActiveShell(), "Import Command Stack", "Command " + c.getQualifiedName() + " does not exist in MDB.");
                return null;
            }
            sc.setMetaCommand(mc);
            sc.setSelectedAliase(c.getSelectedAlias());
            sc.setComment(c.getComment());
            for (CommandArgument ca : c.getCommandArgument()) {
                ArgumentInfo a = getArgumentFromYamcs(mc, ca.getArgumentName());
                if (a == null) {
                    MessageDialog.openError(Display.getCurrent().getActiveShell(), "Import Command Stack", "In command " + c.getQualifiedName() + ", argument " + ca.getArgumentName() + " does not exist in MDB.");
                    return null;
                }
                sc.addAssignment(a, ca.getArgumentValue());
            }
            importedStack.add(sc);
        }
        return importedStack;
    } catch (Exception e) {
        log.log(Level.SEVERE, "Unable to load command stack for importation. Check the XML file is correct. Details:\n" + e.toString());
        MessageDialog.openError(Display.getCurrent().getActiveShell(), "Import Command Stack", "Unable to load command stack for importation. Check the XML file is correct. Details:\n" + e.toString());
        return null;
    }
}
Also used : CommandStack(org.yamcs.studio.commanding.stack.xml.CommandStack) CommandArgument(org.yamcs.studio.commanding.stack.xml.CommandStack.Command.CommandArgument) JAXBContext(javax.xml.bind.JAXBContext) LinkedList(java.util.LinkedList) ExecutionException(org.eclipse.core.commands.ExecutionException) CommandInfo(org.yamcs.protobuf.Mdb.CommandInfo) CommandStack(org.yamcs.studio.commanding.stack.xml.CommandStack) FileReader(java.io.FileReader) Unmarshaller(javax.xml.bind.Unmarshaller) ArgumentInfo(org.yamcs.protobuf.Mdb.ArgumentInfo)

Aggregations

FileReader (java.io.FileReader)1 LinkedList (java.util.LinkedList)1 JAXBContext (javax.xml.bind.JAXBContext)1 Unmarshaller (javax.xml.bind.Unmarshaller)1 ExecutionException (org.eclipse.core.commands.ExecutionException)1 ArgumentInfo (org.yamcs.protobuf.Mdb.ArgumentInfo)1 CommandInfo (org.yamcs.protobuf.Mdb.CommandInfo)1 CommandStack (org.yamcs.studio.commanding.stack.xml.CommandStack)1 CommandArgument (org.yamcs.studio.commanding.stack.xml.CommandStack.Command.CommandArgument)1