Bladeren bron

Nodset compiler: Support aliases for all uses of NodeIds

Julius Pfrommer 6 jaren geleden
bovenliggende
commit
9d8157ddf2
1 gewijzigde bestanden met toevoegingen van 16 en 12 verwijderingen
  1. 16 12
      tools/nodeset_compiler/nodes.py

+ 16 - 12
tools/nodeset_compiler/nodes.py

@@ -54,6 +54,12 @@ class Reference(object):
     def __hash__(self):
         return hash(str(self))
 
+def RefOrAlias(s):
+    try:
+        return NodeId(s)
+    except Exception:
+        return s
+
 class Node(object):
     def __init__(self):
         self.id = NodeId()
@@ -79,7 +85,7 @@ class Node(object):
     def parseXML(self, xmlelement):
         for idname in ['NodeId', 'NodeID', 'nodeid']:
             if xmlelement.hasAttribute(idname):
-                self.id = NodeId(xmlelement.getAttribute(idname))
+                self.id = RefOrAlias(xmlelement.getAttribute(idname))
 
         for (at, av) in xmlelement.attributes.items():
             if at == "BrowseName":
@@ -118,16 +124,14 @@ class Node(object):
         for ref in xmlelement.childNodes:
             if ref.nodeType != ref.ELEMENT_NODE:
                 continue
-            source = NodeId(str(self.id))  # deep-copy of the nodeid
-            target = NodeId(ref.firstChild.data)
+            source = RefOrAlias(str(self.id))  # deep-copy of the nodeid
+            target = RefOrAlias(ref.firstChild.data)
+
             reftype = None
             forward = True
             for (at, av) in ref.attributes.items():
                 if at == "ReferenceType":
-                    if '=' in av:
-                        reftype = NodeId(av)
-                    else:
-                        reftype = av  # alias, such as "HasSubType"
+                    reftype = RefOrAlias(av)
                 elif at == "IsForward":
                     forward = not "false" in av.lower()
             self.references.add(Reference(source, reftype, target, forward))
@@ -149,6 +153,9 @@ class Node(object):
     def replaceAliases(self, aliases):
         if str(self.id) in aliases:
             self.id = NodeId(aliases[self.id])
+        if isinstance(self, VariableNode) or isinstance(self, VariableTypeNode):
+            if str(self.dataType) in aliases:
+                self.dataType = NodeId(aliases[self.dataType])
         new_refs = set()
         for ref in self.references:
             if str(ref.source) in aliases:
@@ -241,10 +248,7 @@ class VariableNode(Node):
             elif at == "MinimumSamplingInterval":
                 self.minimumSamplingInterval = float(av)
             elif at == "DataType":
-                if "=" in av:
-                    self.dataType = NodeId(av)
-                else:
-                    self.dataType = av
+                self.dataType = RefOrAlias(av)
 
         for x in xmlelement.childNodes:
             if x.nodeType != x.ELEMENT_NODE:
@@ -252,7 +256,7 @@ class VariableNode(Node):
             if x.localName == "Value":
                 self.xmlValueDef = x
             elif x.localName == "DataType":
-                self.dataType = NodeId(str(x))
+                self.dataType = RefOrAlias(av)
             elif x.localName == "ValueRank":
                 self.valueRank = int(unicode(x.firstChild.data))
             elif x.localName == "ArrayDimensions":