bpmn-js/lib/import/Importer.js
Nico Rehwaldt 921de712d2 chore(import): factor out import logic to own component
This commit extracts the main import logic found in import/Importer into
the core/BpmnImporter module. By doing so we we are able to reuse it
during modeling.

Related to #6
2014-07-17 14:06:29 +02:00

47 lines
1.0 KiB
JavaScript

'use strict';
var BpmnTreeWalker = require('./BpmnTreeWalker');
/**
* Import the definitions into the given diagram, reporting errors and warnings
* via the specified callback.
*
* @param {Diagram} diagram
* @param {ModdleElement} definitions
* @param {Function} done the callback, invoked with (err, [ warning ]) once the import is done
*/
function importBpmnDiagram(diagram, definitions, done) {
var importer = diagram.get('bpmnImporter'),
commandStack = diagram.get('commandStack');
var warnings = [];
var visitor = {
element: function(element, di, parent) {
return importer.add(element, di, parent);
},
error: function(message, context) {
warnings.push({ message: message, context: context });
}
};
var walker = new BpmnTreeWalker(visitor);
try {
// import
walker.handleDefinitions(definitions);
// clear command stack
commandStack.clear();
done(null, warnings);
} catch (e) {
done(e);
}
}
module.exports.importBpmnDiagram = importBpmnDiagram;