moddle-xml
Advanced tools
Comparing version
@@ -388,2 +388,40 @@ import { forEach, assign, find, isString, findIndex, filter, has } from 'min-dash'; | ||
/** | ||
* Returns a property with an effective type descriptor, | ||
* in case type is defined through xml -> serialize hint. | ||
* | ||
* @param {any} node parsed | ||
* @param {PropertyDescriptor} property | ||
* | ||
* @return {PropertyDescriptor|null} | ||
*/ | ||
ElementHandler.prototype.getSerializeAsTypePropertyForNode = function(node, property) { | ||
const model = this.model; | ||
const serializationType = getSerializationType(property); | ||
if (!serializationType) { | ||
return null; | ||
} | ||
const elementTypeName = node.attributes[serializationType]; | ||
// type is optional, if it does not exists the | ||
// default type is assumed | ||
if (elementTypeName) { | ||
// convert the prefix used to the mapped form, but also | ||
// take possible type prefixes from XML | ||
// into account, i.e.: xsi:type="t{ActualType}", | ||
const normalizedTypeName = normalizeTypeName(elementTypeName, node.ns, model); | ||
const elementType = model.getType(normalizedTypeName); | ||
return assign({}, property, { | ||
effectiveType: getModdleDescriptor(elementType).name | ||
}); | ||
} | ||
}; | ||
ElementHandler.prototype.getPropertyForNode = function(node) { | ||
@@ -404,29 +442,6 @@ | ||
if (property && !property.isAttr) { | ||
const serializationType = getSerializationType(property); | ||
if (serializationType) { | ||
const elementTypeName = node.attributes[serializationType]; | ||
// type is optional, if it does not exists the | ||
// default type is assumed | ||
if (elementTypeName) { | ||
// convert the prefix used to the mapped form, but also | ||
// take possible type prefixes from XML | ||
// into account, i.e.: xsi:type="t{ActualType}", | ||
const normalizedTypeName = normalizeTypeName(elementTypeName, node.ns, model); | ||
const elementType = model.getType(normalizedTypeName); | ||
return assign({}, property, { | ||
effectiveType: getModdleDescriptor(elementType).name | ||
}); | ||
} | ||
} | ||
// search for properties by name first | ||
return property; | ||
return this.getSerializeAsTypePropertyForNode(node, property) || property; | ||
} | ||
// search by properties by type | ||
var pkg = model.getPackage(nameNs.prefix); | ||
@@ -444,6 +459,7 @@ | ||
if (property) { | ||
return assign({}, property, { | ||
return this.getSerializeAsTypePropertyForNode(node, property) || assign({}, property, { | ||
effectiveType: getModdleDescriptor(elementType).name | ||
}); | ||
} | ||
} else { | ||
@@ -450,0 +466,0 @@ |
{ | ||
"name": "moddle-xml", | ||
"version": "11.0.0-exp.1", | ||
"version": "11.0.0-exp.2", | ||
"description": "XML import/export for documents described with moddle", | ||
@@ -5,0 +5,0 @@ "scripts": { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
376141
0.75%6042
0.65%