fix(nodeset-compiler): Use ParentNodeId attribute for parent node where possible

This commit is contained in:
Stefan Profanter 2020-04-10 16:27:08 +02:00
parent 0a6ccdbe44
commit f1f35981ea
No known key found for this signature in database
GPG Key ID: FB509DF184C9E89E
2 changed files with 16 additions and 0 deletions

View File

@ -74,6 +74,7 @@ class Node(object):
self.modelUri = None
self.parent = None
self.parentReference = None
self.parentIdAttribute = None
def __str__(self):
return self.__class__.__name__ + "(" + str(self.id) + ")"
@ -104,6 +105,8 @@ class Node(object):
self.eventNotifier = int(av)
elif at == "SymbolicName":
self.symbolicName = String(av)
elif at == "ParentNodeId":
self.parentIdAttribute = NodeId(av)
for x in xmlelement.childNodes:
if x.nodeType != x.ELEMENT_NODE:
@ -177,6 +180,8 @@ class Node(object):
self.browseName.ns = nsMapping[self.browseName.ns]
if hasattr(self, 'dataType') and isinstance(self.dataType, NodeId):
self.dataType.ns = nsMapping[self.dataType.ns]
if self.parentIdAttribute is not None:
self.parentIdAttribute.ns = nsMapping[self.parentIdAttribute.ns]
new_refs = set()
for ref in self.references:
ref.source.ns = nsMapping[ref.source.ns]

View File

@ -388,6 +388,17 @@ class NodeSet(object):
# ModellingRule, Root node do not have a parent
continue
# Check if the Nodeset explicitly defines a parent node
if node.parentIdAttribute is not None:
for ref in node.references:
if ref.target == node.parentIdAttribute:
node.parent = self.nodes[node.parentIdAttribute]
node.parentReference = self.nodes[ref.referenceType]
break
if node.parent is not None:
# if found, then stop here. Otherwise try to automatically determine parent based on refs
continue
parentref = node.getParentReference(parentreftypes)
if parentref is not None:
node.parent = self.nodes[parentref.target]