@yellicode/elements
Version:
The meta model API for Yellicode - an extensible code generator.
893 lines (892 loc) • 46.9 kB
JavaScript
/*
* Copyright (c) 2020 Yellicode
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
/**
* This code was generated by a tool.
*
* Changes to this file may cause incorrect behavior and will be lost if the code is regenerated.
*/
import * as elements from './interfaces';
import * as classes from './classes';
var PRIMITIVE_BOOLEAN_ID = "boolean_id";
var PRIMITIVE_INTEGER_ID = "integer_id";
var PRIMITIVE_REAL_ID = "real_id";
var PRIMITIVE_STRING_ID = "string_id";
var PRIMITIVE_OBJECT_ID = "object_id";
var PRIMITIVE_UNLIMITEDNATURAL_ID = "unlimitednatural_id";
var DataToModelConverter = /** @class */ (function () {
function DataToModelConverter(elementMap, modelDelegate, elementComparer) {
var _this = this;
this.elementMap = elementMap;
this.modelDelegate = modelDelegate;
this.elementComparer = elementComparer;
this.referencesToResolve = [];
var primitiveTypes = this.createPrimitiveTypes();
primitiveTypes.forEach(function (t) {
_this.elementMap.addElement(t, null);
});
}
DataToModelConverter.prototype.createPrimitiveTypes = function () {
var result = [];
var booleanType = new classes.PrimitiveType(this.modelDelegate, null);
booleanType.id = PRIMITIVE_BOOLEAN_ID;
booleanType.name = 'boolean';
result.push(booleanType);
var integerType = new classes.PrimitiveType(this.modelDelegate, null);
integerType.id = PRIMITIVE_INTEGER_ID;
integerType.name = 'integer';
result.push(integerType);
var realType = new classes.PrimitiveType(this.modelDelegate, null);
realType.id = PRIMITIVE_REAL_ID;
realType.name = 'real';
result.push(realType);
var stringType = new classes.PrimitiveType(this.modelDelegate, null);
stringType.id = PRIMITIVE_STRING_ID;
stringType.name = 'string';
result.push(stringType);
var objectType = new classes.PrimitiveType(this.modelDelegate, null);
objectType.id = PRIMITIVE_OBJECT_ID;
objectType.name = 'object';
result.push(objectType);
var unlimitedNaturalType = new classes.PrimitiveType(this.modelDelegate, null);
unlimitedNaturalType.id = PRIMITIVE_UNLIMITEDNATURAL_ID;
unlimitedNaturalType.name = 'UnlimitedNatural';
result.push(unlimitedNaturalType);
return result;
};
DataToModelConverter.prototype.createElementType = function (elementData) {
switch (elementData) // serialized as string
{
case 'class': return elements.ElementType.class;
case 'stereotype': return elements.ElementType.stereotype;
case 'property': return elements.ElementType.property;
case 'package': return elements.ElementType.package;
case 'profile': return elements.ElementType.profile;
case 'dataType': return elements.ElementType.dataType;
case 'primitiveType': return elements.ElementType.primitiveType;
case 'parameter': return elements.ElementType.parameter;
case 'operation': return elements.ElementType.operation;
case 'model': return elements.ElementType.model;
case 'literalUnlimitedNatural': return elements.ElementType.literalUnlimitedNatural;
case 'literalString': return elements.ElementType.literalString;
case 'literalReal': return elements.ElementType.literalReal;
case 'literalNull': return elements.ElementType.literalNull;
case 'literalInteger': return elements.ElementType.literalInteger;
case 'literalBoolean': return elements.ElementType.literalBoolean;
case 'interfaceRealization': return elements.ElementType.interfaceRealization;
case 'interface': return elements.ElementType.interface;
case 'generalization': return elements.ElementType.generalization;
case 'enumerationLiteral': return elements.ElementType.enumerationLiteral;
case 'enumeration': return elements.ElementType.enumeration;
case 'comment': return elements.ElementType.comment;
case 'association': return elements.ElementType.association;
default: throw "Error reading model. Could not map ElementType value '" + elementData + "'.";
}
};
/**
* NOTE: this function must be edited in the partial template file.
*/
DataToModelConverter.prototype.createElementId = function (elementId) {
return elementId; //
// Obsolete: ids must be prefixed if we are loading a referenced document, because references to it
// are prefixed with the document id
//return this.elementIdPrefix ? this.elementIdPrefix + '.' + elementId : elementId;
};
/**
* NOTE: this function must be edited in the partial template file.
*/
DataToModelConverter.prototype.convert = function (elementData, profiles) {
// this.elementIdPrefix = elementIdPrefix;
var _this = this;
// Deprecated: Extend prototypes with profile specific accessors
// if (profiles) {
// ProfileExtender.applyProfiles(profiles);
// }
// Load the object tree recursively. This will fill elementMap and referencesToResolve.
var model = this.createModel(elementData);
// Now the object tree is loaded, set references between objects
this.referencesToResolve.forEach(function (item) {
item.resolvefn.call(_this, item.target, item.data);
});
this.referencesToResolve = []; // Release this list
return model;
};
/**
* NOTE: this function must be edited in the partial template file.
*/
DataToModelConverter.prototype.addElementById = function (elementData, element) {
if ((!elementData.id || elementData.id.length === 0)) {
// The following element types do not require an id
if (elementData.elementType !== 'enumerationLiteral' && elementData.elementType !== 'comment' && !DataToModelConverter.isValueSpecification(elementData.elementType)) {
console.warn("Mising id on element of type '" + elementData.elementType + "'.");
}
return;
}
this.elementMap.addElement(element, elementData);
};
/**
* Gets the id of the matching built-in primitive type if the element type is a literal type.
* NOTE: this function must be edited in the partial template file.
*/
DataToModelConverter.getTypeIdIfLiteralType = function (elementType) {
switch (elementType) {
case 'literalBoolean':
return PRIMITIVE_BOOLEAN_ID;
case 'literalInteger':
return PRIMITIVE_INTEGER_ID;
case 'literalReal':
return PRIMITIVE_REAL_ID;
case 'literalString':
return PRIMITIVE_STRING_ID;
case 'literalUnlimitedNatural':
return PRIMITIVE_UNLIMITEDNATURAL_ID;
default:
// TODO: deal with literalNull?
return undefined; // returns undefined because the result is assigned to a data property "type?: string;"
}
};
/**
* Custom function to create element properties from tagged values.
* NOTE: this function must be edited in the partial template file.
*/
DataToModelConverter.prototype.mapTaggedValues = function (elementData, element) {
var _this = this;
if (!elementData.appliedStereotypes)
return;
// Get the stereotypes applied to this element. For each stereotype, get the meta properties.
// Note that we should not use element.appliedStereotypes because that data is not available
// at this point.
elementData.appliedStereotypes.forEach(function (stereotypeId) {
// Lookup the stereotype by id. It should be indexed because the profiles are loaded first
var st = _this.elementMap.getElementById(stereotypeId);
if (!st) {
return console.warn("Element " + element.id + " refers to undefined stereotype " + stereotypeId + ".");
}
element["stereotypeName"] = st.name; // always generated
var stereotypeMetaProperties = st.getAllAttributes(); // stereotypes can inherit other stereotypes
stereotypeMetaProperties.forEach(function (metaProperty) {
if (element.hasOwnProperty(metaProperty.name))
return;
// Extend the element with the property. But determine the value first.
var valueSpecification = null;
var taggedValue = elementData.taggedValues ? elementData.taggedValues.find(function (v) { return v.definition === metaProperty.id; }) : null;
if (taggedValue) {
valueSpecification = _this.createValueSpecification(taggedValue.specification, element);
}
else if (metaProperty.defaultValue) {
valueSpecification = metaProperty.defaultValue;
}
element[metaProperty.name] = valueSpecification ? valueSpecification.getValue() : null;
});
});
};
DataToModelConverter.prototype.createVisibilityKind = function (elementData) {
switch (elementData) // serialized as string
{
case 'public': return elements.VisibilityKind.public;
case 'private': return elements.VisibilityKind.private;
case 'protected': return elements.VisibilityKind.protected;
case 'package': return elements.VisibilityKind.package;
default: throw "Error reading model. Could not map VisibilityKind value '" + elementData + "'.";
}
};
DataToModelConverter.prototype.mapElement = function (elementData, target, owner) {
var _a, _b;
var _this = this;
target.id = this.createElementId(elementData.id);
if (elementData.ownedComments) {
(_a = target.ownedComments).push.apply(_a, elementData.ownedComments.map(function (e) { return _this.createComment(e, target); }));
}
if (elementData.taggedValues) {
(_b = target.taggedValues).push.apply(_b, elementData.taggedValues.map(function (e) { return _this.createTaggedValueSpecification(e, target); }));
}
this.referencesToResolve.push({ target: target, data: elementData, resolvefn: this.resolveElementReferences });
};
DataToModelConverter.prototype.resolveElementReferences = function (target, elementData) {
var _a;
if (elementData.appliedStereotypes) {
(_a = target.appliedStereotypes).push.apply(_a, this.elementMap.getElementsByIdList(elementData.appliedStereotypes));
}
};
DataToModelConverter.prototype.mapNamedElement = function (elementData, target, owner) {
if (elementData.isDeprecated) {
target.isDeprecated = elementData.isDeprecated;
}
if (elementData.name) {
target.name = elementData.name;
}
if (elementData.visibility) {
target.visibility = this.createVisibilityKind(elementData.visibility);
}
};
DataToModelConverter.prototype.mapTypedElement = function (elementData, target, owner) {
this.referencesToResolve.push({ target: target, data: elementData, resolvefn: this.resolveTypedElementReferences });
};
DataToModelConverter.prototype.resolveTypedElementReferences = function (target, elementData) {
// Special case for TypedElement: if this is a literal specification, the type can be a predefined primitive.
if (!elementData.type) {
elementData.type = DataToModelConverter.getTypeIdIfLiteralType(elementData.elementType);
}
target.type = elementData.type ? this.elementMap.getElementById(elementData.type) : null;
};
DataToModelConverter.prototype.createValueSpecification = function (elementData, owner) {
switch (elementData.elementType) {
case "literalUnlimitedNatural":
return this.createLiteralUnlimitedNatural(elementData, owner);
case "literalString":
return this.createLiteralString(elementData, owner);
case "literalReal":
return this.createLiteralReal(elementData, owner);
case "literalNull":
return this.createLiteralNull(elementData, owner);
case "literalInteger":
return this.createLiteralInteger(elementData, owner);
case "literalBoolean":
return this.createLiteralBoolean(elementData, owner);
default: throw "Error reading model. Could not map ValueSpecification of type " + elementData.elementType + ".";
}
};
DataToModelConverter.isValueSpecification = function (elementType) {
switch (elementType) {
case "literalUnlimitedNatural":
case "literalString":
case "literalReal":
case "literalNull":
case "literalInteger":
case "literalBoolean":
return true;
default: return false;
}
};
DataToModelConverter.prototype.mapPackageableElement = function (elementData, target, owner) {
};
DataToModelConverter.prototype.createPackageableElement = function (elementData, owner) {
switch (elementData.elementType) {
case "interface":
return this.createInterface(elementData, owner);
case "primitiveType":
return this.createPrimitiveType(elementData, owner);
case "enumeration":
return this.createEnumeration(elementData, owner);
case "dataType":
return this.createDataType(elementData, owner);
case "stereotype":
return this.createStereotype(elementData, owner);
case "class":
return this.createClass(elementData, owner);
case "association":
return this.createAssociation(elementData, owner);
case "profile":
return this.createProfile(elementData, owner);
case "package":
return this.createPackage(elementData, owner);
default: throw "Error reading model. Could not map PackageableElement of type " + elementData.elementType + ".";
}
};
DataToModelConverter.isPackageableElement = function (elementType) {
switch (elementType) {
case "interface":
case "primitiveType":
case "enumeration":
case "dataType":
case "stereotype":
case "class":
case "association":
case "profile":
case "package":
return true;
default: return false;
}
};
DataToModelConverter.prototype.mapType = function (elementData, target, owner) {
if (elementData.isInferred) {
target.isInferred = elementData.isInferred;
}
};
DataToModelConverter.prototype.mapTaggedValueSpecification = function (elementData, target, owner) {
if (elementData.specification) {
target.specification = this.createValueSpecification(elementData.specification, owner);
}
this.referencesToResolve.push({ target: target, data: elementData, resolvefn: this.resolveTaggedValueSpecificationReferences });
};
DataToModelConverter.prototype.resolveTaggedValueSpecificationReferences = function (target, elementData) {
if (!elementData.definition)
console.error("Unable to set property 'definition'. The following data is missing a 'definition' field: " + JSON.stringify(elementData) + ".");
var definition = this.elementMap.getElementById(elementData.definition);
if (definition) {
target.definition = definition;
}
else
console.error("Unable to set property 'definition'. Property with id '" + elementData.definition + "' does not exist.");
};
DataToModelConverter.prototype.createTaggedValueSpecification = function (elementData, owner) {
var element = new classes.TaggedValueSpecification();
this.mapTaggedValueSpecification(elementData, element, owner);
return element;
};
DataToModelConverter.prototype.mapRedefinableElement = function (elementData, target, owner) {
if (elementData.isLeaf) {
target.isLeaf = elementData.isLeaf;
}
};
DataToModelConverter.prototype.mapClassifier = function (elementData, target, owner) {
var _a;
var _this = this;
if (elementData.generalizations) {
(_a = target.generalizations).push.apply(_a, elementData.generalizations.map(function (e) { return _this.createGeneralization(e, target); }));
}
if (elementData.isAbstract) {
target.isAbstract = elementData.isAbstract;
}
if (elementData.isFinalSpecialization) {
target.isFinalSpecialization = elementData.isFinalSpecialization;
}
};
DataToModelConverter.prototype.mapMultiplicityElement = function (elementData, target, owner) {
if (elementData.isOrdered) {
target.isOrdered = elementData.isOrdered;
}
if (elementData.isUnique) {
target.isUnique = elementData.isUnique;
}
if (elementData.lowerValue) {
target.lowerValue = this.createValueSpecification(elementData.lowerValue, target);
}
if (elementData.upperValue) {
target.upperValue = this.createValueSpecification(elementData.upperValue, target);
}
};
DataToModelConverter.prototype.mapOrderedElement = function (elementData, target, owner) {
if (elementData.order) {
target.order = elementData.order;
}
};
DataToModelConverter.prototype.mapFeature = function (elementData, target, owner) {
if (elementData.isStatic) {
target.isStatic = elementData.isStatic;
}
};
DataToModelConverter.prototype.mapStructuralFeature = function (elementData, target, owner) {
if (elementData.isReadOnly) {
target.isReadOnly = elementData.isReadOnly;
}
};
DataToModelConverter.prototype.mapStereotypeExtension = function (elementData, target, owner) {
if (elementData.isRequired) {
target.isRequired = elementData.isRequired;
}
if (elementData.metaClass) {
target.metaClass = this.createElementType(elementData.metaClass);
}
};
DataToModelConverter.prototype.createStereotypeExtension = function (elementData, owner) {
var element = new classes.StereotypeExtension();
this.mapStereotypeExtension(elementData, element, owner);
return element;
};
DataToModelConverter.prototype.mapMemberedClassifier = function (elementData, target, owner) {
var _a, _b;
var _this = this;
if (elementData.ownedAttributes) {
(_a = target.ownedAttributes).push.apply(_a, elementData.ownedAttributes.map(function (e) { return _this.createProperty(e, target); }).sort(this.elementComparer.compareOrderedElements));
}
if (elementData.ownedOperations) {
(_b = target.ownedOperations).push.apply(_b, elementData.ownedOperations.map(function (e) { return _this.createOperation(e, target); }).sort(this.elementComparer.compareOrderedElements));
}
};
DataToModelConverter.prototype.mapBehavioredClassifier = function (elementData, target, owner) {
var _a;
var _this = this;
if (elementData.interfaceRealizations) {
(_a = target.interfaceRealizations).push.apply(_a, elementData.interfaceRealizations.map(function (e) { return _this.createInterfaceRealization(e, target); }));
}
};
DataToModelConverter.prototype.mapClass = function (elementData, target, owner) {
if (elementData.isActive) {
target.isActive = elementData.isActive;
}
};
DataToModelConverter.prototype.createClass = function (elementData, owner) {
var element = new classes.Class(this.modelDelegate, owner);
this.mapElement(elementData, element, element);
this.mapNamedElement(elementData, element, element);
this.mapPackageableElement(elementData, element, element);
this.mapRedefinableElement(elementData, element, element);
this.mapType(elementData, element, element);
this.mapClassifier(elementData, element, element);
this.mapMemberedClassifier(elementData, element, element);
this.mapBehavioredClassifier(elementData, element, element);
this.mapClass(elementData, element, element);
this.mapTaggedValues(elementData, element); // added by code generation
this.addElementById(elementData, element);
return element;
};
DataToModelConverter.prototype.mapStereotype = function (elementData, target, owner) {
var _a;
var _this = this;
if (elementData.extends) {
(_a = target.extends).push.apply(_a, elementData.extends.map(function (e) { return _this.createStereotypeExtension(e, target); }));
}
if (elementData.safeName) {
target.safeName = elementData.safeName;
}
};
DataToModelConverter.prototype.createStereotype = function (elementData, owner) {
var element = new classes.Stereotype(this.modelDelegate, owner);
this.mapElement(elementData, element, element);
this.mapNamedElement(elementData, element, element);
this.mapPackageableElement(elementData, element, element);
this.mapRedefinableElement(elementData, element, element);
this.mapType(elementData, element, element);
this.mapClassifier(elementData, element, element);
this.mapMemberedClassifier(elementData, element, element);
this.mapBehavioredClassifier(elementData, element, element);
this.mapClass(elementData, element, element);
this.mapStereotype(elementData, element, element);
this.mapTaggedValues(elementData, element); // added by code generation
this.addElementById(elementData, element);
return element;
};
DataToModelConverter.prototype.mapProperty = function (elementData, target, owner) {
if (elementData.aggregation) {
target.aggregation = this.createAggregationKind(elementData.aggregation);
}
if (elementData.defaultValue) {
target.defaultValue = this.createValueSpecification(elementData.defaultValue, target);
}
if (elementData.isDerived) {
target.isDerived = elementData.isDerived;
}
if (elementData.isDerivedUnion) {
target.isDerivedUnion = elementData.isDerivedUnion;
}
if (elementData.isID) {
target.isID = elementData.isID;
}
if (elementData.isNavigable) {
target.isNavigable = elementData.isNavigable;
}
};
DataToModelConverter.prototype.createProperty = function (elementData, owner) {
var element = new classes.Property(this.modelDelegate, owner);
this.mapElement(elementData, element, element);
this.mapNamedElement(elementData, element, element);
this.mapOrderedElement(elementData, element, element);
this.mapRedefinableElement(elementData, element, element);
this.mapTypedElement(elementData, element, element);
this.mapMultiplicityElement(elementData, element, element);
this.mapFeature(elementData, element, element);
this.mapStructuralFeature(elementData, element, element);
this.mapProperty(elementData, element, element);
this.mapTaggedValues(elementData, element); // added by code generation
this.addElementById(elementData, element);
return element;
};
DataToModelConverter.prototype.mapPackage = function (elementData, target, owner) {
var _a;
var _this = this;
if (elementData.isNamespaceRoot) {
target.isNamespaceRoot = elementData.isNamespaceRoot;
}
if (elementData.packagedElements) {
(_a = target.packagedElements).push.apply(_a, elementData.packagedElements.map(function (e) { return _this.createPackageableElement(e, target); }).sort(this.elementComparer.comparePackageableElements));
}
this.referencesToResolve.push({ target: target, data: elementData, resolvefn: this.resolvePackageReferences });
};
DataToModelConverter.prototype.resolvePackageReferences = function (target, elementData) {
var _a;
if (elementData.appliedProfiles) {
(_a = target.appliedProfiles).push.apply(_a, this.elementMap.getElementsByIdList(elementData.appliedProfiles));
}
};
DataToModelConverter.prototype.createPackage = function (elementData, owner) {
var element = new classes.Package(this.modelDelegate, owner);
this.mapElement(elementData, element, element);
this.mapNamedElement(elementData, element, element);
this.mapPackageableElement(elementData, element, element);
this.mapPackage(elementData, element, element);
this.mapTaggedValues(elementData, element); // added by code generation
this.addElementById(elementData, element);
return element;
};
DataToModelConverter.prototype.mapProfile = function (elementData, target, owner) {
if (elementData.safeName) {
target.safeName = elementData.safeName;
}
};
DataToModelConverter.prototype.createProfile = function (elementData, owner) {
var element = new classes.Profile(this.modelDelegate, owner);
this.mapElement(elementData, element, element);
this.mapNamedElement(elementData, element, element);
this.mapPackageableElement(elementData, element, element);
this.mapPackage(elementData, element, element);
this.mapProfile(elementData, element, element);
this.mapTaggedValues(elementData, element); // added by code generation
this.addElementById(elementData, element);
return element;
};
DataToModelConverter.prototype.createDataType = function (elementData, owner) {
var element = new classes.DataType(this.modelDelegate, owner);
this.mapElement(elementData, element, element);
this.mapNamedElement(elementData, element, element);
this.mapPackageableElement(elementData, element, element);
this.mapRedefinableElement(elementData, element, element);
this.mapType(elementData, element, element);
this.mapClassifier(elementData, element, element);
this.mapMemberedClassifier(elementData, element, element);
this.mapTaggedValues(elementData, element); // added by code generation
this.addElementById(elementData, element);
return element;
};
DataToModelConverter.prototype.createPrimitiveType = function (elementData, owner) {
var element = new classes.PrimitiveType(this.modelDelegate, owner);
this.mapElement(elementData, element, element);
this.mapNamedElement(elementData, element, element);
this.mapPackageableElement(elementData, element, element);
this.mapRedefinableElement(elementData, element, element);
this.mapType(elementData, element, element);
this.mapClassifier(elementData, element, element);
this.mapMemberedClassifier(elementData, element, element);
this.mapTaggedValues(elementData, element); // added by code generation
this.addElementById(elementData, element);
return element;
};
DataToModelConverter.prototype.createParameterDirectionKind = function (elementData) {
switch (elementData) // serialized as string
{
case 'in': return elements.ParameterDirectionKind.in;
case 'inout': return elements.ParameterDirectionKind.inout;
case 'out': return elements.ParameterDirectionKind.out;
case 'return': return elements.ParameterDirectionKind.return;
default: throw "Error reading model. Could not map ParameterDirectionKind value '" + elementData + "'.";
}
};
DataToModelConverter.prototype.mapParameter = function (elementData, target, owner) {
if (elementData.defaultValue) {
target.defaultValue = this.createValueSpecification(elementData.defaultValue, target);
}
if (elementData.direction) {
target.direction = this.createParameterDirectionKind(elementData.direction);
}
if (elementData.isException) {
target.isException = elementData.isException;
}
if (elementData.isStream) {
target.isStream = elementData.isStream;
}
};
DataToModelConverter.prototype.createParameter = function (elementData, owner) {
var element = new classes.Parameter(this.modelDelegate, owner);
this.mapElement(elementData, element, element);
this.mapNamedElement(elementData, element, element);
this.mapOrderedElement(elementData, element, element);
this.mapMultiplicityElement(elementData, element, element);
this.mapTypedElement(elementData, element, element);
this.mapParameter(elementData, element, element);
this.mapTaggedValues(elementData, element); // added by code generation
this.addElementById(elementData, element);
return element;
};
DataToModelConverter.prototype.mapBehavioralFeature = function (elementData, target, owner) {
var _a;
var _this = this;
if (elementData.isAbstract) {
target.isAbstract = elementData.isAbstract;
}
if (elementData.ownedParameters) {
(_a = target.ownedParameters).push.apply(_a, elementData.ownedParameters.map(function (e) { return _this.createParameter(e, target); }).sort(this.elementComparer.compareOrderedElements));
}
};
DataToModelConverter.prototype.mapOperation = function (elementData, target, owner) {
if (elementData.isConstructor) {
target.isConstructor = elementData.isConstructor;
}
if (elementData.isQuery) {
target.isQuery = elementData.isQuery;
}
};
DataToModelConverter.prototype.createOperation = function (elementData, owner) {
var element = new classes.Operation(this.modelDelegate, owner);
this.mapElement(elementData, element, element);
this.mapNamedElement(elementData, element, element);
this.mapOrderedElement(elementData, element, element);
this.mapRedefinableElement(elementData, element, element);
this.mapFeature(elementData, element, element);
this.mapBehavioralFeature(elementData, element, element);
this.mapOperation(elementData, element, element);
this.mapTaggedValues(elementData, element); // added by code generation
this.addElementById(elementData, element);
return element;
};
DataToModelConverter.prototype.createModel = function (elementData) {
var element = new classes.Model(this.modelDelegate, null);
this.mapElement(elementData, element, element);
this.mapNamedElement(elementData, element, element);
this.mapPackageableElement(elementData, element, element);
this.mapPackage(elementData, element, element);
this.mapTaggedValues(elementData, element); // added by code generation
this.addElementById(elementData, element);
return element;
};
DataToModelConverter.prototype.mapLiteralUnlimitedNatural = function (elementData, target, owner) {
if (elementData.value) {
target.value = new elements.UnlimitedNatural(elementData.value);
}
};
DataToModelConverter.prototype.createLiteralUnlimitedNatural = function (elementData, owner) {
var element = new classes.LiteralUnlimitedNatural(this.modelDelegate, owner);
this.mapElement(elementData, element, element);
this.mapNamedElement(elementData, element, element);
this.mapTypedElement(elementData, element, element);
this.mapLiteralUnlimitedNatural(elementData, element, element);
this.mapTaggedValues(elementData, element); // added by code generation
this.addElementById(elementData, element);
return element;
};
DataToModelConverter.prototype.mapLiteralString = function (elementData, target, owner) {
if (elementData.value) {
target.value = elementData.value;
}
};
DataToModelConverter.prototype.createLiteralString = function (elementData, owner) {
var element = new classes.LiteralString(this.modelDelegate, owner);
this.mapElement(elementData, element, element);
this.mapNamedElement(elementData, element, element);
this.mapTypedElement(elementData, element, element);
this.mapLiteralString(elementData, element, element);
this.mapTaggedValues(elementData, element); // added by code generation
this.addElementById(elementData, element);
return element;
};
DataToModelConverter.prototype.mapLiteralReal = function (elementData, target, owner) {
if (elementData.value) {
target.value = elementData.value;
}
};
DataToModelConverter.prototype.createLiteralReal = function (elementData, owner) {
var element = new classes.LiteralReal(this.modelDelegate, owner);
this.mapElement(elementData, element, element);
this.mapNamedElement(elementData, element, element);
this.mapTypedElement(elementData, element, element);
this.mapLiteralReal(elementData, element, element);
this.mapTaggedValues(elementData, element); // added by code generation
this.addElementById(elementData, element);
return element;
};
DataToModelConverter.prototype.createLiteralNull = function (elementData, owner) {
var element = new classes.LiteralNull(this.modelDelegate, owner);
this.mapElement(elementData, element, element);
this.mapNamedElement(elementData, element, element);
this.mapTypedElement(elementData, element, element);
this.mapTaggedValues(elementData, element); // added by code generation
this.addElementById(elementData, element);
return element;
};
DataToModelConverter.prototype.mapLiteralInteger = function (elementData, target, owner) {
if (elementData.value) {
target.value = elementData.value;
}
};
DataToModelConverter.prototype.createLiteralInteger = function (elementData, owner) {
var element = new classes.LiteralInteger(this.modelDelegate, owner);
this.mapElement(elementData, element, element);
this.mapNamedElement(elementData, element, element);
this.mapTypedElement(elementData, element, element);
this.mapLiteralInteger(elementData, element, element);
this.mapTaggedValues(elementData, element); // added by code generation
this.addElementById(elementData, element);
return element;
};
DataToModelConverter.prototype.mapLiteralBoolean = function (elementData, target, owner) {
if (elementData.value) {
target.value = elementData.value;
}
};
DataToModelConverter.prototype.createLiteralBoolean = function (elementData, owner) {
var element = new classes.LiteralBoolean(this.modelDelegate, owner);
this.mapElement(elementData, element, element);
this.mapNamedElement(elementData, element, element);
this.mapTypedElement(elementData, element, element);
this.mapLiteralBoolean(elementData, element, element);
this.mapTaggedValues(elementData, element); // added by code generation
this.addElementById(elementData, element);
return element;
};
DataToModelConverter.prototype.mapInterfaceRealization = function (elementData, target, owner) {
this.referencesToResolve.push({ target: target, data: elementData, resolvefn: this.resolveInterfaceRealizationReferences });
};
DataToModelConverter.prototype.resolveInterfaceRealizationReferences = function (target, elementData) {
if (!elementData.contract)
console.error("Unable to set property 'contract'. The following data is missing a 'contract' field: " + JSON.stringify(elementData) + ".");
var contract = this.elementMap.getElementById(elementData.contract);
if (contract) {
target.contract = contract;
}
else
console.error("Unable to set property 'contract'. Interface with id '" + elementData.contract + "' does not exist.");
};
DataToModelConverter.prototype.createInterfaceRealization = function (elementData, owner) {
var element = new classes.InterfaceRealization(this.modelDelegate, owner);
this.mapElement(elementData, element, element);
this.mapInterfaceRealization(elementData, element, element);
this.mapTaggedValues(elementData, element); // added by code generation
this.addElementById(elementData, element);
return element;
};
DataToModelConverter.prototype.createInterface = function (elementData, owner) {
var element = new classes.Interface(this.modelDelegate, owner);
this.mapElement(elementData, element, element);
this.mapNamedElement(elementData, element, element);
this.mapPackageableElement(elementData, element, element);
this.mapRedefinableElement(elementData, element, element);
this.mapType(elementData, element, element);
this.mapClassifier(elementData, element, element);
this.mapMemberedClassifier(elementData, element, element);
this.mapTaggedValues(elementData, element); // added by code generation
this.addElementById(elementData, element);
return element;
};
DataToModelConverter.prototype.mapGeneralization = function (elementData, target, owner) {
if (elementData.isSubstitutable) {
target.isSubstitutable = elementData.isSubstitutable;
}
this.referencesToResolve.push({ target: target, data: elementData, resolvefn: this.resolveGeneralizationReferences });
};
DataToModelConverter.prototype.resolveGeneralizationReferences = function (target, elementData) {
if (!elementData.general)
console.error("Unable to set property 'general'. The following data is missing a 'general' field: " + JSON.stringify(elementData) + ".");
var general = this.elementMap.getElementById(elementData.general);
if (general) {
target.general = general;
}
else
console.error("Unable to set property 'general'. Classifier with id '" + elementData.general + "' does not exist.");
};
DataToModelConverter.prototype.createGeneralization = function (elementData, owner) {
var element = new classes.Generalization(this.modelDelegate, owner);
this.mapElement(elementData, element, element);
this.mapGeneralization(elementData, element, element);
this.mapTaggedValues(elementData, element); // added by code generation
this.addElementById(elementData, element);
return element;
};
DataToModelConverter.prototype.mapEnumerationLiteral = function (elementData, target, owner) {
if (elementData.specification) {
target.specification = this.createValueSpecification(elementData.specification, target);
}
};
DataToModelConverter.prototype.createEnumerationLiteral = function (elementData, owner) {
var element = new classes.EnumerationLiteral(this.modelDelegate, owner);
this.mapElement(elementData, element, element);
this.mapOrderedElement(elementData, element, element);
this.mapNamedElement(elementData, element, element);
this.mapEnumerationLiteral(elementData, element, element);
this.mapTaggedValues(elementData, element); // added by code generation
this.addElementById(elementData, element);
return element;
};
DataToModelConverter.prototype.mapEnumeration = function (elementData, target, owner) {
var _a;
var _this = this;
if (elementData.ownedLiterals) {
(_a = target.ownedLiterals).push.apply(_a, elementData.ownedLiterals.map(function (e) { return _this.createEnumerationLiteral(e, target); }).sort(this.elementComparer.compareOrderedElements));
}
this.referencesToResolve.push({ target: target, data: elementData, resolvefn: this.resolveEnumerationReferences });
};
DataToModelConverter.prototype.resolveEnumerationReferences = function (target, elementData) {
target.baseType = elementData.baseType ? this.elementMap.getElementById(elementData.baseType) : null;
};
DataToModelConverter.prototype.createEnumeration = function (elementData, owner) {
var element = new classes.Enumeration(this.modelDelegate, owner);
this.mapElement(elementData, element, element);
this.mapNamedElement(elementData, element, element);
this.mapPackageableElement(elementData, element, element);
this.mapRedefinableElement(elementData, element, element);
this.mapType(elementData, element, element);
this.mapClassifier(elementData, element, element);
this.mapMemberedClassifier(elementData, element, element);
this.mapEnumeration(elementData, element, element);
this.mapTaggedValues(elementData, element); // added by code generation
this.addElementById(elementData, element);
return element;
};
DataToModelConverter.prototype.mapDocumentReference = function (elementData, target, owner) {
if (elementData.location) {
target.location = this.createDocumentLocationKind(elementData.location);
}
if (elementData.name) {
target.name = elementData.name;
}
if (elementData.path) {
target.path = elementData.path;
}
};
DataToModelConverter.prototype.createDocumentReference = function (elementData, owner) {
var element = new classes.DocumentReference();
this.mapDocumentReference(elementData, element, owner);
return element;
};
DataToModelConverter.prototype.createDocumentLocationKind = function (elementData) {
switch (elementData) // serialized as string
{
case 'local': return elements.DocumentLocationKind.local;
case 'npm': return elements.DocumentLocationKind.npm;
default: throw "Error reading model. Could not map DocumentLocationKind value '" + elementData + "'.";
}
};
DataToModelConverter.prototype.mapComment = function (elementData, target, owner) {
if (elementData.body) {
target.body = elementData.body;
}
};
DataToModelConverter.prototype.createComment = function (elementData, owner) {
var element = new classes.Comment(this.modelDelegate, owner);
this.mapElement(elementData, element, element);
this.mapComment(elementData, element, element);
this.mapTaggedValues(elementData, element); // added by code generation
this.addElementById(elementData, element);
return element;
};
DataToModelConverter.prototype.mapAssociation = function (elementData, target, owner) {
var _a;
var _this = this;
if (elementData.ownedEnds) {
(_a = target.ownedEnds).push.apply(_a, elementData.ownedEnds.map(function (e) { return _this.createProperty(e, target); }).sort(this.elementComparer.compareOrderedElements));
}
this.referencesToResolve.push({ target: target, data: elementData, resolvefn: this.resolveAssociationReferences });
};
DataToModelConverter.prototype.resolveAssociationReferences = function (target, elementData) {
var _a;
if (elementData.memberEnds) {
(_a = target.memberEnds).push.apply(_a, this.elementMap.getElementsByIdList(elementData.memberEnds));
}
};
DataToModelConverter.prototype.createAssociation = function (elementData, owner) {
var element = new classes.Association(this.modelDelegate, owner);
this.mapElement(elementData, element, element);
this.mapNamedElement(elementData, element, element);
this.mapPackageableElement(elementData, element, element);
this.mapRedefinableElement(elementData, element, element);
this.mapType(elementData, element, element);
this.mapClassifier(elementData, element, element);
this.mapAssociation(elementData, element, element);
this.mapTaggedValues(elementData, element); // added by code generation
this.addElementById(elementData, element);
return element;
};
DataToModelConverter.prototype.createAggregationKind = function (elementData) {
switch (elementData) // serialized as string
{
case 'none': return elements.AggregationKind.none;
case 'shared': return elements.AggregationKind.shared;
case 'composite': return elements.AggregationKind.composite;
default: throw "Error reading model. Could not map AggregationKind value '" + elementData + "'.";
}
};
return DataToModelConverter;
}());
export { DataToModelConverter };