use of org.opengroup.archimate.xmlexchange.XMLModelImporter in project archi by archimatetool.
the class ImportXMLProvider method run.
@Override
public void run(CommandLine commandLine) throws Exception {
if (!hasCorrectOptions(commandLine)) {
return;
}
// File
String value = commandLine.getOptionValue(OPTION_IMPORT_XML);
if (!StringUtils.isSet(value)) {
logError(Messages.ImportXMLProvider_1);
return;
}
File importFile = new File(value);
if (!importFile.exists()) {
logError(NLS.bind(Messages.ImportXMLProvider_2, value));
return;
}
// Validate file
logMessage(Messages.ImportXMLProvider_3);
XMLValidator validator = new XMLValidator();
validator.validateXML(importFile);
logMessage(Messages.ImportXMLProvider_4);
logMessage(NLS.bind(Messages.ImportXMLProvider_5, importFile.getPath()));
XMLModelImporter importer = new XMLModelImporter();
IArchimateModel model = importer.createArchiMateModel(importFile);
if (model == null) {
throw new IOException(Messages.ImportXMLProvider_6);
}
// Add an Archive Manager
IArchiveManager archiveManager = IArchiveManager.FACTORY.createArchiveManager(model);
model.setAdapter(IArchiveManager.class, archiveManager);
// Add a Command Stack
CommandStack cmdStack = new CommandStack();
model.setAdapter(CommandStack.class, cmdStack);
CommandLineState.setModel(model);
logMessage(Messages.ImportXMLProvider_7);
}
Aggregations