From 5dbdc8ddd8c354567917bdeadfc8da990ca0ddc1 Mon Sep 17 00:00:00 2001 From: Minkyu Lee Date: Wed, 7 Aug 2024 11:36:43 +0900 Subject: [PATCH] Fix for async open/save dialogs --- main.js | 52 +- package.json | 4 +- uml2-export.js | 2340 +++++++++++++++++++++++-------------------- uml2-import.js | 2558 ++++++++++++++++++++++++----------------------- xmi21-reader.js | 267 ++--- xmi21-writer.js | 328 +++--- 6 files changed, 2896 insertions(+), 2653 deletions(-) diff --git a/main.js b/main.js index dbef1ef..646e344 100644 --- a/main.js +++ b/main.js @@ -21,47 +21,55 @@ * */ -const xmi21reader = require('./xmi21-reader') -const xmi21writer = require('./xmi21-writer') -require('./uml2-import') -require('./uml2-export') +const xmi21reader = require("./xmi21-reader"); +const xmi21writer = require("./xmi21-writer"); +require("./uml2-import"); +require("./uml2-export"); const XMI_FILE_FILTERS = [ - {name: 'XMI Files', extensions: ['xmi']}, - {name: 'All Files', extensions: ['*']} -] + { name: "XMI Files", extensions: ["xmi"] }, + { name: "All Files", extensions: ["*"] }, +]; -function _handleXMI21Import (fullPath) { +async function _handleXMI21Import(fullPath) { if (fullPath) { - xmi21reader.loadFromFile(fullPath) + xmi21reader.loadFromFile(fullPath); } else { - var files = app.dialogs.showOpenDialog('Select a XMI File (.xmi)', null, XMI_FILE_FILTERS) + var files = await app.dialogs.showOpenDialogAsync( + "Select a XMI File (.xmi)", + null, + XMI_FILE_FILTERS, + ); if (files && files.length > 0) { try { - xmi21reader.loadFromFile(files[0]) + xmi21reader.loadFromFile(files[0]); } catch (err) { - app.dialogs.showErrorDialog('Failed to load the file.', err) - console.log(err) + app.dialogs.showErrorDialog("Failed to load the file.", err); + console.log(err); } } } } -function _handleXMI21Export (fullPath) { +async function _handleXMI21Export(fullPath) { if (fullPath) { - xmi21writer.saveToFile(fullPath) + xmi21writer.saveToFile(fullPath); } else { - var _filename = app.project.getProject().name - var filename = app.dialogs.showSaveDialog('Export Project As XMI', _filename + '.xmi', XMI_FILE_FILTERS) + var _filename = app.project.getProject().name; + var filename = await app.dialogs.showSaveDialogAsync( + "Export Project As XMI", + _filename + ".xmi", + XMI_FILE_FILTERS, + ); if (filename) { - xmi21writer.saveToFile(filename) + xmi21writer.saveToFile(filename); } } } -function init () { - app.commands.register('xmi:import', _handleXMI21Import) - app.commands.register('xmi:export', _handleXMI21Export) +function init() { + app.commands.register("xmi:import", _handleXMI21Import); + app.commands.register("xmi:export", _handleXMI21Export); } -exports.init = init +exports.init = init; diff --git a/package.json b/package.json index 0a1dbe1..9059ec0 100644 --- a/package.json +++ b/package.json @@ -4,7 +4,7 @@ "description": "XMI (XML Metadata Interchange) import and export", "homepage": "https://github.com/staruml/staruml-xmi", "issues": "https://github.com/staruml/staruml-xmi/issues", - "version": "0.9.4", + "version": "0.9.5", "author": { "name": "Minkyu Lee", "email": "niklaus.lee@gmail.com", @@ -12,6 +12,6 @@ }, "license": "MIT", "engines": { - "staruml": ">=3.0.0" + "staruml": ">=6.0.0" } } diff --git a/uml2-export.js b/uml2-export.js index f2a6f2d..02b47d4 100644 --- a/uml2-export.js +++ b/uml2-export.js @@ -21,19 +21,19 @@ * */ -const writer = require('./xmi21-writer') +const writer = require("./xmi21-writer"); // Core .................................................................... -writer.elements['Element'] = function (elem) { - var json = {} - writer.writeString(json, 'xmi:id', elem._id) - return json -} +writer.elements["Element"] = function (elem) { + var json = {}; + writer.writeString(json, "xmi:id", elem._id); + return json; +}; -writer.elements['Model'] = function (elem) { - var json = writer.elements['Element'](elem) - writer.writeString(json, 'name', elem.name) +writer.elements["Model"] = function (elem) { + var json = writer.elements["Element"](elem); + writer.writeString(json, "name", elem.name); elem.ownedElements.forEach(function (e) { if (e instanceof type.UMLGeneralization) { // Generalizations will be included in Classifier as 'generalization' @@ -47,1298 +47,1420 @@ writer.elements['Model'] = function (elem) { // Extends and Includes will be included in UseCase as 'extend' and 'include' } else if (e instanceof type.UMLConstraint) { // Constraints will be included as 'ownedRule' - writer.writeElement(json, 'ownedRule', e) + writer.writeElement(json, "ownedRule", e); } else if (e instanceof type.UMLConnector && elem instanceof type.UMLPort) { // Connectors will be included in the Port's parent Classifier as 'ownedConnector' } else { if (elem instanceof type.UMLPackage) { - writer.writeElement(json, 'packagedElement', e) + writer.writeElement(json, "packagedElement", e); } else { - writer.writeElement(json, 'ownedMember', e) + writer.writeElement(json, "ownedMember", e); } } - }) - return json -} + }); + return json; +}; -writer.elements['ExtensibleModel'] = function (elem) { - var json = writer.elements['Model'](elem) +writer.elements["ExtensibleModel"] = function (elem) { + var json = writer.elements["Model"](elem); // Write documentation as xmi:Extension - var _writeExtension = false - var _extensionNode = {} + var _writeExtension = false; + var _extensionNode = {}; if (elem.documentation && elem.documentation.trim().length > 0) { - _writeExtension = true - _extensionNode.documentation = { value: elem.documentation.trim() } + _writeExtension = true; + _extensionNode.documentation = { value: elem.documentation.trim() }; } // Write tags as xmi:Extension if (elem.tags && elem.tags.length > 0) { - _writeExtension = true - _extensionNode.tag = [] + _writeExtension = true; + _extensionNode.tag = []; elem.tags.forEach(function (tag) { - var _tag = {} + var _tag = {}; switch (tag.kind) { - case type.Tag.TK_STRING: - _tag[tag.name] = tag.value - _extensionNode.tag.push(_tag) - break - case type.Tag.TK_REFERENCE: - if (tag.reference && tag.reference._id) { - _tag[tag.name] = tag.reference._id - _extensionNode.tag.push(_tag) - } - break - case type.Tag.TK_BOOLEAN: - _tag[tag.name] = tag.checked - _extensionNode.tag.push(_tag) - break - case type.Tag.TK_NUMBER: - _tag[tag.name] = tag.number - _extensionNode.tag.push(_tag) - break + case type.Tag.TK_STRING: + _tag[tag.name] = tag.value; + _extensionNode.tag.push(_tag); + break; + case type.Tag.TK_REFERENCE: + if (tag.reference && tag.reference._id) { + _tag[tag.name] = tag.reference._id; + _extensionNode.tag.push(_tag); + } + break; + case type.Tag.TK_BOOLEAN: + _tag[tag.name] = tag.checked; + _extensionNode.tag.push(_tag); + break; + case type.Tag.TK_NUMBER: + _tag[tag.name] = tag.number; + _extensionNode.tag.push(_tag); + break; } - }) + }); } if (_writeExtension) { - writer.writeExtension(json, _extensionNode) + writer.writeExtension(json, _extensionNode); } - return json -} + return json; +}; -writer.elements['Relationship'] = function (elem) { - var json = writer.elements['ExtensibleModel'](elem) - return json -} +writer.elements["Relationship"] = function (elem) { + var json = writer.elements["ExtensibleModel"](elem); + return json; +}; -writer.elements['DirectedRelationship'] = function (elem) { - var json = writer.elements['Relationship'](elem) +writer.elements["DirectedRelationship"] = function (elem) { + var json = writer.elements["Relationship"](elem); // source // target - return json -} + return json; +}; -writer.elements['RelationshipEnd'] = function (elem) { - var json = writer.elements['ExtensibleModel'](elem) +writer.elements["RelationshipEnd"] = function (elem) { + var json = writer.elements["ExtensibleModel"](elem); // reference - return json -} + return json; +}; -writer.elements['UndirectedRelationship'] = function (elem) { - var json = writer.elements['Relationship'](elem) +writer.elements["UndirectedRelationship"] = function (elem) { + var json = writer.elements["Relationship"](elem); // end1 // end2 - return json -} + return json; +}; // Enumerations ............................................................ -writer.enumerations['UMLVisibilityKind'] = function (value) { +writer.enumerations["UMLVisibilityKind"] = function (value) { switch (value) { - case type.UMLModelElement.VK_PUBLIC: - return 'public' - case type.UMLModelElement.VK_PROTECTED: - return 'protected' - case type.UMLModelElement.VK_PRIVATE: - return 'private' - case type.UMLModelElement.VK_PACKAGE: - return 'package' - default: - return 'public' + case type.UMLModelElement.VK_PUBLIC: + return "public"; + case type.UMLModelElement.VK_PROTECTED: + return "protected"; + case type.UMLModelElement.VK_PRIVATE: + return "private"; + case type.UMLModelElement.VK_PACKAGE: + return "package"; + default: + return "public"; } -} +}; -writer.enumerations['UMLAggregationKind'] = function (value) { +writer.enumerations["UMLAggregationKind"] = function (value) { switch (value) { - case type.UMLAttribute.AK_NONE: - return 'none' - case type.UMLAttribute.AK_SHARED: - return 'shared' - case type.UMLAttribute.AK_COMPOSITE: - return 'composite' - default: - return 'none' + case type.UMLAttribute.AK_NONE: + return "none"; + case type.UMLAttribute.AK_SHARED: + return "shared"; + case type.UMLAttribute.AK_COMPOSITE: + return "composite"; + default: + return "none"; } -} +}; -writer.enumerations['UMLDirectionKind'] = function (value) { +writer.enumerations["UMLDirectionKind"] = function (value) { switch (value) { - case type.UMLParameter.DK_IN: - return 'in' - case type.UMLParameter.DK_INOUT: - return 'inout' - case type.UMLParameter.DK_OUT: - return 'out' - case type.UMLParameter.DK_RETURN: - return 'return' - default: - return 'in' + case type.UMLParameter.DK_IN: + return "in"; + case type.UMLParameter.DK_INOUT: + return "inout"; + case type.UMLParameter.DK_OUT: + return "out"; + case type.UMLParameter.DK_RETURN: + return "return"; + default: + return "in"; } -} +}; -writer.enumerations['UMLCallConcurrencyKind'] = function (value) { +writer.enumerations["UMLCallConcurrencyKind"] = function (value) { switch (value) { - case type.UMLBehavioralFeature.CCK_SEQUENTIAL: - return 'sequential' - case type.UMLBehavioralFeature.CCK_GUARDED: - return 'guarded' - case type.UMLBehavioralFeature.CCK_CONCURRENT: - return 'concurrent' - default: - return 'sequential' + case type.UMLBehavioralFeature.CCK_SEQUENTIAL: + return "sequential"; + case type.UMLBehavioralFeature.CCK_GUARDED: + return "guarded"; + case type.UMLBehavioralFeature.CCK_CONCURRENT: + return "concurrent"; + default: + return "sequential"; } -} +}; -writer.enumerations['UMLMessageSort'] = function (value) { +writer.enumerations["UMLMessageSort"] = function (value) { switch (value) { - case type.UMLMessage.MS_SYNCHCALL: - return 'synchCall' - case type.UMLMessage.MS_ASYNCHCALL: - return 'asynchCall' - case type.UMLMessage.MS_ASYNCHSIGNAL: - return 'asynchSignal' - case type.UMLMessage.MS_CREATEMESSAGE: - return 'createMessage' - case type.UMLMessage.MS_DELETEMESSAGE: - return 'deleteMessage' - case type.UMLMessage.MS_REPLY: - return 'reply' - default: - return 'synchCall' + case type.UMLMessage.MS_SYNCHCALL: + return "synchCall"; + case type.UMLMessage.MS_ASYNCHCALL: + return "asynchCall"; + case type.UMLMessage.MS_ASYNCHSIGNAL: + return "asynchSignal"; + case type.UMLMessage.MS_CREATEMESSAGE: + return "createMessage"; + case type.UMLMessage.MS_DELETEMESSAGE: + return "deleteMessage"; + case type.UMLMessage.MS_REPLY: + return "reply"; + default: + return "synchCall"; } -} +}; -writer.enumerations['UMLInteractionOperatorKind'] = function (value) { +writer.enumerations["UMLInteractionOperatorKind"] = function (value) { switch (value) { - case type.UMLCombinedFragment.IOK_ALT: - return 'alt' - case type.UMLCombinedFragment.IOK_OPT: - return 'opt' - case type.UMLCombinedFragment.IOK_PAR: - return 'par' - case type.UMLCombinedFragment.IOK_LOOP: - return 'loop' - case type.UMLCombinedFragment.IOK_CRITICAL: - return 'critical' - case type.UMLCombinedFragment.IOK_NEG: - return 'neg' - case type.UMLCombinedFragment.IOK_ASSERT: - return 'assert' - case type.UMLCombinedFragment.IOK_STRICT: - return 'strict' - case type.UMLCombinedFragment.IOK_SEQ: - return 'seq' - case type.UMLCombinedFragment.IOK_IGNORE: - return 'ignore' - case type.UMLCombinedFragment.IOK_CONSIDER: - return 'consider' - case type.UMLCombinedFragment.IOK_BREAK: - return 'break' - default: - return 'seq' + case type.UMLCombinedFragment.IOK_ALT: + return "alt"; + case type.UMLCombinedFragment.IOK_OPT: + return "opt"; + case type.UMLCombinedFragment.IOK_PAR: + return "par"; + case type.UMLCombinedFragment.IOK_LOOP: + return "loop"; + case type.UMLCombinedFragment.IOK_CRITICAL: + return "critical"; + case type.UMLCombinedFragment.IOK_NEG: + return "neg"; + case type.UMLCombinedFragment.IOK_ASSERT: + return "assert"; + case type.UMLCombinedFragment.IOK_STRICT: + return "strict"; + case type.UMLCombinedFragment.IOK_SEQ: + return "seq"; + case type.UMLCombinedFragment.IOK_IGNORE: + return "ignore"; + case type.UMLCombinedFragment.IOK_CONSIDER: + return "consider"; + case type.UMLCombinedFragment.IOK_BREAK: + return "break"; + default: + return "seq"; } -} +}; -writer.enumerations['UMLPseudostateKind'] = function (value) { +writer.enumerations["UMLPseudostateKind"] = function (value) { switch (value) { - case type.UMLPseudostate.PSK_INITIAL: - return 'initial' - case type.UMLPseudostate.PSK_DEEPHISTORY: - return 'deepHistory' - case type.UMLPseudostate.PSK_SHALLOWHISTORY: - return 'shallowHistory' - case type.UMLPseudostate.PSK_JOIN: - return 'join' - case type.UMLPseudostate.PSK_FORK: - return 'fork' - case type.UMLPseudostate.PSK_JUNCTION: - return 'junction' - case type.UMLPseudostate.PSK_CHOICE: - return 'choice' - case type.UMLPseudostate.PSK_ENTRYPOINT: - return 'entryPoint' - case type.UMLPseudostate.PSK_EXITPOINT: - return 'exitPoint' - case type.UMLPseudostate.PSK_TERMINATE: - return 'terminate' - default: - return 'initial' + case type.UMLPseudostate.PSK_INITIAL: + return "initial"; + case type.UMLPseudostate.PSK_DEEPHISTORY: + return "deepHistory"; + case type.UMLPseudostate.PSK_SHALLOWHISTORY: + return "shallowHistory"; + case type.UMLPseudostate.PSK_JOIN: + return "join"; + case type.UMLPseudostate.PSK_FORK: + return "fork"; + case type.UMLPseudostate.PSK_JUNCTION: + return "junction"; + case type.UMLPseudostate.PSK_CHOICE: + return "choice"; + case type.UMLPseudostate.PSK_ENTRYPOINT: + return "entryPoint"; + case type.UMLPseudostate.PSK_EXITPOINT: + return "exitPoint"; + case type.UMLPseudostate.PSK_TERMINATE: + return "terminate"; + default: + return "initial"; } -} +}; -writer.enumerations['UMLTransitionKind'] = function (value) { +writer.enumerations["UMLTransitionKind"] = function (value) { switch (value) { - case type.UMLTransition.TK_EXTERNAL: - return 'external' - case type.UMLTransition.TK_INTERNAL: - return 'internal' - case type.UMLTransition.TK_LOCAL: - return 'local' - default: - return 'external' + case type.UMLTransition.TK_EXTERNAL: + return "external"; + case type.UMLTransition.TK_INTERNAL: + return "internal"; + case type.UMLTransition.TK_LOCAL: + return "local"; + default: + return "external"; } -} +}; -writer.enumerations['UMLObjectNodeOrderingKind'] = function (value) { +writer.enumerations["UMLObjectNodeOrderingKind"] = function (value) { switch (value) { - case type.UMLObjectNode.ONOK_UNORDERED: - return 'unordered' - case type.UMLObjectNode.ONOK_ORDERED: - return 'ordered' - case type.UMLObjectNode.ONOK_LIFO: - return 'LIFO' - case type.UMLObjectNode.ONOK_FIFO: - return 'FIFO' - default: - return 'FIFO' + case type.UMLObjectNode.ONOK_UNORDERED: + return "unordered"; + case type.UMLObjectNode.ONOK_ORDERED: + return "ordered"; + case type.UMLObjectNode.ONOK_LIFO: + return "LIFO"; + case type.UMLObjectNode.ONOK_FIFO: + return "FIFO"; + default: + return "FIFO"; } -} +}; // Backbone ................................................................ -writer.elements['UMLModelElement'] = function (elem) { - var json = writer.elements['ExtensibleModel'](elem) +writer.elements["UMLModelElement"] = function (elem) { + var json = writer.elements["ExtensibleModel"](elem); // Write stereotype (it's not Standard, but it's the most convenient way to read - if (typeof elem.stereotype === 'object' && elem.stereotype && elem.stereotype._id) { - writer.writeExtension(json, {'stereotype': { 'value': elem.stereotype._id }}) - } else if (typeof elem.stereotype === 'string') { - writer.writeExtension(json, {'stereotype': { 'value': elem.stereotype }}) + if ( + typeof elem.stereotype === "object" && + elem.stereotype && + elem.stereotype._id + ) { + writer.writeExtension(json, { stereotype: { value: elem.stereotype._id } }); + } else if (typeof elem.stereotype === "string") { + writer.writeExtension(json, { stereotype: { value: elem.stereotype } }); } - writer.writeEnum(json, 'visibility', 'UMLVisibilityKind', elem.visibility) + writer.writeEnum(json, "visibility", "UMLVisibilityKind", elem.visibility); if (elem.templateParameters && elem.templateParameters.length > 0) { - json['ownedTemplateSignature'] = { - 'xmi:id': app.repository.generateGuid(), - 'xmi:type': (elem instanceof type.UMLClassifier ? 'uml:RedefinableTemplateSignature' : 'uml:TemplateSignature') - } - writer.writeElementArray(json['ownedTemplateSignature'], 'ownedParameter', elem.templateParameters) + json["ownedTemplateSignature"] = { + "xmi:id": app.repository.generateGuid(), + "xmi:type": + elem instanceof type.UMLClassifier + ? "uml:RedefinableTemplateSignature" + : "uml:TemplateSignature", + }; + writer.writeElementArray( + json["ownedTemplateSignature"], + "ownedParameter", + elem.templateParameters, + ); } - return json -} + return json; +}; -writer.elements['UMLConstraint'] = function (elem) { - var json = writer.elements['UMLModelElement'](elem) +writer.elements["UMLConstraint"] = function (elem) { + var json = writer.elements["UMLModelElement"](elem); if (elem.constrainedElements && elem.constrainedElements.length > 0) { - writer.writeRefArray(json, 'constrainedElement', elem.constrainedElements) + writer.writeRefArray(json, "constrainedElement", elem.constrainedElements); } else { - writer.writeRefArray(json, 'constrainedElement', [elem._parent]) + writer.writeRefArray(json, "constrainedElement", [elem._parent]); } if (elem.specification && elem.specification.length > 0) { - writer.writeValueSpec(json, 'specification', 'uml:OpaqueExpression', elem.specification) - } - writer.setType(json, 'uml:Constraint') - return json -} - -writer.elements['UMLTemplateParameter'] = function (elem) { - var json = writer.elements['UMLModelElement'](elem) - writer.setType(json, elem._parent instanceof type.UMLClassifier ? 'uml:ClassifierTemplateParameter' : 'uml:TemplateParameter') - json['ownedParameteredElement'] = { - 'xmi:id': app.repository.generateGuid(), - 'xmi:type': 'uml:Class', - 'name': elem.name + writer.writeValueSpec( + json, + "specification", + "uml:OpaqueExpression", + elem.specification, + ); } + writer.setType(json, "uml:Constraint"); + return json; +}; + +writer.elements["UMLTemplateParameter"] = function (elem) { + var json = writer.elements["UMLModelElement"](elem); + writer.setType( + json, + elem._parent instanceof type.UMLClassifier + ? "uml:ClassifierTemplateParameter" + : "uml:TemplateParameter", + ); + json["ownedParameteredElement"] = { + "xmi:id": app.repository.generateGuid(), + "xmi:type": "uml:Class", + name: elem.name, + }; // TODO: defaultValue - return json -} - -writer.elements['UMLFeature'] = function (elem) { - var json = writer.elements['UMLModelElement'](elem) - writer.writeBoolean(json, 'isStatic', elem.isStatic) - writer.writeBoolean(json, 'isLeaf', elem.isLeaf) - return json -} - -writer.elements['UMLStructuralFeature'] = function (elem) { - var json = writer.elements['UMLFeature'](elem) + return json; +}; + +writer.elements["UMLFeature"] = function (elem) { + var json = writer.elements["UMLModelElement"](elem); + writer.writeBoolean(json, "isStatic", elem.isStatic); + writer.writeBoolean(json, "isLeaf", elem.isLeaf); + return json; +}; + +writer.elements["UMLStructuralFeature"] = function (elem) { + var json = writer.elements["UMLFeature"](elem); if (elem.type && elem.type._id) { - writer.writeRef(json, 'type', elem.type) - } else if (typeof elem.type === 'string' && elem.type.trim().length > 0) { + writer.writeRef(json, "type", elem.type); + } else if (typeof elem.type === "string" && elem.type.trim().length > 0) { var _typeNode = { - 'xmi:id': elem.type + '_id', - 'xmi:type': 'uml:DataType', - 'name': elem.type - } - writer.addToDeferedNode(_typeNode) - writer.writeString(json, 'type', _typeNode['xmi:id']) + "xmi:id": elem.type + "_id", + "xmi:type": "uml:DataType", + name: elem.type, + }; + writer.addToDeferedNode(_typeNode); + writer.writeString(json, "type", _typeNode["xmi:id"]); } if (elem.multiplicity) { - if (elem.multiplicity.indexOf('..') > 0) { - var terms = elem.multiplicity.split('..') + if (elem.multiplicity.indexOf("..") > 0) { + var terms = elem.multiplicity.split(".."); if (terms.length > 1) { - terms[0] = terms[0].trim() - terms[1] = terms[1].trim() - writer.writeValueSpec(json, 'lowerValue', 'uml:LiteralInteger', terms[0]) - if (terms[1] === '*') { - writer.writeValueSpec(json, 'upperValue', 'uml:LiteralUnlimitedNatural', terms[1]) + terms[0] = terms[0].trim(); + terms[1] = terms[1].trim(); + writer.writeValueSpec( + json, + "lowerValue", + "uml:LiteralInteger", + terms[0], + ); + if (terms[1] === "*") { + writer.writeValueSpec( + json, + "upperValue", + "uml:LiteralUnlimitedNatural", + terms[1], + ); } else { - writer.writeValueSpec(json, 'upperValue', 'uml:LiteralInteger', terms[1]) + writer.writeValueSpec( + json, + "upperValue", + "uml:LiteralInteger", + terms[1], + ); } } } else { - if (elem.multiplicity.trim() === '*') { - writer.writeValueSpec(json, 'lowerValue', 'uml:LiteralUnlimitedNatural', elem.multiplicity.trim()) - writer.writeValueSpec(json, 'upperValue', 'uml:LiteralUnlimitedNatural', elem.multiplicity.trim()) + if (elem.multiplicity.trim() === "*") { + writer.writeValueSpec( + json, + "lowerValue", + "uml:LiteralUnlimitedNatural", + elem.multiplicity.trim(), + ); + writer.writeValueSpec( + json, + "upperValue", + "uml:LiteralUnlimitedNatural", + elem.multiplicity.trim(), + ); } else { - writer.writeValueSpec(json, 'lowerValue', 'uml:LiteralInteger', elem.multiplicity.trim()) - writer.writeValueSpec(json, 'upperValue', 'uml:LiteralInteger', elem.multiplicity.trim()) + writer.writeValueSpec( + json, + "lowerValue", + "uml:LiteralInteger", + elem.multiplicity.trim(), + ); + writer.writeValueSpec( + json, + "upperValue", + "uml:LiteralInteger", + elem.multiplicity.trim(), + ); } } } - writer.writeValueSpec(json, 'defaultValue', 'uml:LiteralString', elem.defaultValue) - writer.writeBoolean(json, 'isReadOnly', elem.isReadOnly) - writer.writeBoolean(json, 'isOrdered', elem.isOrdered) - writer.writeBoolean(json, 'isUnique', elem.isUnique) - return json -} - -writer.elements['UMLAttribute'] = function (elem) { - var json = writer.elements['UMLStructuralFeature'](elem) - writer.setType(json, 'uml:Property') - writer.writeEnum(json, 'aggregation', 'UMLAggregationKind', elem.aggregation) - writer.writeBoolean(json, 'isDerived', elem.isDerived) - writer.writeBoolean(json, 'isID', elem.isID) - return json -} - -writer.elements['UMLParameter'] = function (elem) { - var json = writer.elements['UMLStructuralFeature'](elem) - writer.writeEnum(json, 'direction', 'UMLDirectionKind', elem.direction) - writer.setType(json, 'uml:Parameter') - return json -} - -writer.elements['UMLBehavioralFeature'] = function (elem) { - var json = writer.elements['UMLFeature'](elem) - writer.writeElementArray(json, 'ownedParameter', elem.parameters) - writer.writeEnum(json, 'concurrency', 'UMLCallConcurrencyKind', elem.concurrency) - writer.writeRefArray(json, 'raisedException', elem.raisedExceptions) - return json -} - -writer.elements['UMLOperation'] = function (elem) { - var json = writer.elements['UMLBehavioralFeature'](elem) - writer.writeBoolean(json, 'isQuery', elem.isQuery) - writer.writeBoolean(json, 'isAbstract', elem.isAbstract) + writer.writeValueSpec( + json, + "defaultValue", + "uml:LiteralString", + elem.defaultValue, + ); + writer.writeBoolean(json, "isReadOnly", elem.isReadOnly); + writer.writeBoolean(json, "isOrdered", elem.isOrdered); + writer.writeBoolean(json, "isUnique", elem.isUnique); + return json; +}; + +writer.elements["UMLAttribute"] = function (elem) { + var json = writer.elements["UMLStructuralFeature"](elem); + writer.setType(json, "uml:Property"); + writer.writeEnum(json, "aggregation", "UMLAggregationKind", elem.aggregation); + writer.writeBoolean(json, "isDerived", elem.isDerived); + writer.writeBoolean(json, "isID", elem.isID); + return json; +}; + +writer.elements["UMLParameter"] = function (elem) { + var json = writer.elements["UMLStructuralFeature"](elem); + writer.writeEnum(json, "direction", "UMLDirectionKind", elem.direction); + writer.setType(json, "uml:Parameter"); + return json; +}; + +writer.elements["UMLBehavioralFeature"] = function (elem) { + var json = writer.elements["UMLFeature"](elem); + writer.writeElementArray(json, "ownedParameter", elem.parameters); + writer.writeEnum( + json, + "concurrency", + "UMLCallConcurrencyKind", + elem.concurrency, + ); + writer.writeRefArray(json, "raisedException", elem.raisedExceptions); + return json; +}; + +writer.elements["UMLOperation"] = function (elem) { + var json = writer.elements["UMLBehavioralFeature"](elem); + writer.writeBoolean(json, "isQuery", elem.isQuery); + writer.writeBoolean(json, "isAbstract", elem.isAbstract); if (elem.specification && elem.specification.trim().length > 0) { - writer.writeExtension(json, { specification: { value: elem.specification } }) + writer.writeExtension(json, { + specification: { value: elem.specification }, + }); } if (elem.preconditions && elem.preconditions.length > 0) { - writer.writeElementArray(json, 'precondition', elem.preconditions) + writer.writeElementArray(json, "precondition", elem.preconditions); } if (elem.postconditions && elem.postconditions.length > 0) { - writer.writeElementArray(json, 'postcondition', elem.postconditions) + writer.writeElementArray(json, "postcondition", elem.postconditions); } if (elem.bodyConditions && elem.bodyConditions.length > 0) { - writer.writeElementArray(json, 'bodyCondition', elem.bodyConditions) + writer.writeElementArray(json, "bodyCondition", elem.bodyConditions); } - writer.setType(json, 'uml:Operation') - return json -} - -writer.elements['UMLClassifier'] = function (elem) { - var json = writer.elements['UMLModelElement'](elem) - var _attrs = elem.attributes.filter(function (e) { return !(e instanceof type.UMLPort) }) - var _ports = elem.attributes.filter(function (e) { return e instanceof type.UMLPort }) - writer.writeElementArray(json, 'ownedAttribute', _attrs) - writer.writeElementArray(json, 'ownedPort', _ports) - writer.writeElementArray(json, 'ownedOperation', elem.operations) + writer.setType(json, "uml:Operation"); + return json; +}; + +writer.elements["UMLClassifier"] = function (elem) { + var json = writer.elements["UMLModelElement"](elem); + var _attrs = elem.attributes.filter(function (e) { + return !(e instanceof type.UMLPort); + }); + var _ports = elem.attributes.filter(function (e) { + return e instanceof type.UMLPort; + }); + writer.writeElementArray(json, "ownedAttribute", _attrs); + writer.writeElementArray(json, "ownedPort", _ports); + writer.writeElementArray(json, "ownedOperation", elem.operations); // Include Connectors - var _connectors = [] + var _connectors = []; _ports.forEach(function (e1) { e1.ownedElements.forEach(function (e2) { if (e2 instanceof type.UMLConnector) { - _connectors.push(e2) + _connectors.push(e2); } - }) - }) - writer.writeElementArray(json, 'ownedConnector', _connectors) - writer.writeBoolean(json, 'isAbstract', elem.isAbstract) - writer.writeBoolean(json, 'isFinalSpecialization', elem.isFinalSpecialization) - writer.writeBoolean(json, 'isLeaf', elem.isLeaf) + }); + }); + writer.writeElementArray(json, "ownedConnector", _connectors); + writer.writeBoolean(json, "isAbstract", elem.isAbstract); + writer.writeBoolean( + json, + "isFinalSpecialization", + elem.isFinalSpecialization, + ); + writer.writeBoolean(json, "isLeaf", elem.isLeaf); var _generalizations = app.repository.getRelationshipsOf(elem, function (r) { - return (r instanceof type.UMLGeneralization) && (r.source === elem) - }) - writer.writeElementArray(json, 'generalization', _generalizations) - var _interfaceRealizations = app.repository.getRelationshipsOf(elem, function (r) { - return (r instanceof type.UMLInterfaceRealization) && (r.source === elem) - }) - writer.writeElementArray(json, 'interfaceRealization', _interfaceRealizations) - writer.writeElementArray(json, 'ownedBehavior', elem.behaviors) - return json -} - -writer.elements['UMLDirectedRelationship'] = function (elem) { - var json = writer.elements['DirectedRelationship'](elem) - Object.assign(json, writer.elements['UMLModelElement'](elem)) - return json -} - -writer.elements['UMLRelationshipEnd'] = function (elem) { - var json = writer.elements['RelationshipEnd'](elem) - Object.assign(json, writer.elements['UMLAttribute'](elem)) + return r instanceof type.UMLGeneralization && r.source === elem; + }); + writer.writeElementArray(json, "generalization", _generalizations); + var _interfaceRealizations = app.repository.getRelationshipsOf( + elem, + function (r) { + return r instanceof type.UMLInterfaceRealization && r.source === elem; + }, + ); + writer.writeElementArray( + json, + "interfaceRealization", + _interfaceRealizations, + ); + writer.writeElementArray(json, "ownedBehavior", elem.behaviors); + return json; +}; + +writer.elements["UMLDirectedRelationship"] = function (elem) { + var json = writer.elements["DirectedRelationship"](elem); + Object.assign(json, writer.elements["UMLModelElement"](elem)); + return json; +}; + +writer.elements["UMLRelationshipEnd"] = function (elem) { + var json = writer.elements["RelationshipEnd"](elem); + Object.assign(json, writer.elements["UMLAttribute"](elem)); // TODO: navigable - return json -} + return json; +}; -writer.elements['UMLUndirectedRelationship'] = function (elem) { - var json = writer.elements['UndirectedRelationship'](elem) - Object.assign(json, writer.elements['UMLModelElement'](elem)) - return json -} +writer.elements["UMLUndirectedRelationship"] = function (elem) { + var json = writer.elements["UndirectedRelationship"](elem); + Object.assign(json, writer.elements["UMLModelElement"](elem)); + return json; +}; // Classes ................................................................. -writer.elements['UMLPackage'] = function (elem) { - var json = writer.elements['UMLModelElement'](elem) - writer.setType(json, 'uml:Package') - return json -} - -writer.elements['UMLModel'] = function (elem) { - var json = writer.elements['UMLPackage'](elem) - writer.setType(json, 'uml:Model') - return json -} - -writer.elements['UMLClass'] = function (elem) { - var json = writer.elements['UMLClassifier'](elem) - writer.setType(json, 'uml:Class') - writer.writeBoolean(json, 'isActive', elem.isActive) - return json -} - -writer.elements['UMLDataType'] = function (elem) { - var json = writer.elements['UMLClassifier'](elem) - writer.setType(json, 'uml:DataType') - return json -} - -writer.elements['UMLPrimitiveType'] = function (elem) { - var json = writer.elements['UMLDataType'](elem) - writer.setType(json, 'uml:PrimitiveType') - return json -} - -writer.elements['UMLEnumerationLiteral'] = function (elem) { - var json = writer.elements['UMLModelElement'](elem) - writer.setType(json, 'uml:EnumerationLiteral') - return json -} - -writer.elements['UMLEnumeration'] = function (elem) { - var json = writer.elements['UMLDataType'](elem) - writer.setType(json, 'uml:Enumeration') - writer.writeElementArray(json, 'ownedLiteral', elem.literals) - return json -} - -writer.elements['UMLInterface'] = function (elem) { - var json = writer.elements['UMLClassifier'](elem) - writer.setType(json, 'uml:Interface') - return json -} - -writer.elements['UMLSignal'] = function (elem) { - var json = writer.elements['UMLClassifier'](elem) - writer.setType(json, 'uml:Signal') - return json -} - -writer.elements['UMLDependency'] = function (elem) { - var json = writer.elements['UMLDirectedRelationship'](elem) - writer.setType(json, 'uml:Dependency') - writer.writeRef(json, 'client', elem.source) - writer.writeRef(json, 'supplier', elem.target) +writer.elements["UMLPackage"] = function (elem) { + var json = writer.elements["UMLModelElement"](elem); + writer.setType(json, "uml:Package"); + return json; +}; + +writer.elements["UMLModel"] = function (elem) { + var json = writer.elements["UMLPackage"](elem); + writer.setType(json, "uml:Model"); + return json; +}; + +writer.elements["UMLClass"] = function (elem) { + var json = writer.elements["UMLClassifier"](elem); + writer.setType(json, "uml:Class"); + writer.writeBoolean(json, "isActive", elem.isActive); + return json; +}; + +writer.elements["UMLDataType"] = function (elem) { + var json = writer.elements["UMLClassifier"](elem); + writer.setType(json, "uml:DataType"); + return json; +}; + +writer.elements["UMLPrimitiveType"] = function (elem) { + var json = writer.elements["UMLDataType"](elem); + writer.setType(json, "uml:PrimitiveType"); + return json; +}; + +writer.elements["UMLEnumerationLiteral"] = function (elem) { + var json = writer.elements["UMLModelElement"](elem); + writer.setType(json, "uml:EnumerationLiteral"); + return json; +}; + +writer.elements["UMLEnumeration"] = function (elem) { + var json = writer.elements["UMLDataType"](elem); + writer.setType(json, "uml:Enumeration"); + writer.writeElementArray(json, "ownedLiteral", elem.literals); + return json; +}; + +writer.elements["UMLInterface"] = function (elem) { + var json = writer.elements["UMLClassifier"](elem); + writer.setType(json, "uml:Interface"); + return json; +}; + +writer.elements["UMLSignal"] = function (elem) { + var json = writer.elements["UMLClassifier"](elem); + writer.setType(json, "uml:Signal"); + return json; +}; + +writer.elements["UMLDependency"] = function (elem) { + var json = writer.elements["UMLDirectedRelationship"](elem); + writer.setType(json, "uml:Dependency"); + writer.writeRef(json, "client", elem.source); + writer.writeRef(json, "supplier", elem.target); // TODO: mapping - return json -} - -writer.elements['UMLAbstraction'] = function (elem) { - var json = writer.elements['UMLDependency'](elem) - writer.setType(json, 'uml:Abstraction') - return json -} - -writer.elements['UMLRealization'] = function (elem) { - var json = writer.elements['UMLAbstraction'](elem) - writer.setType(json, 'uml:Realization') - return json -} - -writer.elements['UMLInterfaceRealization'] = function (elem) { - var json = writer.elements['UMLRealization'](elem) - delete json['client'] - delete json['supplier'] - writer.setType(json, 'uml:InterfaceRealization') - writer.writeRef(json, 'implementingClassifier', elem.source) - writer.writeRef(json, 'contract', elem.target) - return json -} - -writer.elements['UMLComponentRealization'] = function (elem) { - var json = writer.elements['UMLRealization'](elem) - delete json['client'] - delete json['supplier'] - writer.setType(json, 'uml:ComponentRealization') - writer.writeRef(json, 'realizingClassifier', elem.source) - writer.writeRef(json, 'abstraction', elem.target) - return json -} - -writer.elements['UMLGeneralization'] = function (elem) { - var json = writer.elements['UMLDirectedRelationship'](elem) - writer.setType(json, 'uml:Generalization') - writer.writeRef(json, 'specific', elem.source) - writer.writeRef(json, 'general', elem.target) - return json -} - -writer.elements['UMLAssociationEnd'] = function (elem) { - var json = writer.elements['UMLRelationshipEnd'](elem) - writer.setType(json, 'uml:Property') - writer.writeRef(json, 'type', elem.reference) + return json; +}; + +writer.elements["UMLAbstraction"] = function (elem) { + var json = writer.elements["UMLDependency"](elem); + writer.setType(json, "uml:Abstraction"); + return json; +}; + +writer.elements["UMLRealization"] = function (elem) { + var json = writer.elements["UMLAbstraction"](elem); + writer.setType(json, "uml:Realization"); + return json; +}; + +writer.elements["UMLInterfaceRealization"] = function (elem) { + var json = writer.elements["UMLRealization"](elem); + delete json["client"]; + delete json["supplier"]; + writer.setType(json, "uml:InterfaceRealization"); + writer.writeRef(json, "implementingClassifier", elem.source); + writer.writeRef(json, "contract", elem.target); + return json; +}; + +writer.elements["UMLComponentRealization"] = function (elem) { + var json = writer.elements["UMLRealization"](elem); + delete json["client"]; + delete json["supplier"]; + writer.setType(json, "uml:ComponentRealization"); + writer.writeRef(json, "realizingClassifier", elem.source); + writer.writeRef(json, "abstraction", elem.target); + return json; +}; + +writer.elements["UMLGeneralization"] = function (elem) { + var json = writer.elements["UMLDirectedRelationship"](elem); + writer.setType(json, "uml:Generalization"); + writer.writeRef(json, "specific", elem.source); + writer.writeRef(json, "general", elem.target); + return json; +}; + +writer.elements["UMLAssociationEnd"] = function (elem) { + var json = writer.elements["UMLRelationshipEnd"](elem); + writer.setType(json, "uml:Property"); + writer.writeRef(json, "type", elem.reference); // TODO: qualifiers - return json -} - -writer.elements['UMLAssociation'] = function (elem) { - var json = writer.elements['UMLUndirectedRelationship'](elem) - writer.setType(json, 'uml:Association') - writer.writeBoolean(json, 'isDerived', elem.isDerived) - var _e1 = new elem.end1.constructor() - var _e2 = new elem.end2.constructor() - var _ends = [Object.assign(_e1, elem.end1), Object.assign(_e2, elem.end2)] - var _agg = _ends[0].aggregation - _ends[0].aggregation = _ends[1].aggregation - _ends[1].aggregation = _agg - writer.writeElementArray(json, 'ownedEnd', _ends) - writer.writeRefArray(json, 'memberEnd', _ends) - return json -} + return json; +}; + +writer.elements["UMLAssociation"] = function (elem) { + var json = writer.elements["UMLUndirectedRelationship"](elem); + writer.setType(json, "uml:Association"); + writer.writeBoolean(json, "isDerived", elem.isDerived); + var _e1 = new elem.end1.constructor(); + var _e2 = new elem.end2.constructor(); + var _ends = [Object.assign(_e1, elem.end1), Object.assign(_e2, elem.end2)]; + var _agg = _ends[0].aggregation; + _ends[0].aggregation = _ends[1].aggregation; + _ends[1].aggregation = _agg; + writer.writeElementArray(json, "ownedEnd", _ends); + writer.writeRefArray(json, "memberEnd", _ends); + return json; +}; // TODO: UMLAssociationClassLink // Instances ............................................................... -writer.elements['UMLSlot'] = function (elem) { - var json = writer.elements['UMLModelElement'](elem) - writer.setType(json, 'uml:Slot') - writer.writeRef(json, 'definingFeature', elem.definingFeature) - writer.writeValueSpec(json, 'value', 'uml:OpaqueExpression', elem.value) - return json -} - -writer.elements['UMLInstance'] = function (elem) { - var json = writer.elements['UMLModelElement'](elem) - writer.writeElementArray(json, 'slot', elem.slots) - writer.writeRefArray(json, 'classifier', [ elem.classifier ]) - return json -} - -writer.elements['UMLObject'] = function (elem) { - var json = writer.elements['UMLInstance'](elem) - writer.setType(json, 'uml:InstanceSpecification') - return json -} - -writer.elements['UMLArtifactInstance'] = function (elem) { - var json = writer.elements['UMLInstance'](elem) - writer.setType(json, 'uml:InstanceSpecification') - return json -} - -writer.elements['UMLComponentInstance'] = function (elem) { - var json = writer.elements['UMLInstance'](elem) - writer.setType(json, 'uml:InstanceSpecification') - return json -} - -writer.elements['UMLNodeInstance'] = function (elem) { - var json = writer.elements['UMLInstance'](elem) - writer.setType(json, 'uml:InstanceSpecification') - return json -} - -writer.elements['UMLLink'] = function (elem) { - var json = writer.elements['UMLUndirectedRelationship'](elem) - writer.setType(json, 'uml:InstanceSpecification') +writer.elements["UMLSlot"] = function (elem) { + var json = writer.elements["UMLModelElement"](elem); + writer.setType(json, "uml:Slot"); + writer.writeRef(json, "definingFeature", elem.definingFeature); + writer.writeValueSpec(json, "value", "uml:OpaqueExpression", elem.value); + return json; +}; + +writer.elements["UMLInstance"] = function (elem) { + var json = writer.elements["UMLModelElement"](elem); + writer.writeElementArray(json, "slot", elem.slots); + writer.writeRefArray(json, "classifier", [elem.classifier]); + return json; +}; + +writer.elements["UMLObject"] = function (elem) { + var json = writer.elements["UMLInstance"](elem); + writer.setType(json, "uml:InstanceSpecification"); + return json; +}; + +writer.elements["UMLArtifactInstance"] = function (elem) { + var json = writer.elements["UMLInstance"](elem); + writer.setType(json, "uml:InstanceSpecification"); + return json; +}; + +writer.elements["UMLComponentInstance"] = function (elem) { + var json = writer.elements["UMLInstance"](elem); + writer.setType(json, "uml:InstanceSpecification"); + return json; +}; + +writer.elements["UMLNodeInstance"] = function (elem) { + var json = writer.elements["UMLInstance"](elem); + writer.setType(json, "uml:InstanceSpecification"); + return json; +}; + +writer.elements["UMLLink"] = function (elem) { + var json = writer.elements["UMLUndirectedRelationship"](elem); + writer.setType(json, "uml:InstanceSpecification"); if (elem.association) { - writer.writeRefArray(json, 'classifier', [ elem.association ]) + writer.writeRefArray(json, "classifier", [elem.association]); } writer.writeExtension(json, { - 'linkEnd1': { 'value': elem.end1.reference._id }, - 'linkEnd2': { 'value': elem.end2.reference._id } - }) - return json -} + linkEnd1: { value: elem.end1.reference._id }, + linkEnd2: { value: elem.end2.reference._id }, + }); + return json; +}; // Composite Structure ..................................................... -writer.elements['UMLPort'] = function (elem) { - var json = writer.elements['UMLAttribute'](elem) - writer.setType(json, 'uml:Port') - writer.writeBoolean(json, 'isBehavior', elem.isBehavior) - writer.writeBoolean(json, 'isService', elem.isService) - writer.writeBoolean(json, 'isConjugated', elem.isConjugated) - return json -} - -writer.elements['UMLConnectorEnd'] = function (elem) { - var json = writer.elements['UMLRelationshipEnd'](elem) - writer.setType(json, 'uml:ConnectorEnd') - writer.writeRef(json, 'role', elem.reference) - return json -} - -writer.elements['UMLConnector'] = function (elem) { - var json = writer.elements['UMLUndirectedRelationship'](elem) - writer.setType(json, 'uml:Connector') - writer.writeRef(json, 'type', elem.type) - var _e1 = new elem.end1.constructor() - var _e2 = new elem.end2.constructor() - var _ends = [Object.assign(_e1, elem.end1), Object.assign(_e2, elem.end2)] - var _agg = _ends[0].aggregation - _ends[0].aggregation = _ends[1].aggregation - _ends[1].aggregation = _agg - writer.writeElementArray(json, 'end', _ends) - return json -} - -writer.elements['UMLCollaboration'] = function (elem) { - var json = writer.elements['UMLClassifier'](elem) - writer.setType(json, 'uml:Collaboration') - return json -} - -writer.elements['UMLCollaborationUse'] = function (elem) { - var json = writer.elements['UMLModelElement'](elem) - writer.setType(json, 'uml:CollaborationUse') - writer.writeRef(json, 'type', elem.type) - return json -} - -writer.elements['UMLRoleBinding'] = function (elem) { - var json = writer.elements['UMLDependency'](elem) - writer.setType(json, 'uml:Dependency') +writer.elements["UMLPort"] = function (elem) { + var json = writer.elements["UMLAttribute"](elem); + writer.setType(json, "uml:Port"); + writer.writeBoolean(json, "isBehavior", elem.isBehavior); + writer.writeBoolean(json, "isService", elem.isService); + writer.writeBoolean(json, "isConjugated", elem.isConjugated); + return json; +}; + +writer.elements["UMLConnectorEnd"] = function (elem) { + var json = writer.elements["UMLRelationshipEnd"](elem); + writer.setType(json, "uml:ConnectorEnd"); + writer.writeRef(json, "role", elem.reference); + return json; +}; + +writer.elements["UMLConnector"] = function (elem) { + var json = writer.elements["UMLUndirectedRelationship"](elem); + writer.setType(json, "uml:Connector"); + writer.writeRef(json, "type", elem.type); + var _e1 = new elem.end1.constructor(); + var _e2 = new elem.end2.constructor(); + var _ends = [Object.assign(_e1, elem.end1), Object.assign(_e2, elem.end2)]; + var _agg = _ends[0].aggregation; + _ends[0].aggregation = _ends[1].aggregation; + _ends[1].aggregation = _agg; + writer.writeElementArray(json, "end", _ends); + return json; +}; + +writer.elements["UMLCollaboration"] = function (elem) { + var json = writer.elements["UMLClassifier"](elem); + writer.setType(json, "uml:Collaboration"); + return json; +}; + +writer.elements["UMLCollaborationUse"] = function (elem) { + var json = writer.elements["UMLModelElement"](elem); + writer.setType(json, "uml:CollaborationUse"); + writer.writeRef(json, "type", elem.type); + return json; +}; + +writer.elements["UMLRoleBinding"] = function (elem) { + var json = writer.elements["UMLDependency"](elem); + writer.setType(json, "uml:Dependency"); if (elem.roleName && elem.roleName.length > 0) { - writer.writeExtension(json, {roleName: { value: elem.roleName }}) + writer.writeExtension(json, { roleName: { value: elem.roleName } }); } - return json -} + return json; +}; // Components .............................................................. -writer.elements['UMLArtifact'] = function (elem) { - var json = writer.elements['UMLClassifier'](elem) - writer.setType(json, 'uml:Artifact') - writer.writeString(json, 'fileName', elem.fileName) - return json -} - -writer.elements['UMLComponent'] = function (elem) { - var json = writer.elements['UMLClassifier'](elem) - writer.setType(json, 'uml:Component') - writer.writeBoolean(json, 'isIndirectlyInstantiated', elem.isIndirectlyInstantiated) +writer.elements["UMLArtifact"] = function (elem) { + var json = writer.elements["UMLClassifier"](elem); + writer.setType(json, "uml:Artifact"); + writer.writeString(json, "fileName", elem.fileName); + return json; +}; + +writer.elements["UMLComponent"] = function (elem) { + var json = writer.elements["UMLClassifier"](elem); + writer.setType(json, "uml:Component"); + writer.writeBoolean( + json, + "isIndirectlyInstantiated", + elem.isIndirectlyInstantiated, + ); var _realizations = app.repository.getRelationshipsOf(elem, function (r) { - return (r instanceof type.UMLComponentRealization) && (r.target === elem) - }) - writer.writeElementArray(json, 'realization', _realizations) - return json -} - -writer.elements['UMLSubsystem'] = function (elem) { - var json = writer.elements['UMLComponent'](elem) - writer.setType(json, 'uml:Component') - writer.writeExtension(json, {'stereotype': { 'value': 'subsystem' }}) - return json -} + return r instanceof type.UMLComponentRealization && r.target === elem; + }); + writer.writeElementArray(json, "realization", _realizations); + return json; +}; + +writer.elements["UMLSubsystem"] = function (elem) { + var json = writer.elements["UMLComponent"](elem); + writer.setType(json, "uml:Component"); + writer.writeExtension(json, { stereotype: { value: "subsystem" } }); + return json; +}; // Deployments ............................................................. -writer.elements['UMLNode'] = function (elem) { - var json = writer.elements['UMLClassifier'](elem) - writer.setType(json, 'uml:Node') +writer.elements["UMLNode"] = function (elem) { + var json = writer.elements["UMLClassifier"](elem); + writer.setType(json, "uml:Node"); var _deployments = app.repository.getRelationshipsOf(elem, function (r) { - return (r instanceof type.UMLDeployment) && (r.target === elem) - }) - writer.writeElementArray(json, 'deployment', _deployments) - return json -} - -writer.elements['UMLCommunicationPath'] = function (elem) { - var json = writer.elements['UMLAssociation'](elem) - writer.setType(json, 'uml:CommunicationPath') - return json -} - -writer.elements['UMLDeployment'] = function (elem) { - var json = writer.elements['UMLDependency'](elem) - delete json['client'] - delete json['supplier'] - writer.setType(json, 'uml:Deployment') - writer.writeRef(json, 'deployedArtifact', elem.source) - writer.writeRef(json, 'location', elem.target) - return json -} + return r instanceof type.UMLDeployment && r.target === elem; + }); + writer.writeElementArray(json, "deployment", _deployments); + return json; +}; + +writer.elements["UMLCommunicationPath"] = function (elem) { + var json = writer.elements["UMLAssociation"](elem); + writer.setType(json, "uml:CommunicationPath"); + return json; +}; + +writer.elements["UMLDeployment"] = function (elem) { + var json = writer.elements["UMLDependency"](elem); + delete json["client"]; + delete json["supplier"]; + writer.setType(json, "uml:Deployment"); + writer.writeRef(json, "deployedArtifact", elem.source); + writer.writeRef(json, "location", elem.target); + return json; +}; // Use Cases ............................................................... -writer.elements['UMLActor'] = function (elem) { - var json = writer.elements['UMLClassifier'](elem) - writer.setType(json, 'uml:Actor') - return json -} - -writer.elements['UMLExtensionPoint'] = function (elem) { - var json = writer.elements['UMLModelElement'](elem) - writer.setType(json, 'uml:ExtensionPoint') - return json -} - -writer.elements['UMLUseCase'] = function (elem) { - var json = writer.elements['UMLClassifier'](elem) - writer.setType(json, 'uml:UseCase') - writer.writeElementArray(json, 'extensionPoint', elem.extensionPoints) +writer.elements["UMLActor"] = function (elem) { + var json = writer.elements["UMLClassifier"](elem); + writer.setType(json, "uml:Actor"); + return json; +}; + +writer.elements["UMLExtensionPoint"] = function (elem) { + var json = writer.elements["UMLModelElement"](elem); + writer.setType(json, "uml:ExtensionPoint"); + return json; +}; + +writer.elements["UMLUseCase"] = function (elem) { + var json = writer.elements["UMLClassifier"](elem); + writer.setType(json, "uml:UseCase"); + writer.writeElementArray(json, "extensionPoint", elem.extensionPoints); // Extends var _extends = app.repository.getRelationshipsOf(elem, function (r) { - return (r instanceof type.UMLExtend) && (r.source === elem) - }) - writer.writeElementArray(json, 'extend', _extends) + return r instanceof type.UMLExtend && r.source === elem; + }); + writer.writeElementArray(json, "extend", _extends); // Includes var _includes = app.repository.getRelationshipsOf(elem, function (r) { - return (r instanceof type.UMLInclude) && (r.source === elem) - }) - writer.writeElementArray(json, 'include', _includes) - return json -} - -writer.elements['UMLExtend'] = function (elem) { - var json = writer.elements['UMLDependency'](elem) - delete json['client'] - delete json['supplier'] - writer.setType(json, 'uml:Extend') - writer.writeRef(json, 'extendedCase', elem.target) - writer.writeRef(json, 'extension', elem.source) - writer.writeRefArray(json, 'extensionLocation', elem.extensionLocations) + return r instanceof type.UMLInclude && r.source === elem; + }); + writer.writeElementArray(json, "include", _includes); + return json; +}; + +writer.elements["UMLExtend"] = function (elem) { + var json = writer.elements["UMLDependency"](elem); + delete json["client"]; + delete json["supplier"]; + writer.setType(json, "uml:Extend"); + writer.writeRef(json, "extendedCase", elem.target); + writer.writeRef(json, "extension", elem.source); + writer.writeRefArray(json, "extensionLocation", elem.extensionLocations); if (elem.condition && elem.condition.length > 0) { - json['condition'] = { - 'xmi:id': app.repository.generateGuid(), - 'xmi:type': 'uml:Constraint', - 'specification': elem.condition - } + json["condition"] = { + "xmi:id": app.repository.generateGuid(), + "xmi:type": "uml:Constraint", + specification: elem.condition, + }; } - return json -} - -writer.elements['UMLInclude'] = function (elem) { - var json = writer.elements['UMLDependency'](elem) - delete json['client'] - delete json['supplier'] - writer.setType(json, 'uml:Include') - writer.writeRef(json, 'addition', elem.target) - writer.writeRef(json, 'includingCase', elem.source) - return json -} + return json; +}; + +writer.elements["UMLInclude"] = function (elem) { + var json = writer.elements["UMLDependency"](elem); + delete json["client"]; + delete json["supplier"]; + writer.setType(json, "uml:Include"); + writer.writeRef(json, "addition", elem.target); + writer.writeRef(json, "includingCase", elem.source); + return json; +}; // Common Behaviors ........................................................ -writer.elements['UMLBehavior'] = function (elem) { - var json = writer.elements['UMLModelElement'](elem) - writer.writeBoolean(json, 'isReentrant', elem.isReentrant) - writer.writeElementArray(json, 'ownedParameter', elem.parameters) - return json -} - -writer.elements['UMLOpaqueBehavior'] = function (elem) { - var json = writer.elements['UMLBehavior'](elem) - writer.setType(json, 'uml:OpaqueBehavior') - return json -} - -writer.elements['UMLEvent'] = function (elem) { - var json = writer.elements['UMLModelElement'](elem) +writer.elements["UMLBehavior"] = function (elem) { + var json = writer.elements["UMLModelElement"](elem); + writer.writeBoolean(json, "isReentrant", elem.isReentrant); + writer.writeElementArray(json, "ownedParameter", elem.parameters); + return json; +}; + +writer.elements["UMLOpaqueBehavior"] = function (elem) { + var json = writer.elements["UMLBehavior"](elem); + writer.setType(json, "uml:OpaqueBehavior"); + return json; +}; + +writer.elements["UMLEvent"] = function (elem) { + var json = writer.elements["UMLModelElement"](elem); switch (elem.kind) { - case type.UMLEvent.EK_SIGNAL: - writer.setType(json, 'uml:SignalEvent') - writer.writeRef(json, 'signal', elem.targetSignal) - break - case type.UMLEvent.EK_CALL: - writer.setType(json, 'uml:CallEvent') - writer.writeRef(json, 'operation', elem.targetOperation) - break - case type.UMLEvent.EK_CHANGE: - writer.setType(json, 'uml:ChangeEvent') - writer.writeValueSpec(json, 'changeExpression', 'uml:OpaqueExpression', elem.expression) - break - case type.UMLEvent.EK_TIME: - writer.setType(json, 'uml:TimeEvent') - writer.writeValueSpec(json, 'when', 'uml:OpaqueExpression', elem.expression) - break - case type.UMLEvent.EK_ANYRECEIVE: - writer.setType(json, 'uml:AnyReceiveEvent') - break + case type.UMLEvent.EK_SIGNAL: + writer.setType(json, "uml:SignalEvent"); + writer.writeRef(json, "signal", elem.targetSignal); + break; + case type.UMLEvent.EK_CALL: + writer.setType(json, "uml:CallEvent"); + writer.writeRef(json, "operation", elem.targetOperation); + break; + case type.UMLEvent.EK_CHANGE: + writer.setType(json, "uml:ChangeEvent"); + writer.writeValueSpec( + json, + "changeExpression", + "uml:OpaqueExpression", + elem.expression, + ); + break; + case type.UMLEvent.EK_TIME: + writer.setType(json, "uml:TimeEvent"); + writer.writeValueSpec( + json, + "when", + "uml:OpaqueExpression", + elem.expression, + ); + break; + case type.UMLEvent.EK_ANYRECEIVE: + writer.setType(json, "uml:AnyReceiveEvent"); + break; } - return json -} + return json; +}; // Interactions ............................................................ -writer.elements['UMLInteractionFragment'] = function (elem) { - var json = writer.elements['UMLBehavior'](elem) - return json -} +writer.elements["UMLInteractionFragment"] = function (elem) { + var json = writer.elements["UMLBehavior"](elem); + return json; +}; -writer.elements['UMLInteraction'] = function (elem) { - var json = writer.elements['UMLInteractionFragment'](elem) - writer.setType(json, 'uml:Interaction') +writer.elements["UMLInteraction"] = function (elem) { + var json = writer.elements["UMLInteractionFragment"](elem); + writer.setType(json, "uml:Interaction"); elem.participants.forEach(function (e) { if (e instanceof type.UMLLifeline) { - writer.writeElement(json, 'lifeline', e) + writer.writeElement(json, "lifeline", e); } else if (e instanceof type.UMLGate) { - writer.writeElement(json, 'formalGate', e) + writer.writeElement(json, "formalGate", e); } - }) + }); elem.messages.forEach(function (e) { var _fromOccurrence = { - 'xmi:id': app.repository.generateGuid(), - 'xmi:type': 'uml:OccurrenceSpecification', - 'covered': e.source._id - } + "xmi:id": app.repository.generateGuid(), + "xmi:type": "uml:OccurrenceSpecification", + covered: e.source._id, + }; var _toOccurrence = { - 'xmi:id': app.repository.generateGuid(), - 'xmi:type': 'uml:OccurrenceSpecification', - 'covered': e.target._id - } - var _message = writer.writeElement(json, 'message', e) + "xmi:id": app.repository.generateGuid(), + "xmi:type": "uml:OccurrenceSpecification", + covered: e.target._id, + }; + var _message = writer.writeElement(json, "message", e); if (e.source instanceof type.UMLEndpoint) { - _message['receiveEvent'] = _toOccurrence['xmi:id'] - writer.addTo(json, 'fragment', _toOccurrence) + _message["receiveEvent"] = _toOccurrence["xmi:id"]; + writer.addTo(json, "fragment", _toOccurrence); } else if (e.target instanceof type.UMLEndpoint) { - _message['sendEvent'] = _fromOccurrence['xmi:id'] - writer.addTo(json, 'fragment', _fromOccurrence) + _message["sendEvent"] = _fromOccurrence["xmi:id"]; + writer.addTo(json, "fragment", _fromOccurrence); } else { - _message['receiveEvent'] = _toOccurrence['xmi:id'] - _message['sendEvent'] = _fromOccurrence['xmi:id'] - writer.addTo(json, 'fragment', _fromOccurrence) - writer.addTo(json, 'fragment', _toOccurrence) + _message["receiveEvent"] = _toOccurrence["xmi:id"]; + _message["sendEvent"] = _fromOccurrence["xmi:id"]; + writer.addTo(json, "fragment", _fromOccurrence); + writer.addTo(json, "fragment", _toOccurrence); } - }) - writer.writeElementArray(json, 'fragment', elem.fragments) - return json -} - -writer.elements['UMLStateInvariant'] = function (elem) { - var json = writer.elements['UMLInteractionFragment'](elem) - writer.setType(json, 'uml:StateInvariant') - writer.writeRef(json, 'covered', elem.covered) + }); + writer.writeElementArray(json, "fragment", elem.fragments); + return json; +}; + +writer.elements["UMLStateInvariant"] = function (elem) { + var json = writer.elements["UMLInteractionFragment"](elem); + writer.setType(json, "uml:StateInvariant"); + writer.writeRef(json, "covered", elem.covered); if (elem.invariant && elem.invariant.length > 0) { - json['invariant'] = { - 'xmi:id': app.repository.generateGuid(), - 'xmi:type': 'uml:Constraint', - 'specification': elem.invariant - } + json["invariant"] = { + "xmi:id": app.repository.generateGuid(), + "xmi:type": "uml:Constraint", + specification: elem.invariant, + }; } - return json -} - -writer.elements['UMLContinuation'] = function (elem) { - var json = writer.elements['UMLInteractionFragment'](elem) - writer.setType(json, 'uml:Continuation') - writer.writeBoolean(json, 'setting', elem.setting) - return json -} - -writer.elements['UMLInteractionOperand'] = function (elem) { - var json = writer.elements['UMLInteractionFragment'](elem) - writer.setType(json, 'uml:InteractionOperand') + return json; +}; + +writer.elements["UMLContinuation"] = function (elem) { + var json = writer.elements["UMLInteractionFragment"](elem); + writer.setType(json, "uml:Continuation"); + writer.writeBoolean(json, "setting", elem.setting); + return json; +}; + +writer.elements["UMLInteractionOperand"] = function (elem) { + var json = writer.elements["UMLInteractionFragment"](elem); + writer.setType(json, "uml:InteractionOperand"); if (elem.guard && elem.guard.length > 0) { - json['guard'] = { - 'xmi:id': app.repository.generateGuid(), - 'xmi:type': 'uml:Constraint', - 'specification': elem.guard - } + json["guard"] = { + "xmi:id": app.repository.generateGuid(), + "xmi:type": "uml:Constraint", + specification: elem.guard, + }; } // TODO: fragment (see UML Spec, it's about OccurrentSpecifications of Messages included in this operand) - return json -} - -writer.elements['UMLCombinedFragment'] = function (elem) { - var json = writer.elements['UMLInteractionFragment'](elem) - writer.setType(json, 'uml:CombinedFragment') - writer.writeEnum(json, 'interactionOperator', 'UMLInteractionOperatorKind', elem.interactionOperator) - writer.writeElementArray(json, 'operand', elem.operands) - return json -} - -writer.elements['UMLInteractionUse'] = function (elem) { - var json = writer.elements['UMLInteractionFragment'](elem) - writer.setType(json, 'uml:InteractionUse') - writer.writeRef(json, 'refersTo', elem.refersTo) - return json -} - -writer.elements['UMLMessageEndpoint'] = function (elem) { - var json = writer.elements['UMLModelElement'](elem) - return json -} - -writer.elements['UMLLifeline'] = function (elem) { - var json = writer.elements['UMLMessageEndpoint'](elem) - writer.setType(json, 'uml:Lifeline') - writer.writeValueSpec(json, 'selector', 'uml:LiteralString', elem.selector) - writer.writeRef(json, 'represents', elem.represent) - return json -} - -writer.elements['UMLGate'] = function (elem) { - var json = writer.elements['UMLMessageEndpoint'](elem) - writer.setType(json, 'uml:Gate') - return json -} - -writer.elements['UMLMessage'] = function (elem) { - var json = writer.elements['UMLDirectedRelationship'](elem) - writer.setType(json, 'uml:Message') - writer.writeEnum(json, 'messageSort', 'UMLMessageSort', elem.messageSort) + return json; +}; + +writer.elements["UMLCombinedFragment"] = function (elem) { + var json = writer.elements["UMLInteractionFragment"](elem); + writer.setType(json, "uml:CombinedFragment"); + writer.writeEnum( + json, + "interactionOperator", + "UMLInteractionOperatorKind", + elem.interactionOperator, + ); + writer.writeElementArray(json, "operand", elem.operands); + return json; +}; + +writer.elements["UMLInteractionUse"] = function (elem) { + var json = writer.elements["UMLInteractionFragment"](elem); + writer.setType(json, "uml:InteractionUse"); + writer.writeRef(json, "refersTo", elem.refersTo); + return json; +}; + +writer.elements["UMLMessageEndpoint"] = function (elem) { + var json = writer.elements["UMLModelElement"](elem); + return json; +}; + +writer.elements["UMLLifeline"] = function (elem) { + var json = writer.elements["UMLMessageEndpoint"](elem); + writer.setType(json, "uml:Lifeline"); + writer.writeValueSpec(json, "selector", "uml:LiteralString", elem.selector); + writer.writeRef(json, "represents", elem.represent); + return json; +}; + +writer.elements["UMLGate"] = function (elem) { + var json = writer.elements["UMLMessageEndpoint"](elem); + writer.setType(json, "uml:Gate"); + return json; +}; + +writer.elements["UMLMessage"] = function (elem) { + var json = writer.elements["UMLDirectedRelationship"](elem); + writer.setType(json, "uml:Message"); + writer.writeEnum(json, "messageSort", "UMLMessageSort", elem.messageSort); if (elem.source instanceof type.UMLEndpoint) { - writer.writeString(json, 'messageKind', 'found') + writer.writeString(json, "messageKind", "found"); } else if (elem.target instanceof type.UMLEndpoint) { - writer.writeString(json, 'messageKind', 'lost') + writer.writeString(json, "messageKind", "lost"); } else { - writer.writeString(json, 'messageKind', 'complete') + writer.writeString(json, "messageKind", "complete"); } - writer.writeRef(json, 'signature', elem.signature) - writer.writeRef(json, 'connector', elem.connector) + writer.writeRef(json, "signature", elem.signature); + writer.writeRef(json, "connector", elem.connector); if (elem.arguments && elem.arguments.length > 0) { - writer.writeValueSpec(json, 'argument', 'uml:LiteralString', elem.arguments) + writer.writeValueSpec( + json, + "argument", + "uml:LiteralString", + elem.arguments, + ); } if (elem.assignmentTarget && elem.assignmentTarget.length > 0) { - writer.writeExtension(json, {assignmentTarget: { value: elem.assignmentTarget }}) + writer.writeExtension(json, { + assignmentTarget: { value: elem.assignmentTarget }, + }); } - return json -} + return json; +}; // State Machines .......................................................... -writer.elements['UMLStateMachine'] = function (elem) { - var json = writer.elements['UMLBehavior'](elem) - writer.setType(json, 'uml:StateMachine') - writer.writeElementArray(json, 'region', elem.regions) - return json -} - -writer.elements['UMLRegion'] = function (elem) { - var json = writer.elements['UMLModelElement'](elem) - writer.setType(json, 'uml:Region') - writer.writeElementArray(json, 'subvertex', elem.vertices) - writer.writeElementArray(json, 'transition', elem.transitions) - return json -} - -writer.elements['UMLVertex'] = function (elem) { - var json = writer.elements['UMLModelElement'](elem) - return json -} - -writer.elements['UMLPseudostate'] = function (elem) { - var json = writer.elements['UMLVertex'](elem) - writer.setType(json, 'uml:Pseudostate') - writer.writeEnum(json, 'kind', 'UMLPseudostateKind', elem.kind) - return json -} - -writer.elements['UMLConnectionPointReference'] = function (elem) { - var json = writer.elements['UMLVertex'](elem) - writer.setType(json, 'uml:ConnectionPointReference') - writer.writeRefArray(json, 'entry', elem.entry) - writer.writeRefArray(json, 'exit', elem.exit) - return json -} - -writer.elements['UMLState'] = function (elem) { - var json = writer.elements['UMLVertex'](elem) - writer.setType(json, 'uml:State') - writer.writeElementArray(json, 'region', elem.regions) - writer.writeElementArray(json, 'entry', elem.entryActivities) - writer.writeElementArray(json, 'exit', elem.exitActivities) - writer.writeElementArray(json, 'doActivity', elem.doActivities) - writer.writeRef(json, 'submachine', elem.submachine) - writer.writeElementArray(json, 'connection', elem.connections) - return json -} - -writer.elements['UMLFinalState'] = function (elem) { - var json = writer.elements['UMLVertex'](elem) - writer.setType(json, 'uml:FinalState') - return json -} - -writer.elements['UMLTransition'] = function (elem) { - var json = writer.elements['UMLDirectedRelationship'](elem) - writer.setType(json, 'uml:Transition') - writer.writeRef(json, 'source', elem.source) - writer.writeRef(json, 'target', elem.target) - writer.writeEnum(json, 'kind', 'UMLTransitionKind', elem.kind) +writer.elements["UMLStateMachine"] = function (elem) { + var json = writer.elements["UMLBehavior"](elem); + writer.setType(json, "uml:StateMachine"); + writer.writeElementArray(json, "region", elem.regions); + return json; +}; + +writer.elements["UMLRegion"] = function (elem) { + var json = writer.elements["UMLModelElement"](elem); + writer.setType(json, "uml:Region"); + writer.writeElementArray(json, "subvertex", elem.vertices); + writer.writeElementArray(json, "transition", elem.transitions); + return json; +}; + +writer.elements["UMLVertex"] = function (elem) { + var json = writer.elements["UMLModelElement"](elem); + return json; +}; + +writer.elements["UMLPseudostate"] = function (elem) { + var json = writer.elements["UMLVertex"](elem); + writer.setType(json, "uml:Pseudostate"); + writer.writeEnum(json, "kind", "UMLPseudostateKind", elem.kind); + return json; +}; + +writer.elements["UMLConnectionPointReference"] = function (elem) { + var json = writer.elements["UMLVertex"](elem); + writer.setType(json, "uml:ConnectionPointReference"); + writer.writeRefArray(json, "entry", elem.entry); + writer.writeRefArray(json, "exit", elem.exit); + return json; +}; + +writer.elements["UMLState"] = function (elem) { + var json = writer.elements["UMLVertex"](elem); + writer.setType(json, "uml:State"); + writer.writeElementArray(json, "region", elem.regions); + writer.writeElementArray(json, "entry", elem.entryActivities); + writer.writeElementArray(json, "exit", elem.exitActivities); + writer.writeElementArray(json, "doActivity", elem.doActivities); + writer.writeRef(json, "submachine", elem.submachine); + writer.writeElementArray(json, "connection", elem.connections); + return json; +}; + +writer.elements["UMLFinalState"] = function (elem) { + var json = writer.elements["UMLVertex"](elem); + writer.setType(json, "uml:FinalState"); + return json; +}; + +writer.elements["UMLTransition"] = function (elem) { + var json = writer.elements["UMLDirectedRelationship"](elem); + writer.setType(json, "uml:Transition"); + writer.writeRef(json, "source", elem.source); + writer.writeRef(json, "target", elem.target); + writer.writeEnum(json, "kind", "UMLTransitionKind", elem.kind); if (elem.guard && elem.guard.length > 0) { - json['guard'] = { - 'xmi:id': app.repository.generateGuid(), - 'xmi:type': 'uml:Constraint', - 'specification': elem.guard - } + json["guard"] = { + "xmi:id": app.repository.generateGuid(), + "xmi:type": "uml:Constraint", + specification: elem.guard, + }; } elem.triggers.forEach(function (e) { - writer.writeElement(json, 'ownedMember', e) - writer.addTo(json, 'trigger', { - 'xmi:id': app.repository.generateGuid(), - 'xmi:type': 'uml:Trigger', - 'name': e.name, - 'event': e._id - }) - }) - writer.writeElementArray(json, 'trigger', elem.triggers) - writer.writeElementArray(json, 'effect', elem.effects) - return json -} + writer.writeElement(json, "ownedMember", e); + writer.addTo(json, "trigger", { + "xmi:id": app.repository.generateGuid(), + "xmi:type": "uml:Trigger", + name: e.name, + event: e._id, + }); + }); + writer.writeElementArray(json, "trigger", elem.triggers); + writer.writeElementArray(json, "effect", elem.effects); + return json; +}; // Activities .............................................................. -writer.elements['UMLActivity'] = function (elem) { - var json = writer.elements['UMLBehavior'](elem) - writer.setType(json, 'uml:Activity') - writer.writeBoolean(json, 'isReadOnly', elem.isReadOnly) - writer.writeBoolean(json, 'isSingleExecution', elem.isSingleExecution) - writer.writeElementArray(json, 'groups', elem.groups) - writer.writeElementArray(json, 'node', elem.nodes) - writer.writeElementArray(json, 'edge', elem.edges) - return json -} - -writer.elements['UMLPin'] = function (elem) { - var json = writer.elements['UMLStructuralFeature'](elem) - writer.setType(json, 'uml:Pin') - return json -} - -writer.elements['UMLInputPin'] = function (elem) { - var json = writer.elements['UMLPin'](elem) - writer.setType(json, 'uml:InputPin') - return json -} - -writer.elements['UMLOutputPin'] = function (elem) { - var json = writer.elements['UMLPin'](elem) - writer.setType(json, 'uml:OutputPin') - return json -} - -writer.elements['UMLActivityNode'] = function (elem) { - var json = writer.elements['UMLModelElement'](elem) - writer.setType(json, 'uml:ActivityNode') - return json -} - -writer.elements['UMLAction'] = function (elem) { - var json = writer.elements['UMLActivityNode'](elem) +writer.elements["UMLActivity"] = function (elem) { + var json = writer.elements["UMLBehavior"](elem); + writer.setType(json, "uml:Activity"); + writer.writeBoolean(json, "isReadOnly", elem.isReadOnly); + writer.writeBoolean(json, "isSingleExecution", elem.isSingleExecution); + writer.writeElementArray(json, "groups", elem.groups); + writer.writeElementArray(json, "node", elem.nodes); + writer.writeElementArray(json, "edge", elem.edges); + return json; +}; + +writer.elements["UMLPin"] = function (elem) { + var json = writer.elements["UMLStructuralFeature"](elem); + writer.setType(json, "uml:Pin"); + return json; +}; + +writer.elements["UMLInputPin"] = function (elem) { + var json = writer.elements["UMLPin"](elem); + writer.setType(json, "uml:InputPin"); + return json; +}; + +writer.elements["UMLOutputPin"] = function (elem) { + var json = writer.elements["UMLPin"](elem); + writer.setType(json, "uml:OutputPin"); + return json; +}; + +writer.elements["UMLActivityNode"] = function (elem) { + var json = writer.elements["UMLModelElement"](elem); + writer.setType(json, "uml:ActivityNode"); + return json; +}; + +writer.elements["UMLAction"] = function (elem) { + var json = writer.elements["UMLActivityNode"](elem); switch (elem.kind) { - case type.UMLAction.ACK_OPAQUE: - writer.setType(json, 'uml:OpaqueAction') - break - case type.UMLAction.ACK_CREATE: - writer.setType(json, 'uml:CreateObjectAction') - writer.writeRef(json, 'classifier', elem.target) - break - case type.UMLAction.ACK_DESTROY: - writer.setType(json, 'uml:DestroyObjectAction') - writer.writeRef(json, 'target', elem.target) - break - case type.UMLAction.ACK_READ: - writer.setType(json, 'uml:ReadVariableAction') - break - case type.UMLAction.ACK_WRITE: - writer.setType(json, 'uml:WriteVariableAction') - break - case type.UMLAction.ACK_INSERT: - writer.setType(json, 'uml:OpaqueAction') - break - case type.UMLAction.ACK_DELETE: - writer.setType(json, 'uml:OpaqueAction') - break - case type.UMLAction.ACK_SENDSIGNAL: - writer.setType(json, 'uml:SendSignalAction') - writer.writeRef(json, 'signal', elem.target) - break - case type.UMLAction.ACK_ACCEPTSIGNAL: - writer.setType(json, 'uml:AcceptEventAction') - break - case type.UMLAction.ACK_TRIGGEREVENT: - writer.setType(json, 'uml:OpaqueAction') - break - case type.UMLAction.ACK_ACCEPTEVENT: - writer.setType(json, 'uml:AcceptEventAction') - break - case type.UMLAction.ACK_STRUCTURED: - writer.setType(json, 'uml:StructuredActivityNode') - break + case type.UMLAction.ACK_OPAQUE: + writer.setType(json, "uml:OpaqueAction"); + break; + case type.UMLAction.ACK_CREATE: + writer.setType(json, "uml:CreateObjectAction"); + writer.writeRef(json, "classifier", elem.target); + break; + case type.UMLAction.ACK_DESTROY: + writer.setType(json, "uml:DestroyObjectAction"); + writer.writeRef(json, "target", elem.target); + break; + case type.UMLAction.ACK_READ: + writer.setType(json, "uml:ReadVariableAction"); + break; + case type.UMLAction.ACK_WRITE: + writer.setType(json, "uml:WriteVariableAction"); + break; + case type.UMLAction.ACK_INSERT: + writer.setType(json, "uml:OpaqueAction"); + break; + case type.UMLAction.ACK_DELETE: + writer.setType(json, "uml:OpaqueAction"); + break; + case type.UMLAction.ACK_SENDSIGNAL: + writer.setType(json, "uml:SendSignalAction"); + writer.writeRef(json, "signal", elem.target); + break; + case type.UMLAction.ACK_ACCEPTSIGNAL: + writer.setType(json, "uml:AcceptEventAction"); + break; + case type.UMLAction.ACK_TRIGGEREVENT: + writer.setType(json, "uml:OpaqueAction"); + break; + case type.UMLAction.ACK_ACCEPTEVENT: + writer.setType(json, "uml:AcceptEventAction"); + break; + case type.UMLAction.ACK_STRUCTURED: + writer.setType(json, "uml:StructuredActivityNode"); + break; } - writer.writeElementArray(json, 'input', elem.inputs) - writer.writeElementArray(json, 'output', elem.outputs) - writer.writeBoolean(json, 'isLocallyReentrant', elem.isLocallyReentrant) - writer.writeBoolean(json, 'isSynchronous', elem.isSynchronous) - writer.writeString(json, 'language', elem.language) - writer.writeString(json, 'body', elem.body) - writer.writeElementArray(json, 'localPrecondition', elem.localPreconditions) - writer.writeElementArray(json, 'localPostcondition', elem.localPostconditions) - return json -} - -writer.elements['UMLObjectNode'] = function (elem) { - var json = writer.elements['UMLActivityNode'](elem) - writer.setType(json, 'uml:ObjectNode') - writer.writeBoolean(json, 'isControlType', elem.isControlType) - writer.writeEnum(json, 'ordering', 'UMLObjectNodeOrderingKind', elem.ordering) + writer.writeElementArray(json, "input", elem.inputs); + writer.writeElementArray(json, "output", elem.outputs); + writer.writeBoolean(json, "isLocallyReentrant", elem.isLocallyReentrant); + writer.writeBoolean(json, "isSynchronous", elem.isSynchronous); + writer.writeString(json, "language", elem.language); + writer.writeString(json, "body", elem.body); + writer.writeElementArray(json, "localPrecondition", elem.localPreconditions); + writer.writeElementArray( + json, + "localPostcondition", + elem.localPostconditions, + ); + return json; +}; + +writer.elements["UMLObjectNode"] = function (elem) { + var json = writer.elements["UMLActivityNode"](elem); + writer.setType(json, "uml:ObjectNode"); + writer.writeBoolean(json, "isControlType", elem.isControlType); + writer.writeEnum( + json, + "ordering", + "UMLObjectNodeOrderingKind", + elem.ordering, + ); if (elem.type && elem.type._id) { - writer.writeRef(json, 'type', elem.type) - } else if ((typeof elem.type === 'string') && elem.type.trim().length > 0) { + writer.writeRef(json, "type", elem.type); + } else if (typeof elem.type === "string" && elem.type.trim().length > 0) { var _typeNode = { - 'xmi:id': elem.type + '_id', - 'xmi:type': 'uml:DataType', - 'name': elem.type - } - writer.addToDeferedNode(_typeNode) - writer.writeString(json, 'type', _typeNode['xmi:id']) + "xmi:id": elem.type + "_id", + "xmi:type": "uml:DataType", + name: elem.type, + }; + writer.addToDeferedNode(_typeNode); + writer.writeString(json, "type", _typeNode["xmi:id"]); } - return json -} - -writer.elements['UMLControlNode'] = function (elem) { - var json = writer.elements['UMLActivityNode'](elem) - return json -} - -writer.elements['UMLInitialNode'] = function (elem) { - var json = writer.elements['UMLControlNode'](elem) - writer.setType(json, 'uml:InitialNode') - return json -} - -writer.elements['UMLFinalNode'] = function (elem) { - var json = writer.elements['UMLControlNode'](elem) - return json -} - -writer.elements['UMLActivityFinalNode'] = function (elem) { - var json = writer.elements['UMLFinalNode'](elem) - writer.setType(json, 'uml:ActivityFinalNode') - return json -} - -writer.elements['UMLFlowFinalNode'] = function (elem) { - var json = writer.elements['UMLFinalNode'](elem) - writer.setType(json, 'uml:FlowFinalNode') - return json -} - -writer.elements['UMLForkNode'] = function (elem) { - var json = writer.elements['UMLControlNode'](elem) - writer.setType(json, 'uml:ForkNode') - return json -} - -writer.elements['UMLJoinNode'] = function (elem) { - var json = writer.elements['UMLControlNode'](elem) - writer.setType(json, 'uml:JoinNode') - return json -} - -writer.elements['UMLMergeNode'] = function (elem) { - var json = writer.elements['UMLControlNode'](elem) - writer.setType(json, 'uml:MergeNode') - return json -} - -writer.elements['UMLDecisionNode'] = function (elem) { - var json = writer.elements['UMLControlNode'](elem) - writer.setType(json, 'uml:DecisionNode') - return json -} - -writer.elements['UMLActivityGroup'] = function (elem) { - var json = writer.elements['UMLModelElement'](elem) - writer.writeElementArray(json, 'subgroup', elem.subgroups) - return json -} - -writer.elements['UMLActivityPartition'] = function (elem) { - var json = writer.elements['UMLActivityGroup'](elem) - writer.setType(json, 'uml:ActivityPartition') - writer.writeElementArray(json, 'node', elem.nodes) - writer.writeElementArray(json, 'edge', elem.edges) - return json -} - -writer.elements['UMLActivityEdge'] = function (elem) { - var json = writer.elements['UMLDirectedRelationship'](elem) - writer.writeRef(json, 'source', elem.source) - writer.writeRef(json, 'target', elem.target) - writer.writeValueSpec(json, 'guard', 'uml:LiteralString', elem.guard) - writer.writeValueSpec(json, 'weight', 'uml:LiteralInteger', elem.weight) - return json -} - -writer.elements['UMLControlFlow'] = function (elem) { - var json = writer.elements['UMLActivityEdge'](elem) - writer.setType(json, 'uml:ControlFlow') - return json -} - -writer.elements['UMLObjectFlow'] = function (elem) { - var json = writer.elements['UMLActivityEdge'](elem) - writer.setType(json, 'uml:ObjectFlow') - return json -} + return json; +}; + +writer.elements["UMLControlNode"] = function (elem) { + var json = writer.elements["UMLActivityNode"](elem); + return json; +}; + +writer.elements["UMLInitialNode"] = function (elem) { + var json = writer.elements["UMLControlNode"](elem); + writer.setType(json, "uml:InitialNode"); + return json; +}; + +writer.elements["UMLFinalNode"] = function (elem) { + var json = writer.elements["UMLControlNode"](elem); + return json; +}; + +writer.elements["UMLActivityFinalNode"] = function (elem) { + var json = writer.elements["UMLFinalNode"](elem); + writer.setType(json, "uml:ActivityFinalNode"); + return json; +}; + +writer.elements["UMLFlowFinalNode"] = function (elem) { + var json = writer.elements["UMLFinalNode"](elem); + writer.setType(json, "uml:FlowFinalNode"); + return json; +}; + +writer.elements["UMLForkNode"] = function (elem) { + var json = writer.elements["UMLControlNode"](elem); + writer.setType(json, "uml:ForkNode"); + return json; +}; + +writer.elements["UMLJoinNode"] = function (elem) { + var json = writer.elements["UMLControlNode"](elem); + writer.setType(json, "uml:JoinNode"); + return json; +}; + +writer.elements["UMLMergeNode"] = function (elem) { + var json = writer.elements["UMLControlNode"](elem); + writer.setType(json, "uml:MergeNode"); + return json; +}; + +writer.elements["UMLDecisionNode"] = function (elem) { + var json = writer.elements["UMLControlNode"](elem); + writer.setType(json, "uml:DecisionNode"); + return json; +}; + +writer.elements["UMLActivityGroup"] = function (elem) { + var json = writer.elements["UMLModelElement"](elem); + writer.writeElementArray(json, "subgroup", elem.subgroups); + return json; +}; + +writer.elements["UMLActivityPartition"] = function (elem) { + var json = writer.elements["UMLActivityGroup"](elem); + writer.setType(json, "uml:ActivityPartition"); + writer.writeElementArray(json, "node", elem.nodes); + writer.writeElementArray(json, "edge", elem.edges); + return json; +}; + +writer.elements["UMLActivityEdge"] = function (elem) { + var json = writer.elements["UMLDirectedRelationship"](elem); + writer.writeRef(json, "source", elem.source); + writer.writeRef(json, "target", elem.target); + writer.writeValueSpec(json, "guard", "uml:LiteralString", elem.guard); + writer.writeValueSpec(json, "weight", "uml:LiteralInteger", elem.weight); + return json; +}; + +writer.elements["UMLControlFlow"] = function (elem) { + var json = writer.elements["UMLActivityEdge"](elem); + writer.setType(json, "uml:ControlFlow"); + return json; +}; + +writer.elements["UMLObjectFlow"] = function (elem) { + var json = writer.elements["UMLActivityEdge"](elem); + writer.setType(json, "uml:ObjectFlow"); + return json; +}; // Profiles ................................................................ -writer.elements['UMLProfile'] = function (elem) { - var json = writer.elements['UMLPackage'](elem) - writer.setType(json, 'uml:Profile') - return json -} +writer.elements["UMLProfile"] = function (elem) { + var json = writer.elements["UMLPackage"](elem); + writer.setType(json, "uml:Profile"); + return json; +}; -writer.elements['UMLStereotype'] = function (elem) { - var json = writer.elements['UMLClass'](elem) - writer.setType(json, 'uml:Stereotype') +writer.elements["UMLStereotype"] = function (elem) { + var json = writer.elements["UMLClass"](elem); + writer.setType(json, "uml:Stereotype"); // Write UMLExtension var _extensions = app.repository.getRelationshipsOf(elem, function (r) { - return (r instanceof type.UMLExtension) && (r.source === elem) - }) + return r instanceof type.UMLExtension && r.source === elem; + }); if (_extensions.length > 0) { var _extension = { - 'xmi:id': app.repository.generateGuid(), - 'xmi:type': 'uml:Extension', - 'memberEnd': [], - 'ownedEnd': [ + "xmi:id": app.repository.generateGuid(), + "xmi:type": "uml:Extension", + memberEnd: [], + ownedEnd: [ { - 'xmi:id': app.repository.generateGuid(), - 'xmi:type': 'uml:ExtensionEnd', - 'type': elem._id - } - ] - } - writer.addTo(json, 'ownedMember', _extension) + "xmi:id": app.repository.generateGuid(), + "xmi:type": "uml:ExtensionEnd", + type: elem._id, + }, + ], + }; + writer.addTo(json, "ownedMember", _extension); _extensions.forEach(function (ex) { - var _type = 'Class' - if (ex.target && ex.target.name && ex.target.name.substring(0, 3) === 'UML') { - _type = ex.target.name.substring(3, ex.target.name.length) + var _type = "Class"; + if ( + ex.target && + ex.target.name && + ex.target.name.substring(0, 3) === "UML" + ) { + _type = ex.target.name.substring(3, ex.target.name.length); } var node = { - 'xmi:id': ex._id, - 'xmi:type': 'uml:Property', - 'name': 'base_' + _type, - 'association': _extension['xmi:id'], - 'type': { 'href': 'http://schema.omg.org/spec/UML/2.0/uml.xml#' + _type } - } - writer.addTo(json, 'ownedAttribute', node) - }) - writer.writeRefArray(_extension, 'memberEnd', _extensions) + "xmi:id": ex._id, + "xmi:type": "uml:Property", + name: "base_" + _type, + association: _extension["xmi:id"], + type: { href: "http://schema.omg.org/spec/UML/2.0/uml.xml#" + _type }, + }; + writer.addTo(json, "ownedAttribute", node); + }); + writer.writeRefArray(_extension, "memberEnd", _extensions); } - return json -} + return json; +}; diff --git a/uml2-import.js b/uml2-import.js index 10e9d4f..69940fd 100644 --- a/uml2-import.js +++ b/uml2-import.js @@ -21,1483 +21,1573 @@ * */ -const reader = require('./xmi21-reader') +const reader = require("./xmi21-reader"); -function addTo (json, field, element) { +function addTo(json, field, element) { if (!Array.isArray(json[field])) { - json[field] = [] + json[field] = []; } - var arr = json[field] + var arr = json[field]; if (element) { - arr.push(element) + arr.push(element); } } -function appendTo (json, field, elements) { +function appendTo(json, field, elements) { if (!Array.isArray(json[field])) { - json[field] = [] + json[field] = []; } - var arr = json[field] + var arr = json[field]; elements.forEach(function (elem) { - if (!arr.includes(elem) && !arr.some(function (item) { return item._id === elem._id })) { - arr.push(elem) + if ( + !arr.includes(elem) && + !arr.some(function (item) { + return item._id === elem._id; + }) + ) { + arr.push(elem); } - }) + }); } // Enumerations ............................................................ -reader.enumerations['uml:AggregationKind'] = { - 'none': type.UMLAttribute.AK_NONE, - 'shared': type.UMLAttribute.AK_SHARED, - 'composite': type.UMLAttribute.AK_COMPOSITE -} - -reader.enumerations['uml:VisibilityKind'] = { - 'public': type.UMLModelElement.VK_PUBLIC, - 'protected': type.UMLModelElement.VK_PROTECTED, - 'private': type.UMLModelElement.VK_PRIVATE, - 'package': type.UMLModelElement.VK_PACKAGE -} - -reader.enumerations['uml:ParameterDirectionKind'] = { - 'in': type.UMLParameter.DK_IN, - 'inout': type.UMLParameter.DK_INOUT, - 'out': type.UMLParameter.DK_OUT, - 'return': type.UMLParameter.DK_RETURN -} - -reader.enumerations['uml:InteractionOperatorKind'] = { - 'opt': type.UMLCombinedFragment.IOK_OPT, - 'par': type.UMLCombinedFragment.IOK_PAR, - 'loop': type.UMLCombinedFragment.IOK_LOOP, - 'critical': type.UMLCombinedFragment.IOK_CRITICAL, - 'neg': type.UMLCombinedFragment.IOK_NEG, - 'assert': type.UMLCombinedFragment.IOK_ASSERT, - 'strict': type.UMLCombinedFragment.IOK_STRICT, - 'seq': type.UMLCombinedFragment.IOK_SEQ, - 'ignore': type.UMLCombinedFragment.IOK_IGNORE, - 'consider': type.UMLCombinedFragment.IOK_CONSIDER, - 'break': type.UMLCombinedFragment.IOK_BREAK -} - -reader.enumerations['uml:MessageSort'] = { - 'synchCall': type.UMLMessage.MS_SYNCHCALL, - 'asynchCall': type.UMLMessage.MS_ASYNCHCALL, - 'asynchSignal': type.UMLMessage.MS_ASYNCHSIGNAL, - 'createMessage': type.UMLMessage.MS_CREATEMESSAGE, - 'deleteMessage': type.UMLMessage.MS_DELETEMESSAGE, - 'reply': type.UMLMessage.MS_REPLY -} - -reader.enumerations['uml:PseudostateKind'] = { - 'initial': type.UMLPseudostate.PSK_INITIAL, - 'deepHistory': type.UMLPseudostate.PSK_DEEPHISTORY, - 'shallowHistory': type.UMLPseudostate.PSK_SHALLOWHISTORY, - 'join': type.UMLPseudostate.PSK_JOIN, - 'fork': type.UMLPseudostate.PSK_FORK, - 'junction': type.UMLPseudostate.PSK_JUNCTION, - 'choice': type.UMLPseudostate.PSK_CHOICE, - 'entryPoint': type.UMLPseudostate.PSK_ENTRYPOINT, - 'exitPoint': type.UMLPseudostate.PSK_EXITPOINT, - 'terminate': type.UMLPseudostate.PSK_TERMINATE, - 'final': type.UMLPseudostate.PSK_TERMINATE // for VP -} - -reader.enumerations['uml:TransitionKind'] = { - 'internal': type.UMLTransition.TK_INTERNAL, - 'local': type.UMLTransition.TK_LOCAL, - 'external': type.UMLTransition.TK_EXTERNAL -} +reader.enumerations["uml:AggregationKind"] = { + none: type.UMLAttribute.AK_NONE, + shared: type.UMLAttribute.AK_SHARED, + composite: type.UMLAttribute.AK_COMPOSITE, +}; + +reader.enumerations["uml:VisibilityKind"] = { + public: type.UMLModelElement.VK_PUBLIC, + protected: type.UMLModelElement.VK_PROTECTED, + private: type.UMLModelElement.VK_PRIVATE, + package: type.UMLModelElement.VK_PACKAGE, +}; + +reader.enumerations["uml:ParameterDirectionKind"] = { + in: type.UMLParameter.DK_IN, + inout: type.UMLParameter.DK_INOUT, + out: type.UMLParameter.DK_OUT, + return: type.UMLParameter.DK_RETURN, +}; + +reader.enumerations["uml:InteractionOperatorKind"] = { + opt: type.UMLCombinedFragment.IOK_OPT, + par: type.UMLCombinedFragment.IOK_PAR, + loop: type.UMLCombinedFragment.IOK_LOOP, + critical: type.UMLCombinedFragment.IOK_CRITICAL, + neg: type.UMLCombinedFragment.IOK_NEG, + assert: type.UMLCombinedFragment.IOK_ASSERT, + strict: type.UMLCombinedFragment.IOK_STRICT, + seq: type.UMLCombinedFragment.IOK_SEQ, + ignore: type.UMLCombinedFragment.IOK_IGNORE, + consider: type.UMLCombinedFragment.IOK_CONSIDER, + break: type.UMLCombinedFragment.IOK_BREAK, +}; + +reader.enumerations["uml:MessageSort"] = { + synchCall: type.UMLMessage.MS_SYNCHCALL, + asynchCall: type.UMLMessage.MS_ASYNCHCALL, + asynchSignal: type.UMLMessage.MS_ASYNCHSIGNAL, + createMessage: type.UMLMessage.MS_CREATEMESSAGE, + deleteMessage: type.UMLMessage.MS_DELETEMESSAGE, + reply: type.UMLMessage.MS_REPLY, +}; + +reader.enumerations["uml:PseudostateKind"] = { + initial: type.UMLPseudostate.PSK_INITIAL, + deepHistory: type.UMLPseudostate.PSK_DEEPHISTORY, + shallowHistory: type.UMLPseudostate.PSK_SHALLOWHISTORY, + join: type.UMLPseudostate.PSK_JOIN, + fork: type.UMLPseudostate.PSK_FORK, + junction: type.UMLPseudostate.PSK_JUNCTION, + choice: type.UMLPseudostate.PSK_CHOICE, + entryPoint: type.UMLPseudostate.PSK_ENTRYPOINT, + exitPoint: type.UMLPseudostate.PSK_EXITPOINT, + terminate: type.UMLPseudostate.PSK_TERMINATE, + final: type.UMLPseudostate.PSK_TERMINATE, // for VP +}; + +reader.enumerations["uml:TransitionKind"] = { + internal: type.UMLTransition.TK_INTERNAL, + local: type.UMLTransition.TK_LOCAL, + external: type.UMLTransition.TK_EXTERNAL, +}; // Kernel .................................................................. -reader.elements['uml:Element'] = function (node) { - var json = { tags: [] } - var _id = reader.readString(node, 'xmi:id') +reader.elements["uml:Element"] = function (node) { + var json = { tags: [] }; + var _id = reader.readString(node, "xmi:id"); if (!_id) { - _id = app.repository.generateGuid() - node.setAttribute('xmi:id', _id) + _id = app.repository.generateGuid(); + node.setAttribute("xmi:id", _id); } - json['_id'] = _id - return json -} + json["_id"] = _id; + return json; +}; -reader.elements['uml:Relationship'] = function (node) { - var json = reader.elements['uml:Element'](node) - return json -} +reader.elements["uml:Relationship"] = function (node) { + var json = reader.elements["uml:Element"](node); + return json; +}; -reader.elements['uml:DirectedRelationship'] = function (node) { - var json = reader.elements['uml:Element'](node) - return json -} +reader.elements["uml:DirectedRelationship"] = function (node) { + var json = reader.elements["uml:Element"](node); + return json; +}; // Expressions ............................................................. -reader.elements['uml:ValueSpecification'] = function (node) { - var json = reader.elements['uml:Element'](node) - return json -} +reader.elements["uml:ValueSpecification"] = function (node) { + var json = reader.elements["uml:Element"](node); + return json; +}; -reader.elements['uml:LiteralSpecification'] = function (node) { - var json = reader.elements['uml:ValueSpecification'](node) - return json -} +reader.elements["uml:LiteralSpecification"] = function (node) { + var json = reader.elements["uml:ValueSpecification"](node); + return json; +}; -reader.elements['uml:LiteralBoolean'] = function (node) { +reader.elements["uml:LiteralBoolean"] = function (node) { // var json = reader.elements['uml:LiteralSpecification'](node) - var val = reader.readBoolean(node, 'value', false) - return val -} + var val = reader.readBoolean(node, "value", false); + return val; +}; -reader.elements['uml:LiteralInteger'] = function (node) { +reader.elements["uml:LiteralInteger"] = function (node) { // var json = reader.elements['uml:LiteralSpecification'](node) - var val = reader.readInteger(node, 'value', 0) - return val -} + var val = reader.readInteger(node, "value", 0); + return val; +}; -reader.elements['uml:LiteralString'] = function (node) { +reader.elements["uml:LiteralString"] = function (node) { // var json = reader.elements['uml:LiteralSpecification'](node); - var val = reader.readString(node, 'value', '') - return val -} + var val = reader.readString(node, "value", ""); + return val; +}; -reader.elements['uml:LiteralUnlimitedNatural'] = function (node) { +reader.elements["uml:LiteralUnlimitedNatural"] = function (node) { // var json = reader.elements['uml:LiteralSpecification'](node); - var val = reader.readString(node, 'value', '') - if (val === '-1') { // for EA - val = '*' + var val = reader.readString(node, "value", ""); + if (val === "-1") { + // for EA + val = "*"; } - return val -} + return val; +}; -reader.elements['uml:LiteralNull'] = function (node) { +reader.elements["uml:LiteralNull"] = function (node) { // var json = reader.elements['uml:LiteralSpecification'](node) - return null -} + return null; +}; -reader.elements['uml:OpaqueExpression'] = function (node) { +reader.elements["uml:OpaqueExpression"] = function (node) { // var json = reader.elements['uml:ValueSpecification'](node) - var val = reader.readString(node, 'body', '') - return val -} + var val = reader.readString(node, "body", ""); + return val; +}; // Core .................................................................... -reader.elements['uml:MultiplicityElement'] = function (node) { - var json = reader.elements['uml:Element'](node) - json['isOrdered'] = reader.readBoolean(node, 'isOrdered', false) - json['isUnique'] = reader.readBoolean(node, 'isUnique', false) - var lowerValue = reader.readElement(node, 'lowerValue') - var upperValue = reader.readElement(node, 'upperValue') +reader.elements["uml:MultiplicityElement"] = function (node) { + var json = reader.elements["uml:Element"](node); + json["isOrdered"] = reader.readBoolean(node, "isOrdered", false); + json["isUnique"] = reader.readBoolean(node, "isUnique", false); + var lowerValue = reader.readElement(node, "lowerValue"); + var upperValue = reader.readElement(node, "upperValue"); if (lowerValue !== null && upperValue !== null) { - json['multiplicity'] = lowerValue + '..' + upperValue + json["multiplicity"] = lowerValue + ".." + upperValue; } else if (lowerValue !== null) { - json['multiplicity'] = lowerValue + json["multiplicity"] = lowerValue; } else if (upperValue !== null) { - json['multiplicity'] = upperValue + json["multiplicity"] = upperValue; } - if (json['multiplicity'] === '*..*') { // for EA - json['multiplicity'] = '*' + if (json["multiplicity"] === "*..*") { + // for EA + json["multiplicity"] = "*"; } - if (json['multiplicity'] === '1..1' || json['multiplicity'] === '0..0') { // for EA - json['multiplicity'] = '' + if (json["multiplicity"] === "1..1" || json["multiplicity"] === "0..0") { + // for EA + json["multiplicity"] = ""; } - return json -} - -reader.elements['uml:NamedElement'] = function (node) { - var json = reader.elements['uml:Element'](node) - json['name'] = reader.readString(node, 'name', '') - json['visibility'] = reader.readEnum(node, 'visibility', 'uml:VisibilityKind', type.UMLModelElement.VK_PUBLIC) - return json -} - -reader.elements['uml:PackageableElement'] = function (node) { - var json = reader.elements['uml:NamedElement'](node) - return json -} - -reader.elements['uml:Namespace'] = function (node) { - var json = reader.elements['uml:NamedElement'](node) - appendTo(json, 'ownedElements', reader.readElementArray(node, 'ownedMember')) - return json -} - -reader.elements['uml:Package'] = function (node) { - var json = reader.elements['uml:Namespace'](node) - Object.assign(json, reader.elements['uml:PackageableElement'](node)) - json['_type'] = 'UMLPackage' - appendTo(json, 'ownedElements', reader.readElementArray(node, 'packagedElement')) + return json; +}; + +reader.elements["uml:NamedElement"] = function (node) { + var json = reader.elements["uml:Element"](node); + json["name"] = reader.readString(node, "name", ""); + json["visibility"] = reader.readEnum( + node, + "visibility", + "uml:VisibilityKind", + type.UMLModelElement.VK_PUBLIC, + ); + return json; +}; + +reader.elements["uml:PackageableElement"] = function (node) { + var json = reader.elements["uml:NamedElement"](node); + return json; +}; + +reader.elements["uml:Namespace"] = function (node) { + var json = reader.elements["uml:NamedElement"](node); + appendTo(json, "ownedElements", reader.readElementArray(node, "ownedMember")); + return json; +}; + +reader.elements["uml:Package"] = function (node) { + var json = reader.elements["uml:Namespace"](node); + Object.assign(json, reader.elements["uml:PackageableElement"](node)); + json["_type"] = "UMLPackage"; + appendTo( + json, + "ownedElements", + reader.readElementArray(node, "packagedElement"), + ); // TODO: ownedType // TODO: nestedPackage - appendTo(json, 'ownedElements', reader.readElementArray(node, 'ownedConnector')) // for EA - return json -} - -reader.elements['uml:Model'] = function (node) { - var json = reader.elements['uml:Package'](node) - json['_type'] = 'UMLModel' - return json -} - -reader.elements['uml:TypedElement'] = function (node) { - var json = reader.elements['uml:NamedElement'](node) - json['type'] = reader.readRef(node, 'type') + appendTo( + json, + "ownedElements", + reader.readElementArray(node, "ownedConnector"), + ); // for EA + return json; +}; + +reader.elements["uml:Model"] = function (node) { + var json = reader.elements["uml:Package"](node); + json["_type"] = "UMLModel"; + return json; +}; + +reader.elements["uml:TypedElement"] = function (node) { + var json = reader.elements["uml:NamedElement"](node); + json["type"] = reader.readRef(node, "type"); // TODO: read type for EA - return json -} + return json; +}; -reader.elements['uml:RedefinableElement'] = function (node) { - var json = reader.elements['uml:NamedElement'](node) - json['isLeaf'] = reader.readBoolean(node, 'isLeaf', false) - return json -} +reader.elements["uml:RedefinableElement"] = function (node) { + var json = reader.elements["uml:NamedElement"](node); + json["isLeaf"] = reader.readBoolean(node, "isLeaf", false); + return json; +}; -reader.elements['uml:ConnectableElement'] = function (node) { - var json = reader.elements['uml:TypedElement'](node) - return json -} +reader.elements["uml:ConnectableElement"] = function (node) { + var json = reader.elements["uml:TypedElement"](node); + return json; +}; // TODO: Constraint // Features ................................................................ -reader.elements['uml:Feature'] = function (node) { - var json = reader.elements['uml:RedefinableElement'](node) - json['isStatic'] = reader.readBoolean(node, 'isStatic', false) - return json -} - -reader.elements['uml:StructuralFeature'] = function (node) { - var json = reader.elements['uml:Feature'](node) - Object.assign(json, reader.elements['uml:TypedElement'](node)) - Object.assign(json, reader.elements['uml:MultiplicityElement'](node)) - json['isReadOnly'] = reader.readBoolean(node, 'isReadOnly', false) - return json -} - -reader.elements['uml:Property'] = function (node) { - var json = reader.elements['uml:StructuralFeature'](node) - Object.assign(json, reader.elements['uml:ConnectableElement'](node)) - json['_type'] = 'UMLAttribute' - json['isDerived'] = reader.readBoolean(node, 'isDerived', false) +reader.elements["uml:Feature"] = function (node) { + var json = reader.elements["uml:RedefinableElement"](node); + json["isStatic"] = reader.readBoolean(node, "isStatic", false); + return json; +}; + +reader.elements["uml:StructuralFeature"] = function (node) { + var json = reader.elements["uml:Feature"](node); + Object.assign(json, reader.elements["uml:TypedElement"](node)); + Object.assign(json, reader.elements["uml:MultiplicityElement"](node)); + json["isReadOnly"] = reader.readBoolean(node, "isReadOnly", false); + return json; +}; + +reader.elements["uml:Property"] = function (node) { + var json = reader.elements["uml:StructuralFeature"](node); + Object.assign(json, reader.elements["uml:ConnectableElement"](node)); + json["_type"] = "UMLAttribute"; + json["isDerived"] = reader.readBoolean(node, "isDerived", false); // isDerivedUnion - json['aggregation'] = reader.readEnum(node, 'aggregation', 'uml:AggregationKind', type.UMLAttribute.AK_NONE) - json['defaultValue'] = reader.readElement(node, 'defaultValue') || '' + json["aggregation"] = reader.readEnum( + node, + "aggregation", + "uml:AggregationKind", + type.UMLAttribute.AK_NONE, + ); + json["defaultValue"] = reader.readElement(node, "defaultValue") || ""; // Read as an AssociationEnd - json['navigable'] = reader.readBoolean(node, 'isNavigable', false) - json['qualifiers'] = reader.readElementArray(node, 'qualifier') || [] - return json -} - -reader.elements['uml:Parameter'] = function (node) { - var json = reader.elements['uml:TypedElement'](node) - Object.assign(json, reader.elements['uml:MultiplicityElement'](node)) - json['_type'] = 'UMLParameter' - json['defaultValue'] = reader.readElement(node, 'defaultValue') || '' - json['direction'] = - reader.readEnum(node, 'direction', 'uml:ParameterDirectionKind') || - reader.readEnum(node, 'kind', 'uml:ParameterDirectionKind') || - type.UMLParameter.DK_IN - return json -} - -reader.elements['uml:BehavioralFeature'] = function (node) { - var json = reader.elements['uml:Feature'](node) - Object.assign(json, reader.elements['uml:Namespace'](node)) - json['parameters'] = reader.readElementArray(node, 'ownedParameter', 'uml:Parameter') - return json -} - -reader.elements['uml:Operation'] = function (node) { - var json = reader.elements['uml:BehavioralFeature'](node) - json['_type'] = 'UMLOperation' - json['isQuery'] = reader.readBoolean(node, 'isQuery', false) - json['isAbstract'] = reader.readBoolean(node, 'isAbstract', false) - return json -} + json["navigable"] = reader.readBoolean(node, "isNavigable", false); + json["qualifiers"] = reader.readElementArray(node, "qualifier") || []; + return json; +}; + +reader.elements["uml:Parameter"] = function (node) { + var json = reader.elements["uml:TypedElement"](node); + Object.assign(json, reader.elements["uml:MultiplicityElement"](node)); + json["_type"] = "UMLParameter"; + json["defaultValue"] = reader.readElement(node, "defaultValue") || ""; + json["direction"] = + reader.readEnum(node, "direction", "uml:ParameterDirectionKind") || + reader.readEnum(node, "kind", "uml:ParameterDirectionKind") || + type.UMLParameter.DK_IN; + return json; +}; + +reader.elements["uml:BehavioralFeature"] = function (node) { + var json = reader.elements["uml:Feature"](node); + Object.assign(json, reader.elements["uml:Namespace"](node)); + json["parameters"] = reader.readElementArray( + node, + "ownedParameter", + "uml:Parameter", + ); + return json; +}; + +reader.elements["uml:Operation"] = function (node) { + var json = reader.elements["uml:BehavioralFeature"](node); + json["_type"] = "UMLOperation"; + json["isQuery"] = reader.readBoolean(node, "isQuery", false); + json["isAbstract"] = reader.readBoolean(node, "isAbstract", false); + return json; +}; // Templates ............................................................... -reader.elements['uml:TemplateableElement'] = function (node) { - var json = reader.elements['uml:Element'](node) - var ts = reader.readElement(node, 'ownedTemplateSignature') - if (ts && ts['__ownedParameter']) { - ts['__ownedParameter'].forEach(function (e) { - addTo(json, 'templateParameters', e) - e._parent = { '$ref': json._id } - }) +reader.elements["uml:TemplateableElement"] = function (node) { + var json = reader.elements["uml:Element"](node); + var ts = reader.readElement(node, "ownedTemplateSignature"); + if (ts && ts["__ownedParameter"]) { + ts["__ownedParameter"].forEach(function (e) { + addTo(json, "templateParameters", e); + e._parent = { $ref: json._id }; + }); } - return json -} - -reader.elements['uml:ParameterableElement'] = function (node) { - var json = reader.elements['uml:Element'](node) - return json -} - -reader.elements['uml:TemplateSignature'] = function (node) { - var json = reader.elements['uml:Element'](node) - json['__ownedParameter'] = reader.readElementArray(node, 'ownedParameter') - return json -} - -reader.elements['uml:RedefinableTemplateSignature'] = function (node) { - var json = reader.elements['uml:TemplateSignature'](node) - Object.assign(json, reader.elements['uml:RedefinableElement'](node)) - return json -} - -reader.elements['uml:TemplateParameter'] = function (node) { - var json = reader.elements['uml:Element'](node) - json['_type'] = 'UMLTemplateParameter' - var pe = reader.readElement(node, 'ownedParameteredElement') - json['name'] = (pe ? pe.name : null) || reader.readString(node, 'name') || '' - json['defaultValue'] = reader.readElement(node, 'defaultValue') || /* for VP */ '' + return json; +}; + +reader.elements["uml:ParameterableElement"] = function (node) { + var json = reader.elements["uml:Element"](node); + return json; +}; + +reader.elements["uml:TemplateSignature"] = function (node) { + var json = reader.elements["uml:Element"](node); + json["__ownedParameter"] = reader.readElementArray(node, "ownedParameter"); + return json; +}; + +reader.elements["uml:RedefinableTemplateSignature"] = function (node) { + var json = reader.elements["uml:TemplateSignature"](node); + Object.assign(json, reader.elements["uml:RedefinableElement"](node)); + return json; +}; + +reader.elements["uml:TemplateParameter"] = function (node) { + var json = reader.elements["uml:Element"](node); + json["_type"] = "UMLTemplateParameter"; + var pe = reader.readElement(node, "ownedParameteredElement"); + json["name"] = (pe ? pe.name : null) || reader.readString(node, "name") || ""; + json["defaultValue"] = + reader.readElement(node, "defaultValue") || /* for VP */ ""; // TODO: defaultValue for EA // TODO: parameterType - return json -} + return json; +}; -reader.elements['uml:ClassifierTemplateParameter'] = function (node) { - var json = reader.elements['uml:TemplateParameter'](node) - return json -} +reader.elements["uml:ClassifierTemplateParameter"] = function (node) { + var json = reader.elements["uml:TemplateParameter"](node); + return json; +}; // Instances ............................................................... -reader.elements['uml:InstanceSpecification'] = function (node) { - var json = reader.elements['uml:NamedElement'](node) - json['specification'] = reader.readElement(node, 'specification') - json['_type'] = 'UMLObject' - json['classifier'] = reader.readRef(node, 'classifier') - json['slots'] = reader.readElementArray(node, 'slot') +reader.elements["uml:InstanceSpecification"] = function (node) { + var json = reader.elements["uml:NamedElement"](node); + json["specification"] = reader.readElement(node, "specification"); + json["_type"] = "UMLObject"; + json["classifier"] = reader.readRef(node, "classifier"); + json["slots"] = reader.readElementArray(node, "slot"); // TODO: Link is represented as InstanceSpecification with extensions in VP - return json -} + return json; +}; -reader.elements['uml:Slot'] = function (node) { - var json = reader.elements['uml:Element'](node) - json['_type'] = 'UMLSlot' - json['value'] = reader.readElement(node, 'value') || '' - json['definingFeature'] = reader.readRef(node, 'definingFeature') - return json -} +reader.elements["uml:Slot"] = function (node) { + var json = reader.elements["uml:Element"](node); + json["_type"] = "UMLSlot"; + json["value"] = reader.readElement(node, "value") || ""; + json["definingFeature"] = reader.readRef(node, "definingFeature"); + return json; +}; // Types ................................................................... -reader.elements['uml:Type'] = function (node) { - var json = reader.elements['uml:PackageableElement'](node) - return json -} - -reader.elements['uml:Classifier'] = function (node) { - var json = reader.elements['uml:Namespace'](node) - Object.assign(json, reader.elements['uml:RedefinableElement'](node)) - Object.assign(json, reader.elements['uml:Type'](node)) - Object.assign(json, reader.elements['uml:TemplateableElement'](node)) - Object.assign(json, reader.elements['uml:ParameterableElement'](node)) - json['isAbstract'] = reader.readBoolean(node, 'isAbstract', false) - json['attributes'] = reader.readElementArray(node, 'ownedAttribute', 'uml:Property') - json['operations'] = reader.readElementArray(node, 'ownedOperation', 'uml:Operation') - var _generalizations = reader.readElementArray(node, 'generalization') +reader.elements["uml:Type"] = function (node) { + var json = reader.elements["uml:PackageableElement"](node); + return json; +}; + +reader.elements["uml:Classifier"] = function (node) { + var json = reader.elements["uml:Namespace"](node); + Object.assign(json, reader.elements["uml:RedefinableElement"](node)); + Object.assign(json, reader.elements["uml:Type"](node)); + Object.assign(json, reader.elements["uml:TemplateableElement"](node)); + Object.assign(json, reader.elements["uml:ParameterableElement"](node)); + json["isAbstract"] = reader.readBoolean(node, "isAbstract", false); + json["attributes"] = reader.readElementArray( + node, + "ownedAttribute", + "uml:Property", + ); + json["operations"] = reader.readElementArray( + node, + "ownedOperation", + "uml:Operation", + ); + var _generalizations = reader.readElementArray(node, "generalization"); _generalizations.forEach(function (g) { - g['source'] = { '$ref': json._id } - addTo(json, 'ownedElements', g) - }) - appendTo(json, 'ownedElements', reader.readElementArray(node, 'collaborationUse')) - appendTo(json, 'ownedElements', reader.readElementArray(node, 'nestedClassifier')) - return json -} - -reader.elements['uml:StructuredClassifier'] = function (node) { - var json = reader.elements['uml:Classifier'](node) - appendTo(json, 'ownedElements', reader.readElementArray(node, 'ownedConnector')) - return json -} - -reader.elements['uml:EncapsulatedClassifier'] = function (node) { - var json = reader.elements['uml:StructuredClassifier'](node) - appendTo(json, 'attributes', reader.readElementArray(node, 'ownedPort')) - return json -} - -reader.elements['uml:BehavioredClassifier'] = function (node) { - var json = reader.elements['uml:Classifier'](node) - json['behaviors'] = reader.readElementArray(node, 'ownedBehavior') - return json -} - -reader.elements['uml:Class'] = function (node) { - var json = reader.elements['uml:Classifier'](node) - var _encapsulated = reader.elements['uml:EncapsulatedClassifier'](node) - var _behaviored = reader.elements['uml:BehavioredClassifier'](node) - Object.assign(json, _encapsulated) - Object.assign(json, _behaviored) - appendTo(json, 'ownedElements', _encapsulated.ownedElements) - appendTo(json, 'ownedElements', _behaviored.ownedElements) - appendTo(json, 'attributes', _encapsulated.attributes) - json['_type'] = 'UMLClass' - return json -} - -reader.elements['uml:Interface'] = function (node) { - var json = reader.elements['uml:Classifier'](node) - json['_type'] = 'UMLInterface' - return json -} - -reader.elements['uml:DataType'] = function (node) { - var json = reader.elements['uml:Classifier'](node) - json['_type'] = 'UMLDataType' - return json -} - -reader.elements['uml:PrimitiveType'] = function (node) { - var json = reader.elements['uml:DataType'](node) - json['_type'] = 'UMLPrimitiveType' - return json -} - -reader.elements['uml:EnumerationLiteral'] = function (node) { - var json = reader.elements['uml:InstanceSpecification'](node) - json['_type'] = 'UMLEnumerationLiteral' - return json -} - -reader.elements['uml:Enumeration'] = function (node) { - var json = reader.elements['uml:DataType'](node) - json['_type'] = 'UMLEnumeration' - json['literals'] = reader.readElementArray(node, 'ownedLiteral') - return json -} - -reader.elements['uml:Generalization'] = function (node) { - var json = reader.elements['uml:DirectedRelationship'](node) - json['_type'] = 'UMLGeneralization' - json['target'] = reader.readRef(node, 'general') - return json -} - -reader.elements['uml:Dependency'] = function (node) { - var json = reader.elements['uml:DirectedRelationship'](node) - Object.assign(json, reader.elements['uml:PackageableElement'](node)) - json['_type'] = 'UMLDependency' - json['source'] = reader.readRef(node, 'client') - json['target'] = reader.readRef(node, 'supplier') - return json -} - -reader.elements['uml:Abstraction'] = function (node) { - var json = reader.elements['uml:Dependency'](node) - json['_type'] = 'UMLAbstraction' - return json -} - -reader.elements['uml:Usage'] = function (node) { - var json = reader.elements['uml:Dependency'](node) - json['_type'] = 'UMLDependency' - json['stereotype'] = 'use' - return json -} - -reader.elements['uml:Realization'] = function (node) { - var json = reader.elements['uml:Abstraction'](node) - json['_type'] = 'UMLRealization' - return json -} - -reader.elements['uml:InterfaceRealization'] = function (node) { - var json = reader.elements['uml:Realization'](node) - json['_type'] = 'UMLInterfaceRealization' - return json -} - -reader.elements['uml:Association'] = function (node) { - var json = reader.elements['uml:Relationship'](node) - Object.assign(json, reader.elements['uml:Classifier'](node)) - json['_type'] = 'UMLAssociation' - var _ends = reader.readElementArray(node, 'ownedEnd') - var _endRefs = reader.readRefArray(node, 'memberEnd') + g["source"] = { $ref: json._id }; + addTo(json, "ownedElements", g); + }); + appendTo( + json, + "ownedElements", + reader.readElementArray(node, "collaborationUse"), + ); + appendTo( + json, + "ownedElements", + reader.readElementArray(node, "nestedClassifier"), + ); + return json; +}; + +reader.elements["uml:StructuredClassifier"] = function (node) { + var json = reader.elements["uml:Classifier"](node); + appendTo( + json, + "ownedElements", + reader.readElementArray(node, "ownedConnector"), + ); + return json; +}; + +reader.elements["uml:EncapsulatedClassifier"] = function (node) { + var json = reader.elements["uml:StructuredClassifier"](node); + appendTo(json, "attributes", reader.readElementArray(node, "ownedPort")); + return json; +}; + +reader.elements["uml:BehavioredClassifier"] = function (node) { + var json = reader.elements["uml:Classifier"](node); + json["behaviors"] = reader.readElementArray(node, "ownedBehavior"); + return json; +}; + +reader.elements["uml:Class"] = function (node) { + var json = reader.elements["uml:Classifier"](node); + var _encapsulated = reader.elements["uml:EncapsulatedClassifier"](node); + var _behaviored = reader.elements["uml:BehavioredClassifier"](node); + Object.assign(json, _encapsulated); + Object.assign(json, _behaviored); + appendTo(json, "ownedElements", _encapsulated.ownedElements); + appendTo(json, "ownedElements", _behaviored.ownedElements); + appendTo(json, "attributes", _encapsulated.attributes); + json["_type"] = "UMLClass"; + return json; +}; + +reader.elements["uml:Interface"] = function (node) { + var json = reader.elements["uml:Classifier"](node); + json["_type"] = "UMLInterface"; + return json; +}; + +reader.elements["uml:DataType"] = function (node) { + var json = reader.elements["uml:Classifier"](node); + json["_type"] = "UMLDataType"; + return json; +}; + +reader.elements["uml:PrimitiveType"] = function (node) { + var json = reader.elements["uml:DataType"](node); + json["_type"] = "UMLPrimitiveType"; + return json; +}; + +reader.elements["uml:EnumerationLiteral"] = function (node) { + var json = reader.elements["uml:InstanceSpecification"](node); + json["_type"] = "UMLEnumerationLiteral"; + return json; +}; + +reader.elements["uml:Enumeration"] = function (node) { + var json = reader.elements["uml:DataType"](node); + json["_type"] = "UMLEnumeration"; + json["literals"] = reader.readElementArray(node, "ownedLiteral"); + return json; +}; + +reader.elements["uml:Generalization"] = function (node) { + var json = reader.elements["uml:DirectedRelationship"](node); + json["_type"] = "UMLGeneralization"; + json["target"] = reader.readRef(node, "general"); + return json; +}; + +reader.elements["uml:Dependency"] = function (node) { + var json = reader.elements["uml:DirectedRelationship"](node); + Object.assign(json, reader.elements["uml:PackageableElement"](node)); + json["_type"] = "UMLDependency"; + json["source"] = reader.readRef(node, "client"); + json["target"] = reader.readRef(node, "supplier"); + return json; +}; + +reader.elements["uml:Abstraction"] = function (node) { + var json = reader.elements["uml:Dependency"](node); + json["_type"] = "UMLAbstraction"; + return json; +}; + +reader.elements["uml:Usage"] = function (node) { + var json = reader.elements["uml:Dependency"](node); + json["_type"] = "UMLDependency"; + json["stereotype"] = "use"; + return json; +}; + +reader.elements["uml:Realization"] = function (node) { + var json = reader.elements["uml:Abstraction"](node); + json["_type"] = "UMLRealization"; + return json; +}; + +reader.elements["uml:InterfaceRealization"] = function (node) { + var json = reader.elements["uml:Realization"](node); + json["_type"] = "UMLInterfaceRealization"; + return json; +}; + +reader.elements["uml:Association"] = function (node) { + var json = reader.elements["uml:Relationship"](node); + Object.assign(json, reader.elements["uml:Classifier"](node)); + json["_type"] = "UMLAssociation"; + var _ends = reader.readElementArray(node, "ownedEnd"); + var _endRefs = reader.readRefArray(node, "memberEnd"); if (_ends && _ends.length >= 2) { - _ends[0]._type = 'UMLAssociationEnd' - _ends[1]._type = 'UMLAssociationEnd' - _ends[0].reference = _ends[0].type - _ends[1].reference = _ends[1].type - var _agg = _ends[0].aggregation - _ends[0].aggregation = _ends[1].aggregation - _ends[1].aggregation = _agg - json['end1'] = _ends[0] - json['end2'] = _ends[1] + _ends[0]._type = "UMLAssociationEnd"; + _ends[1]._type = "UMLAssociationEnd"; + _ends[0].reference = _ends[0].type; + _ends[1].reference = _ends[1].type; + var _agg = _ends[0].aggregation; + _ends[0].aggregation = _ends[1].aggregation; + _ends[1].aggregation = _agg; + json["end1"] = _ends[0]; + json["end2"] = _ends[1]; } else if (_ends && _ends.length === 1) { - _ends[0]._type = 'UMLAssociationEnd' - _ends[0].reference = _ends[0].type - json['end1'] = _ends[0] + _ends[0]._type = "UMLAssociationEnd"; + _ends[0].reference = _ends[0].type; + json["end1"] = _ends[0]; if (_endRefs && _endRefs.length > 0) { - json['end2'] = _endRefs[0] + json["end2"] = _endRefs[0]; } } else { if (_endRefs && _endRefs.length >= 2) { - json['end1'] = _endRefs[0] - json['end2'] = _endRefs[1] + json["end1"] = _endRefs[0]; + json["end2"] = _endRefs[1]; } } - return json -} + return json; +}; -reader.elements['uml:AssociationClass'] = function (node) { +reader.elements["uml:AssociationClass"] = function (node) { // Read for Class - var jsonClass = reader.elements['uml:Class'](node) - jsonClass['_type'] = 'UMLClass' + var jsonClass = reader.elements["uml:Class"](node); + jsonClass["_type"] = "UMLClass"; // Read for Association - var jsonAsso = reader.elements['uml:Association'](node) - jsonAsso['_type'] = 'UMLAssociation' - jsonAsso['_id'] = app.repository.generateGuid() - jsonAsso['_parent'] = { '$ref': jsonClass._id } + var jsonAsso = reader.elements["uml:Association"](node); + jsonAsso["_type"] = "UMLAssociation"; + jsonAsso["_id"] = app.repository.generateGuid(); + jsonAsso["_parent"] = { $ref: jsonClass._id }; if (jsonAsso.end1) { - jsonAsso.end1._parent = { '$ref': jsonAsso._id } + jsonAsso.end1._parent = { $ref: jsonAsso._id }; } if (jsonAsso.end2) { - jsonAsso.end2._parent = { '$ref': jsonAsso._id } + jsonAsso.end2._parent = { $ref: jsonAsso._id }; } - reader.put(jsonAsso) + reader.put(jsonAsso); // Object for AssociationClassLink var jsonLink = { _id: app.repository.generateGuid(), - _type: 'UMLAssociationClassLink', - _parent: { '$ref': jsonClass._id }, - associationSide: { '$ref': jsonAsso._id }, - classSide: { '$ref': jsonClass._id } - } - reader.put(jsonLink) + _type: "UMLAssociationClassLink", + _parent: { $ref: jsonClass._id }, + associationSide: { $ref: jsonAsso._id }, + classSide: { $ref: jsonClass._id }, + }; + reader.put(jsonLink); // Add Asso and Link to Class. - jsonClass.__association = jsonAsso - jsonClass.__link = jsonLink - addTo(jsonClass, 'ownedElements', jsonAsso) - addTo(jsonClass, 'ownedElements', jsonLink) - return jsonClass -} + jsonClass.__association = jsonAsso; + jsonClass.__link = jsonLink; + addTo(jsonClass, "ownedElements", jsonAsso); + addTo(jsonClass, "ownedElements", jsonLink); + return jsonClass; +}; // Composite Structure ..................................................... -reader.elements['uml:ConnectorEnd'] = function (node) { - var json = reader.elements['uml:MultiplicityElement'](node) - json['_type'] = 'UMLConnectorEnd' - json['reference'] = reader.readRef(node, 'role') - return json -} - -reader.elements['uml:Connector'] = function (node) { - var json = reader.elements['uml:Feature'](node) - json['_type'] = 'UMLConnector' - var _ends = reader.readElementArray(node, 'end') +reader.elements["uml:ConnectorEnd"] = function (node) { + var json = reader.elements["uml:MultiplicityElement"](node); + json["_type"] = "UMLConnectorEnd"; + json["reference"] = reader.readRef(node, "role"); + return json; +}; + +reader.elements["uml:Connector"] = function (node) { + var json = reader.elements["uml:Feature"](node); + json["_type"] = "UMLConnector"; + var _ends = reader.readElementArray(node, "end"); if (_ends && _ends.length >= 2) { - json['end1'] = _ends[0] - json['end2'] = _ends[1] + json["end1"] = _ends[0]; + json["end2"] = _ends[1]; } - return json -} - -reader.elements['uml:Port'] = function (node) { - var json = reader.elements['uml:Property'](node) - json['_type'] = 'UMLPort' - json['isBehavior'] = reader.readBoolean(node, 'isBehavior', false) - json['isService'] = reader.readBoolean(node, 'isService', false) - return json -} - -reader.elements['uml:Collaboration'] = function (node) { - var json = reader.elements['uml:BehavioredClassifier'](node) - json['_type'] = 'UMLCollaboration' - return json -} - -reader.elements['uml:CollaborationUse'] = function (node) { - var json = reader.elements['uml:NamedElement'](node) - json['_type'] = 'UMLCollaborationUse' - json['type'] = reader.readRef(node, 'type') - return json -} -reader.elements['collaborationOccurrence'] = reader.elements['uml:CollaborationUse'] // for VP + return json; +}; + +reader.elements["uml:Port"] = function (node) { + var json = reader.elements["uml:Property"](node); + json["_type"] = "UMLPort"; + json["isBehavior"] = reader.readBoolean(node, "isBehavior", false); + json["isService"] = reader.readBoolean(node, "isService", false); + return json; +}; + +reader.elements["uml:Collaboration"] = function (node) { + var json = reader.elements["uml:BehavioredClassifier"](node); + json["_type"] = "UMLCollaboration"; + return json; +}; + +reader.elements["uml:CollaborationUse"] = function (node) { + var json = reader.elements["uml:NamedElement"](node); + json["_type"] = "UMLCollaborationUse"; + json["type"] = reader.readRef(node, "type"); + return json; +}; +reader.elements["collaborationOccurrence"] = + reader.elements["uml:CollaborationUse"]; // for VP // Components .............................................................. -reader.elements['uml:Component'] = function (node) { - var json = reader.elements['uml:Class'](node) - json['_type'] = 'UMLComponent' - json['isIndirectlyInstantiated'] = reader.readBoolean(node, 'isIndirectlyInstantiated', false) - return json -} - -reader.elements['uml:ComponentRealization'] = function (node) { - var json = reader.elements['uml:Realization'](node) - json['_type'] = 'UMLComponentRealization' - return json -} +reader.elements["uml:Component"] = function (node) { + var json = reader.elements["uml:Class"](node); + json["_type"] = "UMLComponent"; + json["isIndirectlyInstantiated"] = reader.readBoolean( + node, + "isIndirectlyInstantiated", + false, + ); + return json; +}; + +reader.elements["uml:ComponentRealization"] = function (node) { + var json = reader.elements["uml:Realization"](node); + json["_type"] = "UMLComponentRealization"; + return json; +}; // Deployments ............................................................. -reader.elements['uml:DeploymentTarget'] = function (node) { - var json = reader.elements['uml:NamedElement'](node) - appendTo(json, 'ownedElements', reader.readElementArray(node, 'deployment')) - return json -} - -reader.elements['uml:DeployedArtifact'] = function (node) { - var json = reader.elements['uml:NamedElement'](node) - return json -} - -reader.elements['uml:Artifact'] = function (node) { - var json = reader.elements['uml:Classifier'](node) - Object.assign(json, reader.elements['uml:DeployedArtifact'](node)) - json['_type'] = 'UMLArtifact' - json['fileName'] = reader.readString(node, 'fileName', '') - return json -} - -reader.elements['uml:Node'] = function (node) { - var json = reader.elements['uml:Class'](node) - Object.assign(json, reader.elements['uml:DeploymentTarget'](node)) - json['_type'] = 'UMLNode' - return json -} - -reader.elements['uml:CommunicationPath'] = function (node) { - var json = reader.elements['uml:Association'](node) - json['_type'] = 'UMLCommunicationPath' - return json -} - -reader.elements['uml:Device'] = function (node) { - var json = reader.elements['uml:Node'](node) - json['_type'] = 'UMLNode' - json['stereotype'] = 'device' - return json -} - -reader.elements['uml:ExecutionEnvironment'] = function (node) { - var json = reader.elements['uml:Node'](node) - json['_type'] = 'UMLNode' - json['stereotype'] = 'executionEnvironment' - return json -} - -reader.elements['uml:Deployment'] = function (node) { - var json = reader.elements['uml:Dependency'](node) - json['_type'] = 'UMLDeployment' - return json -} +reader.elements["uml:DeploymentTarget"] = function (node) { + var json = reader.elements["uml:NamedElement"](node); + appendTo(json, "ownedElements", reader.readElementArray(node, "deployment")); + return json; +}; + +reader.elements["uml:DeployedArtifact"] = function (node) { + var json = reader.elements["uml:NamedElement"](node); + return json; +}; + +reader.elements["uml:Artifact"] = function (node) { + var json = reader.elements["uml:Classifier"](node); + Object.assign(json, reader.elements["uml:DeployedArtifact"](node)); + json["_type"] = "UMLArtifact"; + json["fileName"] = reader.readString(node, "fileName", ""); + return json; +}; + +reader.elements["uml:Node"] = function (node) { + var json = reader.elements["uml:Class"](node); + Object.assign(json, reader.elements["uml:DeploymentTarget"](node)); + json["_type"] = "UMLNode"; + return json; +}; + +reader.elements["uml:CommunicationPath"] = function (node) { + var json = reader.elements["uml:Association"](node); + json["_type"] = "UMLCommunicationPath"; + return json; +}; + +reader.elements["uml:Device"] = function (node) { + var json = reader.elements["uml:Node"](node); + json["_type"] = "UMLNode"; + json["stereotype"] = "device"; + return json; +}; + +reader.elements["uml:ExecutionEnvironment"] = function (node) { + var json = reader.elements["uml:Node"](node); + json["_type"] = "UMLNode"; + json["stereotype"] = "executionEnvironment"; + return json; +}; + +reader.elements["uml:Deployment"] = function (node) { + var json = reader.elements["uml:Dependency"](node); + json["_type"] = "UMLDeployment"; + return json; +}; // Use Case ................................................................ -reader.elements['uml:ExtensionPoint'] = function (node) { - var json = reader.elements['uml:RedefinableElement'](node) - json['_type'] = 'UMLExtensionPoint' - return json -} - -reader.elements['uml:Actor'] = function (node) { - var json = reader.elements['uml:BehavioredClassifier'](node) - json['_type'] = 'UMLActor' - return json -} - -reader.elements['uml:UseCase'] = function (node) { - var json = reader.elements['uml:BehavioredClassifier'](node) - json['_type'] = 'UMLUseCase' - json['extensionPoints'] = reader.readElementArray(node, 'extensionPoint') - var _includes = reader.readElementArray(node, 'include') +reader.elements["uml:ExtensionPoint"] = function (node) { + var json = reader.elements["uml:RedefinableElement"](node); + json["_type"] = "UMLExtensionPoint"; + return json; +}; + +reader.elements["uml:Actor"] = function (node) { + var json = reader.elements["uml:BehavioredClassifier"](node); + json["_type"] = "UMLActor"; + return json; +}; + +reader.elements["uml:UseCase"] = function (node) { + var json = reader.elements["uml:BehavioredClassifier"](node); + json["_type"] = "UMLUseCase"; + json["extensionPoints"] = reader.readElementArray(node, "extensionPoint"); + var _includes = reader.readElementArray(node, "include"); _includes.forEach(function (g) { - g['source'] = { '$ref': json._id } - addTo(json, 'ownedElements', g) - }) - var _extends = reader.readElementArray(node, 'extend') + g["source"] = { $ref: json._id }; + addTo(json, "ownedElements", g); + }); + var _extends = reader.readElementArray(node, "extend"); _extends.forEach(function (g) { - g['source'] = { '$ref': json._id } - addTo(json, 'ownedElements', g) - }) - return json -} - -reader.elements['uml:Extend'] = function (node) { - var json = reader.elements['uml:DirectedRelationship'](node) - Object.assign(json, reader.elements['uml:NamedElement'](node)) - json['_type'] = 'UMLExtend' - json['target'] = reader.readRef(node, 'extendedCase') - addTo(json, 'extensionLocations', reader.readRef(node, 'extensionLocation')) - return json -} - -reader.elements['uml:Include'] = function (node) { - var json = reader.elements['uml:DirectedRelationship'](node) - Object.assign(json, reader.elements['uml:NamedElement'](node)) - json['_type'] = 'UMLInclude' - json['target'] = reader.readRef(node, 'addition') - return json -} + g["source"] = { $ref: json._id }; + addTo(json, "ownedElements", g); + }); + return json; +}; + +reader.elements["uml:Extend"] = function (node) { + var json = reader.elements["uml:DirectedRelationship"](node); + Object.assign(json, reader.elements["uml:NamedElement"](node)); + json["_type"] = "UMLExtend"; + json["target"] = reader.readRef(node, "extendedCase"); + addTo(json, "extensionLocations", reader.readRef(node, "extensionLocation")); + return json; +}; + +reader.elements["uml:Include"] = function (node) { + var json = reader.elements["uml:DirectedRelationship"](node); + Object.assign(json, reader.elements["uml:NamedElement"](node)); + json["_type"] = "UMLInclude"; + json["target"] = reader.readRef(node, "addition"); + return json; +}; // Profiles ................................................................ -reader.elements['uml:Profile'] = function (node) { - var json = reader.elements['uml:Package'](node) - json['_type'] = 'UMLProfile' - return json -} +reader.elements["uml:Profile"] = function (node) { + var json = reader.elements["uml:Package"](node); + json["_type"] = "UMLProfile"; + return json; +}; -reader.elements['uml:Stereotype'] = function (node) { - var json = reader.elements['uml:Class'](node) - json['_type'] = 'UMLStereotype' - return json -} +reader.elements["uml:Stereotype"] = function (node) { + var json = reader.elements["uml:Class"](node); + json["_type"] = "UMLStereotype"; + return json; +}; // Common Behavior ......................................................... -reader.elements['uml:Event'] = function (node) { - var json = reader.elements['uml:PackageableElement'](node) - json['_type'] = 'UMLEvent' - return json -} - -reader.elements['uml:MessageEvent'] = function (node) { - var json = reader.elements['uml:Event'](node) - return json -} - -reader.elements['uml:TimeEvent'] = function (node) { - var json = reader.elements['uml:Event'](node) - return json -} - -reader.elements['uml:ChangeEvent'] = function (node) { - var json = reader.elements['uml:Event'](node) - return json -} - -reader.elements['uml:Action'] = function (node) { - var json = reader.elements['uml:NamedElement'](node) - json['_type'] = 'UMLAction' - return json -} - -reader.elements['uml:InvocationAction'] = function (node) { - var json = reader.elements['uml:Action'](node) - return json -} - -reader.elements['uml:CallAction'] = function (node) { - var json = reader.elements['uml:InvocationAction'](node) - return json -} - -reader.elements['uml:CallBehaviorAction'] = function (node) { - var json = reader.elements['uml:CallAction'](node) - json['_type'] = 'UMLCallBehaviorAction' - json['behavior'] = reader.readRef(node, 'behavior') - return json -} - -reader.elements['uml:CallOperationAction'] = function (node) { - var json = reader.elements['uml:CallAction'](node) - json['_type'] = 'UMLCallOperationAction' - json['operation'] = reader.readRef(node, 'operation') - return json -} - -reader.elements['uml:SendSignalAction'] = function (node) { - var json = reader.elements['uml:InvocationAction'](node) - json['_type'] = 'UMLSendSignalAction' - json['signal'] = reader.readRef(node, 'signal') - return json -} - -reader.elements['uml:MessageEnd'] = function (node) { - var json = reader.elements['uml:NamedElement'](node) - return json -} +reader.elements["uml:Event"] = function (node) { + var json = reader.elements["uml:PackageableElement"](node); + json["_type"] = "UMLEvent"; + return json; +}; + +reader.elements["uml:MessageEvent"] = function (node) { + var json = reader.elements["uml:Event"](node); + return json; +}; + +reader.elements["uml:TimeEvent"] = function (node) { + var json = reader.elements["uml:Event"](node); + return json; +}; + +reader.elements["uml:ChangeEvent"] = function (node) { + var json = reader.elements["uml:Event"](node); + return json; +}; + +reader.elements["uml:Action"] = function (node) { + var json = reader.elements["uml:NamedElement"](node); + json["_type"] = "UMLAction"; + return json; +}; + +reader.elements["uml:InvocationAction"] = function (node) { + var json = reader.elements["uml:Action"](node); + return json; +}; + +reader.elements["uml:CallAction"] = function (node) { + var json = reader.elements["uml:InvocationAction"](node); + return json; +}; + +reader.elements["uml:CallBehaviorAction"] = function (node) { + var json = reader.elements["uml:CallAction"](node); + json["_type"] = "UMLCallBehaviorAction"; + json["behavior"] = reader.readRef(node, "behavior"); + return json; +}; + +reader.elements["uml:CallOperationAction"] = function (node) { + var json = reader.elements["uml:CallAction"](node); + json["_type"] = "UMLCallOperationAction"; + json["operation"] = reader.readRef(node, "operation"); + return json; +}; + +reader.elements["uml:SendSignalAction"] = function (node) { + var json = reader.elements["uml:InvocationAction"](node); + json["_type"] = "UMLSendSignalAction"; + json["signal"] = reader.readRef(node, "signal"); + return json; +}; + +reader.elements["uml:MessageEnd"] = function (node) { + var json = reader.elements["uml:NamedElement"](node); + return json; +}; // Interactions ............................................................ -reader.elements['uml:Behavior'] = function (node) { - var json = reader.elements['uml:Class'](node) - json['isReentrant'] = reader.readBoolean(node, 'isReentrant', false) - return json -} - -reader.elements['uml:InteractionFragment'] = function (node) { - var json = reader.elements['uml:NamedElement'](node) - json['_formalGates'] = reader.readElementArray(node, 'formalGate') - return json -} - -reader.elements['uml:Interaction'] = function (node) { - var json = reader.elements['uml:InteractionFragment'](node) - Object.assign(json, reader.elements['uml:Behavior'](node)) - json['_type'] = 'UMLInteraction' - appendTo(json, 'participants', reader.readElementArray(node, 'lifeline')) - appendTo(json, 'participants', reader.readElementArray(node, 'formalGate')) - json['fragments'] = reader.readElementArray(node, 'fragment') - json['messages'] = reader.readElementArray(node, 'message') - return json -} - -reader.elements['uml:StateInvariant'] = function (node) { - var json = reader.elements['uml:InteractionFragment'](node) - json['_type'] = 'UMLStateInvariant' - return json -} - -reader.elements['uml:OccurrenceSpecification'] = function (node) { - var json = reader.elements['uml:InteractionFragment'](node) - json['_type'] = 'OccurrenceSpecification' - json['covered'] = reader.readRef(node, 'covered') - return json -} - -reader.elements['uml:ExecutionSpecification'] = function (node) { - var json = reader.elements['uml:InteractionFragment'](node) - json['_type'] = 'ExecutionSpecification' - return json -} +reader.elements["uml:Behavior"] = function (node) { + var json = reader.elements["uml:Class"](node); + json["isReentrant"] = reader.readBoolean(node, "isReentrant", false); + return json; +}; + +reader.elements["uml:InteractionFragment"] = function (node) { + var json = reader.elements["uml:NamedElement"](node); + json["_formalGates"] = reader.readElementArray(node, "formalGate"); + return json; +}; + +reader.elements["uml:Interaction"] = function (node) { + var json = reader.elements["uml:InteractionFragment"](node); + Object.assign(json, reader.elements["uml:Behavior"](node)); + json["_type"] = "UMLInteraction"; + appendTo(json, "participants", reader.readElementArray(node, "lifeline")); + appendTo(json, "participants", reader.readElementArray(node, "formalGate")); + json["fragments"] = reader.readElementArray(node, "fragment"); + json["messages"] = reader.readElementArray(node, "message"); + return json; +}; + +reader.elements["uml:StateInvariant"] = function (node) { + var json = reader.elements["uml:InteractionFragment"](node); + json["_type"] = "UMLStateInvariant"; + return json; +}; + +reader.elements["uml:OccurrenceSpecification"] = function (node) { + var json = reader.elements["uml:InteractionFragment"](node); + json["_type"] = "OccurrenceSpecification"; + json["covered"] = reader.readRef(node, "covered"); + return json; +}; + +reader.elements["uml:ExecutionSpecification"] = function (node) { + var json = reader.elements["uml:InteractionFragment"](node); + json["_type"] = "ExecutionSpecification"; + return json; +}; // NOTE: EventOccurrence is only for VP (not in UML Spec) -reader.elements['uml:EventOccurrence'] = function (node) { - var json = reader.elements['uml:OccurrenceSpecification'](node) - json['_type'] = 'OccurrenceSpecification' - json['message'] = reader.readRef(node, 'message') - return json -} - -reader.elements['uml:CombinedFragment'] = function (node) { - var json = reader.elements['uml:InteractionFragment'](node) - json['_type'] = 'UMLCombinedFragment' - json['interactionOperator'] = reader.readEnum(node, 'interactionOperator', 'uml:InteractionOperatorKind', type.UMLCombinedFragment.IOK_SEQ) - appendTo(json, 'operands', reader.readElementArray(node, 'ownedMember')) // for VP - appendTo(json, 'operands', reader.readElementArray(node, 'operand')) - return json -} - -reader.elements['uml:InteractionOperand'] = function (node) { - var json = reader.elements['uml:InteractionFragment'](node) - json['_type'] = 'UMLInteractionOperand' - return json -} - -reader.elements['uml:Lifeline'] = function (node) { - var json = reader.elements['uml:NamedElement'](node) - json['_type'] = 'UMLLifeline' - json['represent'] = reader.readRef(node, 'represents') - return json -} - -reader.elements['uml:Message'] = function (node) { - var json = reader.elements['uml:NamedElement'](node) - json['_type'] = 'UMLMessage' - json['receiveEvent'] = reader.readRef(node, 'receiveEvent') - json['sendEvent'] = reader.readRef(node, 'sendEvent') - json['connector'] = reader.readRef(node, 'connector') - json['messageSort'] = reader.readEnum(node, 'messageSort', 'uml:MessageSort', type.UMLMessage.MS_SYNCHCALL) - var _signature = reader.readElement(node, 'signature') - if (_signature && _signature._type === 'UMLCallOperationAction') { - json['signature'] = _signature.operation +reader.elements["uml:EventOccurrence"] = function (node) { + var json = reader.elements["uml:OccurrenceSpecification"](node); + json["_type"] = "OccurrenceSpecification"; + json["message"] = reader.readRef(node, "message"); + return json; +}; + +reader.elements["uml:CombinedFragment"] = function (node) { + var json = reader.elements["uml:InteractionFragment"](node); + json["_type"] = "UMLCombinedFragment"; + json["interactionOperator"] = reader.readEnum( + node, + "interactionOperator", + "uml:InteractionOperatorKind", + type.UMLCombinedFragment.IOK_SEQ, + ); + appendTo(json, "operands", reader.readElementArray(node, "ownedMember")); // for VP + appendTo(json, "operands", reader.readElementArray(node, "operand")); + return json; +}; + +reader.elements["uml:InteractionOperand"] = function (node) { + var json = reader.elements["uml:InteractionFragment"](node); + json["_type"] = "UMLInteractionOperand"; + return json; +}; + +reader.elements["uml:Lifeline"] = function (node) { + var json = reader.elements["uml:NamedElement"](node); + json["_type"] = "UMLLifeline"; + json["represent"] = reader.readRef(node, "represents"); + return json; +}; + +reader.elements["uml:Message"] = function (node) { + var json = reader.elements["uml:NamedElement"](node); + json["_type"] = "UMLMessage"; + json["receiveEvent"] = reader.readRef(node, "receiveEvent"); + json["sendEvent"] = reader.readRef(node, "sendEvent"); + json["connector"] = reader.readRef(node, "connector"); + json["messageSort"] = reader.readEnum( + node, + "messageSort", + "uml:MessageSort", + type.UMLMessage.MS_SYNCHCALL, + ); + var _signature = reader.readElement(node, "signature"); + if (_signature && _signature._type === "UMLCallOperationAction") { + json["signature"] = _signature.operation; } - if (_signature && _signature._type === 'UMLSendSignalAction') { - json['signature'] = _signature.signal + if (_signature && _signature._type === "UMLSendSignalAction") { + json["signature"] = _signature.signal; } - return json -} + return json; +}; -reader.elements['uml:InteractionUse'] = function (node) { - var json = reader.elements['uml:InteractionFragment'](node) - json['_type'] = 'UMLInteractionUse' - json['refersTo'] = reader.readRef(node, 'refersTo') +reader.elements["uml:InteractionUse"] = function (node) { + var json = reader.elements["uml:InteractionFragment"](node); + json["_type"] = "UMLInteractionUse"; + json["refersTo"] = reader.readRef(node, "refersTo"); // TODO: arguments // TODO: returnValue // TODO: returnValueRecipient - return json -} -reader.elements['uml:InteractionOccurrence'] = reader.elements['uml:InteractionUse'] // for VP - -reader.elements['uml:Continuation'] = function (node) { - var json = reader.elements['uml:InteractionFragment'](node) - json['_type'] = 'UMLContinuation' + return json; +}; +reader.elements["uml:InteractionOccurrence"] = + reader.elements["uml:InteractionUse"]; // for VP + +reader.elements["uml:Continuation"] = function (node) { + var json = reader.elements["uml:InteractionFragment"](node); + json["_type"] = "UMLContinuation"; // TODO: covered? - return json -} + return json; +}; -reader.elements['uml:StateInvariant'] = function (node) { - var json = reader.elements['uml:InteractionFragment'](node) - json['_type'] = 'UMLStateInvariant' - json['covered'] = reader.readRef(node, 'covered') +reader.elements["uml:StateInvariant"] = function (node) { + var json = reader.elements["uml:InteractionFragment"](node); + json["_type"] = "UMLStateInvariant"; + json["covered"] = reader.readRef(node, "covered"); // TODO: invariant - return json -} + return json; +}; -reader.elements['uml:Gate'] = function (node) { - var json = reader.elements['uml:MessageEnd'](node) - json['_type'] = 'UMLGate' - return json -} +reader.elements["uml:Gate"] = function (node) { + var json = reader.elements["uml:MessageEnd"](node); + json["_type"] = "UMLGate"; + return json; +}; // State Machines .......................................................... -reader.elements['uml:StateMachine'] = function (node) { - var json = reader.elements['uml:Behavior'](node) - json['_type'] = 'UMLStateMachine' - json['regions'] = reader.readElementArray(node, 'region') - return json -} - -reader.elements['uml:Vertex'] = function (node) { - var json = reader.elements['uml:NamedElement'](node) - return json -} - -reader.elements['uml:Region'] = function (node) { - var json = reader.elements['uml:Namespace'](node) - json['_type'] = 'UMLRegion' - json['vertices'] = reader.readElementArray(node, 'vertex') - appendTo(json, 'vertices', reader.readElementArray(node, 'ownedMember')) - appendTo(json, 'vertices', reader.readElementArray(node, 'subvertex')) // for VP - json['transitions'] = reader.readElementArray(node, 'transition') - return json -} - -reader.elements['uml:Pseudostate'] = function (node) { - var json = reader.elements['uml:Vertex'](node) - json['_type'] = 'UMLPseudostate' - json['kind'] = reader.readEnum(node, 'kind', 'uml:PseudostateKind', type.UMLPseudostate.PSK_INITIAL) - return json -} - -reader.elements['uml:ConnectionPointReference'] = function (node) { - var json = reader.elements['uml:Vertex'](node) - json['_type'] = 'UMLConnectionPointReference' - return json -} - -reader.elements['uml:State'] = function (node) { - var json = reader.elements['uml:Namespace'](node) - Object.assign(json, reader.elements['uml:Vertex'](node)) - json['_type'] = 'UMLState' - json['regions'] = reader.readElementArray(node, 'region') - json['entryActivities'] = reader.readElementArray(node, 'entry') - json['doActivities'] = reader.readElementArray(node, 'doActivity') - json['exitActivities'] = reader.readElementArray(node, 'exit') - return json -} - -reader.elements['uml:FinalState'] = function (node) { - var json = reader.elements['uml:State'](node) - json['_type'] = 'UMLFinalState' - return json -} - -reader.elements['uml:Transition'] = function (node) { - var json = reader.elements['uml:Namespace'](node) - json['_type'] = 'UMLTransition' - json['kind'] = reader.readEnum(node, 'kind', 'uml:TransitionKind', type.UMLTransition.TK_INTERNAL) - json['source'] = reader.readRef(node, 'source') - json['target'] = reader.readRef(node, 'target') - return json -} +reader.elements["uml:StateMachine"] = function (node) { + var json = reader.elements["uml:Behavior"](node); + json["_type"] = "UMLStateMachine"; + json["regions"] = reader.readElementArray(node, "region"); + return json; +}; + +reader.elements["uml:Vertex"] = function (node) { + var json = reader.elements["uml:NamedElement"](node); + return json; +}; + +reader.elements["uml:Region"] = function (node) { + var json = reader.elements["uml:Namespace"](node); + json["_type"] = "UMLRegion"; + json["vertices"] = reader.readElementArray(node, "vertex"); + appendTo(json, "vertices", reader.readElementArray(node, "ownedMember")); + appendTo(json, "vertices", reader.readElementArray(node, "subvertex")); // for VP + json["transitions"] = reader.readElementArray(node, "transition"); + return json; +}; + +reader.elements["uml:Pseudostate"] = function (node) { + var json = reader.elements["uml:Vertex"](node); + json["_type"] = "UMLPseudostate"; + json["kind"] = reader.readEnum( + node, + "kind", + "uml:PseudostateKind", + type.UMLPseudostate.PSK_INITIAL, + ); + return json; +}; + +reader.elements["uml:ConnectionPointReference"] = function (node) { + var json = reader.elements["uml:Vertex"](node); + json["_type"] = "UMLConnectionPointReference"; + return json; +}; + +reader.elements["uml:State"] = function (node) { + var json = reader.elements["uml:Namespace"](node); + Object.assign(json, reader.elements["uml:Vertex"](node)); + json["_type"] = "UMLState"; + json["regions"] = reader.readElementArray(node, "region"); + json["entryActivities"] = reader.readElementArray(node, "entry"); + json["doActivities"] = reader.readElementArray(node, "doActivity"); + json["exitActivities"] = reader.readElementArray(node, "exit"); + return json; +}; + +reader.elements["uml:FinalState"] = function (node) { + var json = reader.elements["uml:State"](node); + json["_type"] = "UMLFinalState"; + return json; +}; + +reader.elements["uml:Transition"] = function (node) { + var json = reader.elements["uml:Namespace"](node); + json["_type"] = "UMLTransition"; + json["kind"] = reader.readEnum( + node, + "kind", + "uml:TransitionKind", + type.UMLTransition.TK_INTERNAL, + ); + json["source"] = reader.readRef(node, "source"); + json["target"] = reader.readRef(node, "target"); + return json; +}; // Activities .............................................................. -reader.elements['uml:Activity'] = function (node) { - var json = reader.elements['uml:Behavior'](node) - json['_type'] = 'UMLActivity' - json['nodes'] = reader.readElementArray(node, 'node') - json['edges'] = reader.readElementArray(node, 'edge') - json['groups'] = reader.readElementArray(node, 'group') - return json -} - -reader.elements['uml:Pin'] = function (node) { - var json = reader.elements['uml:TypedElement'](node) - Object.assign(json, reader.elements['uml:MultiplicityElement'](node)) - return json -} - -reader.elements['uml:InputPin'] = function (node) { - var json = reader.elements['uml:Pin'](node) - json['_type'] = 'UMLInputPin' - return json -} - -reader.elements['uml:OutputPin'] = function (node) { - var json = reader.elements['uml:Pin'](node) - json['_type'] = 'UMLOutputPin' - return json -} - -reader.elements['uml:ValuePin'] = function (node) { - var json = reader.elements['uml:InputPin'](node) - json['_type'] = 'UMLInputPin' - return json -} - -reader.elements['uml:ActivityNode'] = function (node) { - var json = reader.elements['uml:NamedElement'](node) - return json -} - -reader.elements['uml:Action'] = function (node) { - var json = reader.elements['uml:ActivityNode'](node) - json['_type'] = 'UMLAction' - json['inputs'] = reader.readElementArray(node, 'argument') - appendTo(json, 'inputs', reader.readElementArray(node, 'input')) - json['outputs'] = reader.readElementArray(node, 'result') - appendTo(json, 'outputs', reader.readElementArray(node, 'output')) - return json -} - -reader.elements['uml:OpaqueAction'] = function (node) { - var json = reader.elements['uml:Action'](node) - json['_type'] = 'UMLAction' - json['kind'] = type.UMLAction.ACK_OPAQUE - return json -} - -reader.elements['uml:InvocationAction'] = function (node) { - var json = reader.elements['uml:Action'](node) - return json -} - -reader.elements['uml:CallAction'] = function (node) { - var json = reader.elements['uml:InvocationAction'](node) - json['isSynchronous'] = reader.readBoolean(node, 'isSynchronous', false) - return json -} - -reader.elements['uml:CallBehaviorAction'] = function (node) { - var json = reader.elements['uml:CallAction'](node) - json['_type'] = 'UMLAction' - json['target'] = reader.readRef(node, 'behavior') - return json -} - -reader.elements['uml:CallOperationAction'] = function (node) { - var json = reader.elements['uml:CallAction'](node) - json['_type'] = 'UMLAction' - json['target'] = reader.readRef(node, 'operation') - return json -} - -reader.elements['uml:SendSignalAction'] = function (node) { - var json = reader.elements['uml:InvocationAction'](node) - json['_type'] = 'UMLAction' - json['kind'] = type.UMLAction.ACK_SENDSIGNAL - json['target'] = reader.readRef(node, 'signal') - return json -} - -reader.elements['uml:BroadcastSignalAction'] = function (node) { - var json = reader.elements['uml:InvocationAction'](node) - json['_type'] = 'UMLAction' - return json -} - -reader.elements['uml:SendObjectAction'] = function (node) { - var json = reader.elements['uml:InvocationAction'](node) - json['_type'] = 'UMLAction' - return json -} - -reader.elements['uml:CreateObjectAction'] = function (node) { - var json = reader.elements['uml:Action'](node) - json['_type'] = 'UMLAction' - json['kind'] = type.UMLAction.ACK_CREATE - return json -} - -reader.elements['uml:DestroyObjectAction'] = function (node) { - var json = reader.elements['uml:Action'](node) - json['_type'] = 'UMLAction' - json['kind'] = type.UMLAction.ACK_DESTROY - return json -} - -reader.elements['uml:StructuralFeatureAction'] = function (node) { - var json = reader.elements['uml:Action'](node) - json['_type'] = 'UMLAction' - return json -} - -reader.elements['uml:ReadStructuralFeatureAction'] = function (node) { - var json = reader.elements['uml:StructuralFeatureAction'](node) - json['_type'] = 'UMLAction' - json['kind'] = type.UMLAction.ACK_READ - return json -} - -reader.elements['uml:WriteStructuralFeatureAction'] = function (node) { - var json = reader.elements['uml:StructuralFeatureAction'](node) - json['_type'] = 'UMLAction' - json['kind'] = type.UMLAction.ACK_WRITE - return json -} - -reader.elements['uml:ClearStructuralFeatureAction'] = function (node) { - var json = reader.elements['uml:StructuralFeatureAction'](node) - json['_type'] = 'UMLAction' - return json -} - -reader.elements['uml:AddStructuralFeatureAction'] = function (node) { - var json = reader.elements['uml:WriteStructuralFeatureAction'](node) - json['_type'] = 'UMLAction' - return json -} - -reader.elements['uml:RemoveStructuralFeatureAction'] = function (node) { - var json = reader.elements['uml:WriteStructuralFeatureAction'](node) - json['_type'] = 'UMLAction' - return json -} - -reader.elements['uml:AcceptEventAction'] = function (node) { - var json = reader.elements['uml:Action'](node) - json['_type'] = 'UMLAction' - json['kind'] = type.UMLAction.ACK_ACCEPTEVENT - return json -} - -reader.elements['uml:ActivityGroup'] = function (node) { - var json = reader.elements['uml:NamedElement'](node) - return json -} - -reader.elements['uml:ActivityPartition'] = function (node) { - var json = reader.elements['uml:ActivityGroup'](node) - json['_type'] = 'UMLActivityPartition' - return json -} - -reader.elements['uml:ObjectNode'] = function (node) { - var json = reader.elements['uml:ActivityNode'](node) - json['_type'] = 'UMLObjectNode' - return json -} - -reader.elements['uml:ControlNode'] = function (node) { - var json = reader.elements['uml:ActivityNode'](node) - json['_type'] = 'UMLControlNode' - return json -} - -reader.elements['uml:FinalNode'] = function (node) { - var json = reader.elements['uml:ControlNode'](node) - return json -} - -reader.elements['uml:ActivityFinalNode'] = function (node) { - var json = reader.elements['uml:FinalNode'](node) - json['_type'] = 'UMLActivityFinalNode' - return json -} - -reader.elements['uml:FlowFinalNode'] = function (node) { - var json = reader.elements['uml:FinalNode'](node) - json['_type'] = 'UMLFlowFinalNode' - return json -} - -reader.elements['uml:InitialNode'] = function (node) { - var json = reader.elements['uml:ControlNode'](node) - json['_type'] = 'UMLInitialNode' - return json -} - -reader.elements['uml:ForkNode'] = function (node) { - var json = reader.elements['uml:ControlNode'](node) - json['_type'] = 'UMLForkNode' - return json -} - -reader.elements['uml:JoinNode'] = function (node) { - var json = reader.elements['uml:ControlNode'](node) - json['_type'] = 'UMLJoinNode' - return json -} - -reader.elements['uml:MergeNode'] = function (node) { - var json = reader.elements['uml:ControlNode'](node) - json['_type'] = 'UMLMergeNode' - return json -} - -reader.elements['uml:DecisionNode'] = function (node) { - var json = reader.elements['uml:ControlNode'](node) - json['_type'] = 'UMLDecisionNode' - return json -} - -reader.elements['uml:ActivityEdge'] = function (node) { - var json = reader.elements['uml:RedefinableElement'](node) - json['source'] = reader.readRef(node, 'source') - json['target'] = reader.readRef(node, 'target') - return json -} - -reader.elements['uml:ControlFlow'] = function (node) { - var json = reader.elements['uml:ActivityEdge'](node) - json['_type'] = 'UMLControlFlow' - return json -} - -reader.elements['uml:ObjectFlow'] = function (node) { - var json = reader.elements['uml:ActivityEdge'](node) - json['_type'] = 'UMLObjectFlow' - return json -} +reader.elements["uml:Activity"] = function (node) { + var json = reader.elements["uml:Behavior"](node); + json["_type"] = "UMLActivity"; + json["nodes"] = reader.readElementArray(node, "node"); + json["edges"] = reader.readElementArray(node, "edge"); + json["groups"] = reader.readElementArray(node, "group"); + return json; +}; + +reader.elements["uml:Pin"] = function (node) { + var json = reader.elements["uml:TypedElement"](node); + Object.assign(json, reader.elements["uml:MultiplicityElement"](node)); + return json; +}; + +reader.elements["uml:InputPin"] = function (node) { + var json = reader.elements["uml:Pin"](node); + json["_type"] = "UMLInputPin"; + return json; +}; + +reader.elements["uml:OutputPin"] = function (node) { + var json = reader.elements["uml:Pin"](node); + json["_type"] = "UMLOutputPin"; + return json; +}; + +reader.elements["uml:ValuePin"] = function (node) { + var json = reader.elements["uml:InputPin"](node); + json["_type"] = "UMLInputPin"; + return json; +}; + +reader.elements["uml:ActivityNode"] = function (node) { + var json = reader.elements["uml:NamedElement"](node); + return json; +}; + +reader.elements["uml:Action"] = function (node) { + var json = reader.elements["uml:ActivityNode"](node); + json["_type"] = "UMLAction"; + json["inputs"] = reader.readElementArray(node, "argument"); + appendTo(json, "inputs", reader.readElementArray(node, "input")); + json["outputs"] = reader.readElementArray(node, "result"); + appendTo(json, "outputs", reader.readElementArray(node, "output")); + return json; +}; + +reader.elements["uml:OpaqueAction"] = function (node) { + var json = reader.elements["uml:Action"](node); + json["_type"] = "UMLAction"; + json["kind"] = type.UMLAction.ACK_OPAQUE; + return json; +}; + +reader.elements["uml:InvocationAction"] = function (node) { + var json = reader.elements["uml:Action"](node); + return json; +}; + +reader.elements["uml:CallAction"] = function (node) { + var json = reader.elements["uml:InvocationAction"](node); + json["isSynchronous"] = reader.readBoolean(node, "isSynchronous", false); + return json; +}; + +reader.elements["uml:CallBehaviorAction"] = function (node) { + var json = reader.elements["uml:CallAction"](node); + json["_type"] = "UMLAction"; + json["target"] = reader.readRef(node, "behavior"); + return json; +}; + +reader.elements["uml:CallOperationAction"] = function (node) { + var json = reader.elements["uml:CallAction"](node); + json["_type"] = "UMLAction"; + json["target"] = reader.readRef(node, "operation"); + return json; +}; + +reader.elements["uml:SendSignalAction"] = function (node) { + var json = reader.elements["uml:InvocationAction"](node); + json["_type"] = "UMLAction"; + json["kind"] = type.UMLAction.ACK_SENDSIGNAL; + json["target"] = reader.readRef(node, "signal"); + return json; +}; + +reader.elements["uml:BroadcastSignalAction"] = function (node) { + var json = reader.elements["uml:InvocationAction"](node); + json["_type"] = "UMLAction"; + return json; +}; + +reader.elements["uml:SendObjectAction"] = function (node) { + var json = reader.elements["uml:InvocationAction"](node); + json["_type"] = "UMLAction"; + return json; +}; + +reader.elements["uml:CreateObjectAction"] = function (node) { + var json = reader.elements["uml:Action"](node); + json["_type"] = "UMLAction"; + json["kind"] = type.UMLAction.ACK_CREATE; + return json; +}; + +reader.elements["uml:DestroyObjectAction"] = function (node) { + var json = reader.elements["uml:Action"](node); + json["_type"] = "UMLAction"; + json["kind"] = type.UMLAction.ACK_DESTROY; + return json; +}; + +reader.elements["uml:StructuralFeatureAction"] = function (node) { + var json = reader.elements["uml:Action"](node); + json["_type"] = "UMLAction"; + return json; +}; + +reader.elements["uml:ReadStructuralFeatureAction"] = function (node) { + var json = reader.elements["uml:StructuralFeatureAction"](node); + json["_type"] = "UMLAction"; + json["kind"] = type.UMLAction.ACK_READ; + return json; +}; + +reader.elements["uml:WriteStructuralFeatureAction"] = function (node) { + var json = reader.elements["uml:StructuralFeatureAction"](node); + json["_type"] = "UMLAction"; + json["kind"] = type.UMLAction.ACK_WRITE; + return json; +}; + +reader.elements["uml:ClearStructuralFeatureAction"] = function (node) { + var json = reader.elements["uml:StructuralFeatureAction"](node); + json["_type"] = "UMLAction"; + return json; +}; + +reader.elements["uml:AddStructuralFeatureAction"] = function (node) { + var json = reader.elements["uml:WriteStructuralFeatureAction"](node); + json["_type"] = "UMLAction"; + return json; +}; + +reader.elements["uml:RemoveStructuralFeatureAction"] = function (node) { + var json = reader.elements["uml:WriteStructuralFeatureAction"](node); + json["_type"] = "UMLAction"; + return json; +}; + +reader.elements["uml:AcceptEventAction"] = function (node) { + var json = reader.elements["uml:Action"](node); + json["_type"] = "UMLAction"; + json["kind"] = type.UMLAction.ACK_ACCEPTEVENT; + return json; +}; + +reader.elements["uml:ActivityGroup"] = function (node) { + var json = reader.elements["uml:NamedElement"](node); + return json; +}; + +reader.elements["uml:ActivityPartition"] = function (node) { + var json = reader.elements["uml:ActivityGroup"](node); + json["_type"] = "UMLActivityPartition"; + return json; +}; + +reader.elements["uml:ObjectNode"] = function (node) { + var json = reader.elements["uml:ActivityNode"](node); + json["_type"] = "UMLObjectNode"; + return json; +}; + +reader.elements["uml:ControlNode"] = function (node) { + var json = reader.elements["uml:ActivityNode"](node); + json["_type"] = "UMLControlNode"; + return json; +}; + +reader.elements["uml:FinalNode"] = function (node) { + var json = reader.elements["uml:ControlNode"](node); + return json; +}; + +reader.elements["uml:ActivityFinalNode"] = function (node) { + var json = reader.elements["uml:FinalNode"](node); + json["_type"] = "UMLActivityFinalNode"; + return json; +}; + +reader.elements["uml:FlowFinalNode"] = function (node) { + var json = reader.elements["uml:FinalNode"](node); + json["_type"] = "UMLFlowFinalNode"; + return json; +}; + +reader.elements["uml:InitialNode"] = function (node) { + var json = reader.elements["uml:ControlNode"](node); + json["_type"] = "UMLInitialNode"; + return json; +}; + +reader.elements["uml:ForkNode"] = function (node) { + var json = reader.elements["uml:ControlNode"](node); + json["_type"] = "UMLForkNode"; + return json; +}; + +reader.elements["uml:JoinNode"] = function (node) { + var json = reader.elements["uml:ControlNode"](node); + json["_type"] = "UMLJoinNode"; + return json; +}; + +reader.elements["uml:MergeNode"] = function (node) { + var json = reader.elements["uml:ControlNode"](node); + json["_type"] = "UMLMergeNode"; + return json; +}; + +reader.elements["uml:DecisionNode"] = function (node) { + var json = reader.elements["uml:ControlNode"](node); + json["_type"] = "UMLDecisionNode"; + return json; +}; + +reader.elements["uml:ActivityEdge"] = function (node) { + var json = reader.elements["uml:RedefinableElement"](node); + json["source"] = reader.readRef(node, "source"); + json["target"] = reader.readRef(node, "target"); + return json; +}; + +reader.elements["uml:ControlFlow"] = function (node) { + var json = reader.elements["uml:ActivityEdge"](node); + json["_type"] = "UMLControlFlow"; + return json; +}; + +reader.elements["uml:ObjectFlow"] = function (node) { + var json = reader.elements["uml:ActivityEdge"](node); + json["_type"] = "UMLObjectFlow"; + return json; +}; // Post-processors ......................................................... // process ComponentRealization reader.postprocessors.push(function (elem) { - if (elem._type === 'UMLRealization') { + if (elem._type === "UMLRealization") { // var source = reader.get(elem.source.$ref) - var target = reader.get(elem.target.$ref) - if (app.metamodels.isKindOf(target._type, 'UMLComponent')) { - elem._type = 'UMLComponentRealization' + var target = reader.get(elem.target.$ref); + if (app.metamodels.isKindOf(target._type, "UMLComponent")) { + elem._type = "UMLComponentRealization"; } - if (app.metamodels.isKindOf(target._type, 'UMLInterface')) { - elem._type = 'UMLInterfaceRealization' + if (app.metamodels.isKindOf(target._type, "UMLInterface")) { + elem._type = "UMLInterfaceRealization"; } } -}) +}); // process 'memberEnd' of Association reader.postprocessors.push(function (elem) { - if (app.metamodels.isKindOf(elem._type, 'UMLAssociation')) { + if (app.metamodels.isKindOf(elem._type, "UMLAssociation")) { if (elem.end1 && elem.end1.$ref) { - elem.end1 = reader.get(elem.end1.$ref) - var parent1 = reader.get(elem.end1._parent.$ref) - parent1.attributes = parent1.attributes.filter(e => e !== elem.end1) - elem.end1._type = 'UMLAssociationEnd' - elem.end1._parent = { '$ref': elem._id } - elem.end1.navigable = false - elem.end1.reference = elem.end1.type + elem.end1 = reader.get(elem.end1.$ref); + var parent1 = reader.get(elem.end1._parent.$ref); + parent1.attributes = parent1.attributes.filter((e) => e !== elem.end1); + elem.end1._type = "UMLAssociationEnd"; + elem.end1._parent = { $ref: elem._id }; + elem.end1.navigable = false; + elem.end1.reference = elem.end1.type; } if (elem.end2 && elem.end2.$ref) { - elem.end2 = reader.get(elem.end2.$ref) - var parent2 = reader.get(elem.end2._parent.$ref) - parent2.attributes = parent2.attributes.filter(e => e !== elem.end2) - elem.end2._type = 'UMLAssociationEnd' - elem.end2._parent = { '$ref': elem._id } - elem.end2.navigable = false - elem.end2.reference = elem.end2.type + elem.end2 = reader.get(elem.end2.$ref); + var parent2 = reader.get(elem.end2._parent.$ref); + parent2.attributes = parent2.attributes.filter((e) => e !== elem.end2); + elem.end2._type = "UMLAssociationEnd"; + elem.end2._parent = { $ref: elem._id }; + elem.end2.navigable = false; + elem.end2.reference = elem.end2.type; } } -}) +}); // process RoleBindings of CollaborationUse // TODO: RoleBindings are not properly loaded of Visual Paradigm XMI reader.postprocessors.push(function (elem) { - if (elem._type === 'UMLDependency') { - var e1, e2 + if (elem._type === "UMLDependency") { + var e1, e2; if (elem.source.$ref) { - e1 = reader.get(elem.source.$ref) + e1 = reader.get(elem.source.$ref); } if (elem.target.$ref) { - e2 = reader.get(elem.target.$ref) + e2 = reader.get(elem.target.$ref); } if (e1 && e2) { - if ((app.metamodels.isKindOf(e1._type, 'UMLCollaborationUse') && - (app.metamodels.isKindOf(e2._type, 'UMLAttribute'))) || - (app.metamodels.isKindOf(e1._type, 'UMLCollaborationUse') && - (app.metamodels.isKindOf(e2._type, 'UMLAttribute')))) { - elem._type = 'UMLRoleBinding' + if ( + (app.metamodels.isKindOf(e1._type, "UMLCollaborationUse") && + app.metamodels.isKindOf(e2._type, "UMLAttribute")) || + (app.metamodels.isKindOf(e1._type, "UMLCollaborationUse") && + app.metamodels.isKindOf(e2._type, "UMLAttribute")) + ) { + elem._type = "UMLRoleBinding"; } } } -}) +}); // process Deployment reader.postprocessors.push(function (elem) { - if (elem._type === 'UMLDeployment') { - var _temp = elem.source - elem.source = elem.target - elem.target = _temp + if (elem._type === "UMLDeployment") { + var _temp = elem.source; + elem.source = elem.target; + elem.target = _temp; } -}) +}); // process InstanceSpecification reader.postprocessors.push(function (elem) { - if (elem._type === 'UMLObject' && elem.classifier) { - var _classifier = reader.get(elem.classifier.$ref) - if (_classifier._type === 'UMLNode') { - elem._type = 'UMLNodeInstance' - } else if (_classifier._type === 'UMLComponent') { - elem._type = 'UMLComponentInstance' - } else if (_classifier._type === 'UMLArtifact') { - elem._type = 'UMLArtifactInstance' + if (elem._type === "UMLObject" && elem.classifier) { + var _classifier = reader.get(elem.classifier.$ref); + if (_classifier._type === "UMLNode") { + elem._type = "UMLNodeInstance"; + } else if (_classifier._type === "UMLComponent") { + elem._type = "UMLComponentInstance"; + } else if (_classifier._type === "UMLArtifact") { + elem._type = "UMLArtifactInstance"; } } -}) +}); // process Slot reader.postprocessors.push(function (elem) { - if (elem._type === 'UMLSlot') { + if (elem._type === "UMLSlot") { if ((!elem.name || elem.name.trim().length === 0) && elem.definingFeature) { - var _feature = reader.get(elem.definingFeature.$ref) - elem.name = _feature.name + var _feature = reader.get(elem.definingFeature.$ref); + elem.name = _feature.name; } } -}) +}); // process Extend reader.postprocessors.push(function (elem) { - if (elem._type === 'UMLExtend' && elem.__extensionLocation) { - var loc = reader.get(elem.__extensionLocation.$ref) - elem.location = loc.name + if (elem._type === "UMLExtend" && elem.__extensionLocation) { + var loc = reader.get(elem.__extensionLocation.$ref); + elem.location = loc.name; } -}) +}); // process Interaction reader.postprocessors.push(function (elem) { - if (elem._type === 'UMLInteraction') { - var parent = reader.get(elem._parent.$ref) - if (parent && app.metamodels.isKindOf(parent._type, 'UMLClassifier')) { + if (elem._type === "UMLInteraction") { + var parent = reader.get(elem._parent.$ref); + if (parent && app.metamodels.isKindOf(parent._type, "UMLClassifier")) { elem.attributes.forEach(function (e) { - addTo(parent, 'attributes', e) - e._parent = { '$ref': parent._id } - }) + addTo(parent, "attributes", e); + e._parent = { $ref: parent._id }; + }); elem.operations.forEach(function (e) { - addTo(parent, 'operations', e) - e._parent = { '$ref': parent._id } - }) + addTo(parent, "operations", e); + e._parent = { $ref: parent._id }; + }); } else if (parent && parent.ownedElements) { - parent.ownedElements = parent.ownedElements.filter(e => e !== elem) + parent.ownedElements = parent.ownedElements.filter((e) => e !== elem); var collaboration = { _id: app.repository.generateGuid(), - _parent: { '$ref': parent._id }, - _type: 'UMLCollaboration', - ownedElements: [ elem ], + _parent: { $ref: parent._id }, + _type: "UMLCollaboration", + ownedElements: [elem], attributes: [], - operations: [] - } + operations: [], + }; elem.attributes.forEach(function (e) { - addTo(collaboration, 'attributes', e) - e._parent = { '$ref': collaboration._id } - }) + addTo(collaboration, "attributes", e); + e._parent = { $ref: collaboration._id }; + }); elem.operations.forEach(function (e) { - addTo(collaboration, 'operations', e) - e._parent = { '$ref': collaboration._id } - }) - parent.ownedElements.push(collaboration) - elem._parent = { '$ref': collaboration._id } + addTo(collaboration, "operations", e); + e._parent = { $ref: collaboration._id }; + }); + parent.ownedElements.push(collaboration); + elem._parent = { $ref: collaboration._id }; } elem.messages.forEach(function (msg) { - var _endpoint - if (msg.sendEvent && msg.sendEvent.$ref && reader.get(msg.sendEvent.$ref)) { - var _from = reader.get(msg.sendEvent.$ref) - if (_from._type === 'OccurrenceSpecification') { - msg.source = _from.covered + var _endpoint; + if ( + msg.sendEvent && + msg.sendEvent.$ref && + reader.get(msg.sendEvent.$ref) + ) { + var _from = reader.get(msg.sendEvent.$ref); + if (_from._type === "OccurrenceSpecification") { + msg.source = _from.covered; } else { - msg.source = { '$ref': _from._id } + msg.source = { $ref: _from._id }; } } else { _endpoint = { _id: app.repository.generateGuid(), - _type: 'UMLEndpoint', - _parent: { '$ref': elem._id } - } - elem.participants.push(_endpoint) - msg.source = { '$ref': _endpoint._id } + _type: "UMLEndpoint", + _parent: { $ref: elem._id }, + }; + elem.participants.push(_endpoint); + msg.source = { $ref: _endpoint._id }; } - if (msg.receiveEvent && msg.receiveEvent.$ref && reader.get(msg.receiveEvent.$ref)) { - var _to = reader.get(msg.receiveEvent.$ref) - if (_to._type === 'OccurrenceSpecification') { - msg.target = _to.covered + if ( + msg.receiveEvent && + msg.receiveEvent.$ref && + reader.get(msg.receiveEvent.$ref) + ) { + var _to = reader.get(msg.receiveEvent.$ref); + if (_to._type === "OccurrenceSpecification") { + msg.target = _to.covered; } else { - msg.target = { '$ref': _to._id } + msg.target = { $ref: _to._id }; } } else { _endpoint = { _id: app.repository.generateGuid(), - _type: 'UMLEndpoint', - _parent: { '$ref': elem._id } - } - elem.participants.push(_endpoint) - msg.target = { '$ref': _endpoint._id } + _type: "UMLEndpoint", + _parent: { $ref: elem._id }, + }; + elem.participants.push(_endpoint); + msg.target = { $ref: _endpoint._id }; } - }) + }); elem.fragments = elem.fragments.filter(function (f) { - return (f._type !== 'OccurrenceSpecification') - }) + return f._type !== "OccurrenceSpecification"; + }); } -}) +}); // process InteractionFragment's formalGates (for EA) reader.postprocessors.push(function (elem) { - if (elem._type === 'UMLInteractionOperand') { + if (elem._type === "UMLInteractionOperand") { if (Array.isArray(elem._formalGates) && elem._formalGates.length > 0) { - var _cb = reader.get(elem._parent.$ref) - var _int = reader.get(_cb._parent.$ref) - if (_int._type === 'UMLInteraction') { + var _cb = reader.get(elem._parent.$ref); + var _int = reader.get(_cb._parent.$ref); + if (_int._type === "UMLInteraction") { elem._formalGates.forEach(function (e) { - addTo(_int, 'participants', e) - e._parent = { '$ref': _int._id } - }) + addTo(_int, "participants", e); + e._parent = { $ref: _int._id }; + }); } } } -}) +}); // process Vertex (for VP) reader.postprocessors.push(function (elem) { - if (app.metamodels.isKindOf(elem._type, 'UMLVertex') || app.metamodels.isKindOf(elem._type, 'UMLTransition')) { - var parent = reader.get(elem._parent.$ref) - if (parent._type !== 'UMLRegion') { + if ( + app.metamodels.isKindOf(elem._type, "UMLVertex") || + app.metamodels.isKindOf(elem._type, "UMLTransition") + ) { + var parent = reader.get(elem._parent.$ref); + if (parent._type !== "UMLRegion") { if (!parent._stateMachine) { - var stateMachineId = app.repository.generateGuid() + var stateMachineId = app.repository.generateGuid(); parent._stateMachine = { _id: stateMachineId, - _type: 'UMLStateMachine', - _parent: { '$ref': parent._id }, + _type: "UMLStateMachine", + _parent: { $ref: parent._id }, regions: [ { _id: app.repository.generateGuid(), - _type: 'UMLRegion', - _parent: { '$ref': stateMachineId }, + _type: "UMLRegion", + _parent: { $ref: stateMachineId }, vertices: [], - transitions: [] - } - ] - } - parent.ownedElements.push(parent._stateMachine) + transitions: [], + }, + ], + }; + parent.ownedElements.push(parent._stateMachine); } - if (app.metamodels.isKindOf(elem._type, 'UMLVertex')) { - parent._stateMachine.regions[0].vertices.push(elem) - parent.ownedElements = parent.ownedElements.filter(e => e !== elem) - elem._parent = { '$ref': parent._stateMachine.regions[0]._id } - } else if (app.metamodels.isKindOf(elem._type, 'UMLTransition')) { - parent._stateMachine.regions[0].transitions.push(elem) - parent.ownedElements = parent.ownedElements.filter(e => e !== elem) - elem._parent = { '$ref': parent._stateMachine.regions[0]._id } + if (app.metamodels.isKindOf(elem._type, "UMLVertex")) { + parent._stateMachine.regions[0].vertices.push(elem); + parent.ownedElements = parent.ownedElements.filter((e) => e !== elem); + elem._parent = { $ref: parent._stateMachine.regions[0]._id }; + } else if (app.metamodels.isKindOf(elem._type, "UMLTransition")) { + parent._stateMachine.regions[0].transitions.push(elem); + parent.ownedElements = parent.ownedElements.filter((e) => e !== elem); + elem._parent = { $ref: parent._stateMachine.regions[0]._id }; } } } -}) +}); // process Relationships reader.postprocessors.push(function (elem) { - if (app.metamodels.isKindOf(elem._type, 'DirectedRelationship')) { - var parent = elem._parent ? reader.get(elem._parent.$ref) : null - var source = elem.source ? reader.get(elem.source.$ref) : null - var target = elem.target ? reader.get(elem.target.$ref) : null + if (app.metamodels.isKindOf(elem._type, "DirectedRelationship")) { + var parent = elem._parent ? reader.get(elem._parent.$ref) : null; + var source = elem.source ? reader.get(elem.source.$ref) : null; + var target = elem.target ? reader.get(elem.target.$ref) : null; if (!source || !target) { if (parent.ownedElements && parent.ownedElements.includes(elem)) { - parent.ownedElements = parent.ownedElements.filter(e => e !== elem) + parent.ownedElements = parent.ownedElements.filter((e) => e !== elem); } else if (parent.edges && parent.edges.includes(elem)) { - parent.edges = parent.edges.filter(e => e !== elem) + parent.edges = parent.edges.filter((e) => e !== elem); } else if (parent.messages && parent.messages.includes(elem)) { - parent.messages = parent.messages.filter(e => e !== elem) + parent.messages = parent.messages.filter((e) => e !== elem); } } } -}) +}); diff --git a/xmi21-reader.js b/xmi21-reader.js index 7b4be8d..fb48036 100644 --- a/xmi21-reader.js +++ b/xmi21-reader.js @@ -21,13 +21,13 @@ * */ -const fs = require('fs') +const fs = require("fs"); /** * XML Node Types * @enum {number} */ -const ELEMENT_NODE = 1 +const ELEMENT_NODE = 1; // const ATTRIBUTE_NODE = 2 // const TEXT_NODE = 3 // const CDATA_SECTION_NODE = 4 @@ -43,24 +43,24 @@ const ELEMENT_NODE = 1 /** * Map for Enumeration Readers */ -var enumerations = {} +var enumerations = {}; /** * Map for Element Readers */ -var elements = {} +var elements = {}; /** * Object Id Map * @type {Object} */ -var idMap = {} +var idMap = {}; /** * Post-processors * @type {Array.} */ -var postprocessors = [] +var postprocessors = []; /** * Find child node by name @@ -69,15 +69,15 @@ var postprocessors = [] * @param {string} name * @return {null|XMLNode} */ -function _findChildByName (node, name) { - var i, len +function _findChildByName(node, name) { + var i, len; for (i = 0, len = node.childNodes.length; i < len; i++) { - var child = node.childNodes[i] + var child = node.childNodes[i]; if (child.nodeType === ELEMENT_NODE && child.nodeName === name) { - return child + return child; } } - return null + return null; } /** @@ -87,12 +87,12 @@ function _findChildByName (node, name) { * @param {?} defaultValue * @return {number|boolean|string|null} value of the attr */ -function readString (node, name, defaultValue) { - var val = node.getAttribute(name) - if (typeof val !== 'undefined' && val !== null) { - return val +function readString(node, name, defaultValue) { + var val = node.getAttribute(name); + if (typeof val !== "undefined" && val !== null) { + return val; } - return defaultValue + return defaultValue; } /** @@ -102,12 +102,12 @@ function readString (node, name, defaultValue) { * @param {boolean} defaultValue * @return {boolean|null} value of the attr */ -function readBoolean (node, name, defaultValue) { - var val = node.getAttribute(name) - if (typeof val !== 'undefined' && val !== null) { - return (val.toLowerCase() === 'true') +function readBoolean(node, name, defaultValue) { + var val = node.getAttribute(name); + if (typeof val !== "undefined" && val !== null) { + return val.toLowerCase() === "true"; } - return defaultValue + return defaultValue; } /** @@ -117,12 +117,12 @@ function readBoolean (node, name, defaultValue) { * @param {number} defaultValue * @return {number|null} value of the attr */ -function readInteger (node, name, defaultValue) { - var val = node.getAttribute(name) - if (typeof val !== 'undefined' && val !== null) { - return Number(val) +function readInteger(node, name, defaultValue) { + var val = node.getAttribute(name); + if (typeof val !== "undefined" && val !== null) { + return Number(val); } - return defaultValue + return defaultValue; } /** @@ -133,16 +133,16 @@ function readInteger (node, name, defaultValue) { * @param {?} defaultValue * @return {number|boolean|string|null} value of the attr */ -function readEnum (node, name, type, defaultValue) { - var _enum = enumerations[type] +function readEnum(node, name, type, defaultValue) { + var _enum = enumerations[type]; if (_enum) { - var val = readString(node, name) - var literal = _enum[val] - if (typeof literal !== 'undefined') { - return literal + var val = readString(node, name); + var literal = _enum[val]; + if (typeof literal !== "undefined") { + return literal; } } - return defaultValue + return defaultValue; } /** @@ -152,19 +152,19 @@ function readEnum (node, name, type, defaultValue) { * @param {?} defaultValue * @return {null|string} value of the attr */ -function readExpression (node, name, defaultValue) { - var _name = node.nodeName + '.' + name - var _node = _findChildByName(node, _name) +function readExpression(node, name, defaultValue) { + var _name = node.nodeName + "." + name; + var _node = _findChildByName(node, _name); if (_node) { - var exprNode = _findChildByName(_node, 'UML:Expression') + var exprNode = _findChildByName(_node, "UML:Expression"); if (exprNode) { - var val = _node.getAttribute('body') - if (typeof val !== 'undefined' && val !== null) { - return val + var val = _node.getAttribute("body"); + if (typeof val !== "undefined" && val !== null) { + return val; } } } - return defaultValue + return defaultValue; } /** @@ -173,26 +173,30 @@ function readExpression (node, name, defaultValue) { * @param {string} name * @return {Array.} converted array of js objects */ -function readElement (node, name) { - var parentId = readString(node, 'xmi:id') +function readElement(node, name) { + var parentId = readString(node, "xmi:id"); for (var i = 0, len = node.childNodes.length; i < len; i++) { - var child = node.childNodes[i] + var child = node.childNodes[i]; if (child.nodeType === ELEMENT_NODE && child.nodeName === name) { - var _type = child.getAttribute('xmi:type') - var fun = elements[_type] + var _type = child.getAttribute("xmi:type"); + var fun = elements[_type]; if (fun) { - var elem = fun(child) - if (typeof elem !== 'undefined' && elem !== null && typeof elem === 'object') { + var elem = fun(child); + if ( + typeof elem !== "undefined" && + elem !== null && + typeof elem === "object" + ) { if (parentId) { - elem._parent = { '$ref': parentId } + elem._parent = { $ref: parentId }; } - idMap[elem._id] = elem - return elem + idMap[elem._id] = elem; + return elem; } } } } - return null + return null; } /** @@ -202,28 +206,32 @@ function readElement (node, name) { * @param {string} defaultElementType * @return {Array.} converted array of js objects */ -function readElementArray (node, name, defaultElementType) { - var parentId = readString(node, 'xmi:id') - var jsonArray = [] +function readElementArray(node, name, defaultElementType) { + var parentId = readString(node, "xmi:id"); + var jsonArray = []; for (var i = 0, len = node.childNodes.length; i < len; i++) { - var child = node.childNodes[i] + var child = node.childNodes[i]; if (child.nodeType === ELEMENT_NODE && child.nodeName === name) { - var _type = child.getAttribute('xmi:type') || defaultElementType - var fun = elements[_type] + var _type = child.getAttribute("xmi:type") || defaultElementType; + var fun = elements[_type]; if (fun) { - var elem = fun(child) - if (typeof elem !== 'undefined' && elem !== null && typeof elem === 'object') { + var elem = fun(child); + if ( + typeof elem !== "undefined" && + elem !== null && + typeof elem === "object" + ) { if (parentId) { - elem._parent = { '$ref': parentId } + elem._parent = { $ref: parentId }; } - idMap[elem._id] = elem - jsonArray.push(elem) + idMap[elem._id] = elem; + jsonArray.push(elem); } } } } - return jsonArray + return jsonArray; } /** @@ -232,22 +240,22 @@ function readElementArray (node, name, defaultElementType) { * @param {string} name * @return {object} $ref object */ -function readRef (node, name) { - var val = node.getAttribute(name) +function readRef(node, name) { + var val = node.getAttribute(name); if (val) { // Ref as attribute - return { '$ref': val } + return { $ref: val }; } else { // Ref as childNode - val = _findChildByName(node, name) + val = _findChildByName(node, name); if (val) { - var refid = val.getAttribute('xmi:idref') + var refid = val.getAttribute("xmi:idref"); if (refid) { - return { '$ref': refid } + return { $ref: refid }; } } } - return null + return null; } /** @@ -256,32 +264,32 @@ function readRef (node, name) { * @param {string} name * @return {Array.} $ref object */ -function readRefArray (node, name) { - var jsonArray = [] +function readRefArray(node, name) { + var jsonArray = []; for (var i = 0, len = node.childNodes.length; i < len; i++) { - var child = node.childNodes[i] + var child = node.childNodes[i]; if (child.nodeType === ELEMENT_NODE && child.nodeName === name) { - var refid = child.getAttribute('xmi:idref') + var refid = child.getAttribute("xmi:idref"); if (refid) { - jsonArray.push({ '$ref': refid }) + jsonArray.push({ $ref: refid }); } } } - return jsonArray + return jsonArray; } /** * Execute All Post-processors */ -function postprocess () { - var i, len +function postprocess() { + var i, len; for (i = 0, len = postprocessors.length; i < len; i++) { - var key - var processor = postprocessors[i] + var key; + var processor = postprocessors[i]; for (key in idMap) { if (idMap.hasOwnProperty(key)) { - var elem = idMap[key] - processor(elem) + var elem = idMap[key]; + processor(elem); } } } @@ -290,8 +298,8 @@ function postprocess () { /** * Clear loaded objects */ -function clear () { - idMap = {} +function clear() { + idMap = {}; } /** @@ -299,24 +307,24 @@ function clear () { * @param {string} id * @return {Object} */ -function get (id) { - return idMap[id] +function get(id) { + return idMap[id]; } /** * Get idMap * @return {Object} */ -function getIdMap () { - return idMap +function getIdMap() { + return idMap; } /** * Put newly created object which have a new ID * @param {Object} obj */ -function put (obj) { - idMap[obj._id] = obj +function put(obj) { + idMap[obj._id] = obj; } /** @@ -325,59 +333,60 @@ function put (obj) { * @param {string} filename * @return {$.Promise} */ -function loadFromFile (filename) { - var data = fs.readFileSync(filename, 'utf8') +function loadFromFile(filename) { + var data = fs.readFileSync(filename, "utf8"); + // Parse XMI - var parser = new DOMParser() - var dom = parser.parseFromString(data, 'text/xml') - var XMINode = dom.getElementsByTagName('XMI')[0] + var parser = new DOMParser(); + var dom = parser.parseFromString(data, "text/xml"); + var XMINode = dom.childNodes[0]; // dom.getElementsByTagName("XMI")[0]; // Read top-level elements - var topLevelElements = [] + var topLevelElements = []; for (var i = 0, len = XMINode.childNodes.length; i < len; i++) { - var child = XMINode.childNodes[i] - var fun = elements[child.nodeName] + var child = XMINode.childNodes[i]; + var fun = elements[child.nodeName]; if (fun) { - var elem = fun(child) + var elem = fun(child); if (elem) { - topLevelElements.push(elem) + topLevelElements.push(elem); } } } - postprocess() + postprocess(); // Load XMI var XMIData = { _id: app.repository.generateGuid(), - _type: 'UMLModel', - name: 'XMIImported', - ownedElements: topLevelElements - } - topLevelElements.forEach(e => { - e._parent = { '$ref': XMIData._id } - }) + _type: "UMLModel", + name: "XMIImported", + ownedElements: topLevelElements, + }; + topLevelElements.forEach((e) => { + e._parent = { $ref: XMIData._id }; + }); - app.project.importFromJson(app.project.getProject(), XMIData) - app.modelExplorer.expand(app.repository.get(XMIData._id)) + app.project.importFromJson(app.project.getProject(), XMIData); + app.modelExplorer.expand(app.repository.get(XMIData._id)); } -exports.enumerations = enumerations -exports.elements = elements -exports.postprocessors = postprocessors +exports.enumerations = enumerations; +exports.elements = elements; +exports.postprocessors = postprocessors; -exports.readString = readString -exports.readBoolean = readBoolean -exports.readInteger = readInteger -exports.readEnum = readEnum -exports.readExpression = readExpression -exports.readElement = readElement -exports.readElementArray = readElementArray -exports.readRef = readRef -exports.readRefArray = readRefArray +exports.readString = readString; +exports.readBoolean = readBoolean; +exports.readInteger = readInteger; +exports.readEnum = readEnum; +exports.readExpression = readExpression; +exports.readElement = readElement; +exports.readElementArray = readElementArray; +exports.readRef = readRef; +exports.readRefArray = readRefArray; -exports.postprocess = postprocess -exports.clear = clear -exports.get = get -exports.put = put -exports.getIdMap = getIdMap -exports.loadFromFile = loadFromFile +exports.postprocess = postprocess; +exports.clear = clear; +exports.get = get; +exports.put = put; +exports.getIdMap = getIdMap; +exports.loadFromFile = loadFromFile; diff --git a/xmi21-writer.js b/xmi21-writer.js index edabf5a..ace689b 100644 --- a/xmi21-writer.js +++ b/xmi21-writer.js @@ -1,27 +1,27 @@ /* -* Copyright (c) 2014 MKLab. All rights reserved. -* -* Permission is hereby granted, free of charge, to any person obtaining a -* copy of this software and associated documentation files (the "Software"), -* to deal in the Software without restriction, including without limitation -* the rights to use, copy, modify, merge, publish, distribute, sublicense, -* and/or sell copies of the Software, and to permit persons to whom the -* Software is furnished to do so, subject to the following conditions: -* -* The above copyright notice and this permission notice shall be included in -* all copies or substantial portions of the Software. -* -* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING -* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -* DEALINGS IN THE SOFTWARE. -* -*/ - -const fs = require('fs') + * Copyright (c) 2014 MKLab. All rights reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + * + */ + +const fs = require("fs"); /** * XMLWriter @@ -30,40 +30,40 @@ class XMLWriter { /** * @constructor */ - constructor (indentString) { + constructor(indentString) { /** @member {Array.} lines */ - this.lines = [] + this.lines = []; /** @member {string} indentString */ - this.indentString = indentString || '\t' // default tab + this.indentString = indentString || "\t"; // default tab /** @member {Array.} indentations */ - this.indentations = [] + this.indentations = []; } /** * Indent */ - indent () { - this.indentations.push(this.indentString) + indent() { + this.indentations.push(this.indentString); } /** * Outdent */ - outdent () { - this.indentations.splice(this.indentations.length - 1, 1) + outdent() { + this.indentations.splice(this.indentations.length - 1, 1); } /** * Write a line * @param {string} line */ - writeLine (line) { + writeLine(line) { if (line) { - this.lines.push(this.indentations.join('') + line) + this.lines.push(this.indentations.join("") + line); } else { - this.lines.push('') + this.lines.push(""); } } @@ -71,25 +71,25 @@ class XMLWriter { * Return as all string data * @return {string} */ - getData () { - return this.lines.join('\n') + getData() { + return this.lines.join("\n"); } } /** * Map for Enumeration Writers */ -var enumerations = {} +var enumerations = {}; /** * Map for Element Writers */ -var elements = {} +var elements = {}; /** * Nodes to be added later */ -var deferedNodes = [] +var deferedNodes = []; /** * Add a value to an array field @@ -97,11 +97,11 @@ var deferedNodes = [] * @param {string} name * @param {?} value */ -function addTo (json, name, value) { +function addTo(json, name, value) { if (!Array.isArray(json[name])) { - json[name] = [] + json[name] = []; } - json[name].push(value) + json[name].push(value); } /** @@ -110,25 +110,35 @@ function addTo (json, name, value) { * @param {string} name * @param {Array.} elements */ -function appendTo (json, name, elements) { +function appendTo(json, name, elements) { if (!Array.isArray(json[name])) { - json[name] = [] + json[name] = []; } - var arr = json[name] + var arr = json[name]; elements.forEach(function (elem) { - if (!arr.includes(elem) && !arr.some(function (item) { return item._id === elem._id })) { - arr.push(elem) + if ( + !arr.includes(elem) && + !arr.some(function (item) { + return item._id === elem._id; + }) + ) { + arr.push(elem); } - }) + }); } /** * Add a node to deferedNodes * @param{object} node */ -function addToDeferedNode (node) { - if (node['xmi:id'] && !deferedNodes.some(function (n) { return (n['xmi:id'] === node['xmi:id']) })) { - deferedNodes.push(node) +function addToDeferedNode(node) { + if ( + node["xmi:id"] && + !deferedNodes.some(function (n) { + return n["xmi:id"] === node["xmi:id"]; + }) + ) { + deferedNodes.push(node); } } @@ -137,8 +147,8 @@ function addToDeferedNode (node) { * @param {object} json * @param {string} typeName */ -function setType (json, typeName) { - json['xmi:type'] = typeName +function setType(json, typeName) { + json["xmi:type"] = typeName; } /** @@ -147,9 +157,9 @@ function setType (json, typeName) { * @param {string} name * @param {string} value */ -function writeString (json, name, value) { +function writeString(json, name, value) { if (value && value.length > 0) { - json[name] = value + json[name] = value; } } @@ -159,11 +169,11 @@ function writeString (json, name, value) { * @param {string} name * @param {boolean} value */ -function writeBoolean (json, name, value) { +function writeBoolean(json, name, value) { if (value) { - json[name] = 'true' + json[name] = "true"; } else { - json[name] = 'false' + json[name] = "false"; } } @@ -173,10 +183,10 @@ function writeBoolean (json, name, value) { * @param {string} name * @param {?} value */ -function writeEnum (json, name, type, value) { - var fun = enumerations[type] +function writeEnum(json, name, type, value) { + var fun = enumerations[type]; if (fun) { - json[name] = fun(value) + json[name] = fun(value); } } @@ -186,14 +196,14 @@ function writeEnum (json, name, type, value) { * @param {string} name * @param {Element} elem */ -function writeElement (json, name, elem) { - var fun = elements[elem.getClassName()] - var node = null +function writeElement(json, name, elem) { + var fun = elements[elem.getClassName()]; + var node = null; if (fun) { - node = fun(elem) - addTo(json, name, node) + node = fun(elem); + addTo(json, name, node); } - return node + return node; } /** @@ -202,14 +212,14 @@ function writeElement (json, name, elem) { * @param {string} name * @param {Array.} elems */ -function writeElementArray (json, name, elems) { +function writeElementArray(json, name, elems) { elems.forEach(function (elem) { - var fun = elements[elem.getClassName()] + var fun = elements[elem.getClassName()]; if (fun) { - var node = fun(elem) - addTo(json, name, node) + var node = fun(elem); + addTo(json, name, node); } - }) + }); } /** @@ -218,9 +228,9 @@ function writeElementArray (json, name, elems) { * @param {string} name * @param {Element} elem */ -function writeRef (json, name, elem) { +function writeRef(json, name, elem) { if (elem) { - json[name] = elem._id + json[name] = elem._id; } } @@ -230,13 +240,13 @@ function writeRef (json, name, elem) { * @param {string} name * @param {Array.} elems */ -function writeRefArray (json, name, elems) { +function writeRefArray(json, name, elems) { elems.forEach(function (elem) { if (elem) { - var node = { 'xmi:idref': elem._id } - addTo(json, name, node) + var node = { "xmi:idref": elem._id }; + addTo(json, name, node); } - }) + }); } /** @@ -246,23 +256,23 @@ function writeRefArray (json, name, elems) { * @param {string} valueType * @param {string} value */ -function writeValueSpec (json, name, valueType, value) { - value = String(value) - if (valueType === 'uml:OpaqueExpression') { +function writeValueSpec(json, name, valueType, value) { + value = String(value); + if (valueType === "uml:OpaqueExpression") { if (value && value.length > 0) { json[name] = { - 'xmi:id': app.repository.generateGuid(), - 'xmi:type': valueType, - 'body': value - } + "xmi:id": app.repository.generateGuid(), + "xmi:type": valueType, + body: value, + }; } } else { if (value && value.length > 0) { json[name] = { - 'xmi:id': app.repository.generateGuid(), - 'xmi:type': valueType, - 'value': value - } + "xmi:id": app.repository.generateGuid(), + "xmi:type": valueType, + value: value, + }; } } } @@ -272,16 +282,16 @@ function writeValueSpec (json, name, valueType, value) { * @param {object} json * @param {object} valueMap */ -function writeExtension (json, valueMap) { - var node = json['xmi:Extension'] +function writeExtension(json, valueMap) { + var node = json["xmi:Extension"]; if (!node) { node = { - 'extender': 'StarUML' - } - json['xmi:Extension'] = node + extender: "StarUML", + }; + json["xmi:Extension"] = node; } for (var key in valueMap) { - node[key] = valueMap[key] + node[key] = valueMap[key]; } } @@ -291,45 +301,45 @@ function writeExtension (json, valueMap) { * @param{XMLWriter} xmlWriter * @param{string} tagName */ -function convertJsonToXML (json, xmlWriter, tagName) { - tagName = tagName || json['xmi:type'] +function convertJsonToXML(json, xmlWriter, tagName) { + tagName = tagName || json["xmi:type"]; - var line = '<' + tagName + var line = "<" + tagName; // Convert attributes - var childCount = 0 - var key, val + var childCount = 0; + var key, val; for (key in json) { - val = json[key] - if (typeof val === 'string') { - line += ' ' + key + '="' + encodeURI(val) + '"' - } else if (!(typeof val === 'object')) { - line += ' ' + key + '="' + val + '"' + val = json[key]; + if (typeof val === "string") { + line += " " + key + '="' + encodeURI(val) + '"'; + } else if (!(typeof val === "object")) { + line += " " + key + '="' + val + '"'; } else { - childCount++ + childCount++; } } if (childCount > 0) { - line += '>' - xmlWriter.writeLine(line) - xmlWriter.indent() + line += ">"; + xmlWriter.writeLine(line); + xmlWriter.indent(); // Convert children for (key in json) { - val = json[key] + val = json[key]; if (Array.isArray(val)) { val.forEach(function (item) { - convertJsonToXML(item, xmlWriter, key) - }) - } else if (typeof val === 'object') { - convertJsonToXML(val, xmlWriter, key) + convertJsonToXML(item, xmlWriter, key); + }); + } else if (typeof val === "object") { + convertJsonToXML(val, xmlWriter, key); } } - xmlWriter.outdent() - xmlWriter.writeLine('') + xmlWriter.outdent(); + xmlWriter.writeLine(""); } else { - line += '/>' - xmlWriter.writeLine(line) + line += "/>"; + xmlWriter.writeLine(line); } } @@ -339,54 +349,58 @@ function convertJsonToXML (json, xmlWriter, tagName) { * @param {string} filename * @return {$.Promise} */ -function saveToFile (filename) { +function saveToFile(filename) { try { // Build intermediate JSON representations - var project = app.project.getProject() + var project = app.project.getProject(); var root = { - 'xmi:id': app.repository.generateGuid(), - 'xmi:type': 'uml:Model', - 'name': 'RootModel', - 'packagedElement': [] - } - writeElementArray(root, 'packagedElement', project.ownedElements) + "xmi:id": app.repository.generateGuid(), + "xmi:type": "uml:Model", + name: "RootModel", + packagedElement: [], + }; + writeElementArray(root, "packagedElement", project.ownedElements); deferedNodes.forEach(function (node) { - addTo(root, 'packagedElement', node) - }) + addTo(root, "packagedElement", node); + }); // Convert to XML - var xmlWriter = new XMLWriter() - xmlWriter.writeLine('') - xmlWriter.writeLine('') - xmlWriter.indent() - xmlWriter.writeLine('') - convertJsonToXML(root, xmlWriter) - xmlWriter.outdent() - xmlWriter.writeLine('') + var xmlWriter = new XMLWriter(); + xmlWriter.writeLine(''); + xmlWriter.writeLine( + '', + ); + xmlWriter.indent(); + xmlWriter.writeLine( + '', + ); + convertJsonToXML(root, xmlWriter); + xmlWriter.outdent(); + xmlWriter.writeLine(""); // Save to File - fs.writeFileSync(filename, xmlWriter.getData()) + fs.writeFileSync(filename, xmlWriter.getData()); } catch (err) { - console.error(err) + console.error(err); } } -exports.enumerations = enumerations -exports.elements = elements -exports.deferedNodes = deferedNodes - -exports.addTo = addTo -exports.appendTo = appendTo -exports.addToDeferedNode = addToDeferedNode -exports.setType = setType -exports.writeString = writeString -exports.writeBoolean = writeBoolean -exports.writeEnum = writeEnum -exports.writeElement = writeElement -exports.writeElementArray = writeElementArray -exports.writeRef = writeRef -exports.writeRefArray = writeRefArray -exports.writeValueSpec = writeValueSpec -exports.writeExtension = writeExtension - -exports.saveToFile = saveToFile +exports.enumerations = enumerations; +exports.elements = elements; +exports.deferedNodes = deferedNodes; + +exports.addTo = addTo; +exports.appendTo = appendTo; +exports.addToDeferedNode = addToDeferedNode; +exports.setType = setType; +exports.writeString = writeString; +exports.writeBoolean = writeBoolean; +exports.writeEnum = writeEnum; +exports.writeElement = writeElement; +exports.writeElementArray = writeElementArray; +exports.writeRef = writeRef; +exports.writeRefArray = writeRefArray; +exports.writeValueSpec = writeValueSpec; +exports.writeExtension = writeExtension; + +exports.saveToFile = saveToFile;