Skip to content

Commit

Permalink
Merge 9293907 into c17b068
Browse files Browse the repository at this point in the history
  • Loading branch information
Pro committed Oct 31, 2018
2 parents c17b068 + 9293907 commit 87e3a9e
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 7 deletions.
9 changes: 6 additions & 3 deletions tools/nodeset_compiler/nodes.py
Expand Up @@ -70,6 +70,7 @@ def __init__(self):
self.userWriteMask = 0
self.references = set()
self.hidden = False
self.modelUri = None

def __str__(self):
return self.__class__.__name__ + "(" + str(self.id) + ")"
Expand Down Expand Up @@ -563,9 +564,11 @@ def buildEncoding(self, nodeset, indent=0, force=False):

# This might be a subtype... follow the node defined as datatype to find out
# what encoding to use
if not NodeId(fdtype) in nodeset.nodes:
raise Exception("Node {} not found in nodeset".format(NodeId(fdtype)))
dtnode = nodeset.nodes[NodeId(fdtype)]
fdTypeNodeId = NodeId(fdtype)
fdTypeNodeId.ns = nodeset.namespaceMapping[self.modelUri][fdTypeNodeId.ns]
if not fdTypeNodeId in nodeset.nodes:
raise Exception("Node {} not found in nodeset".format(fdTypeNodeId))
dtnode = nodeset.nodes[fdTypeNodeId]
# The node in the datatype element was found. we inherit its encoding,
# but must still ensure that the dtnode is itself validly encodable
typeDict.append([fname, dtnode])
Expand Down
28 changes: 24 additions & 4 deletions tools/nodeset_compiler/nodeset.py
Expand Up @@ -108,6 +108,7 @@ def __init__(self):
self.nodes = {}
self.aliases = {}
self.namespaces = ["http://opcfoundation.org/UA/"]
self.namespaceMapping = {};

def sanitize(self):
for n in self.nodes.values():
Expand Down Expand Up @@ -148,7 +149,7 @@ def getNodeById(self, namespace, id):
def getRoot(self):
return self.getNodeByBrowseName("Root")

def createNode(self, xmlelement, nsMapping, hidden=False):
def createNode(self, xmlelement, modelUri, hidden=False):
ndtype = xmlelement.localName.lower()
if ndtype[:2] == "ua":
ndtype = ndtype[2:]
Expand All @@ -174,6 +175,7 @@ def createNode(self, xmlelement, nsMapping, hidden=False):
if node == None:
return None

node.modelUri = modelUri
node.hidden = hidden
return node

Expand Down Expand Up @@ -212,11 +214,29 @@ def addNodeSet(self, xmlfile, hidden=False, typesArray="UA_TYPES"):
raise Exception(self, self.originXML + " contains no or more then 1 nodeset")
nodeset = nodesets[0]


# Extract the modelUri
modelUri = None
try:
modelTag = nodeset.getElementsByTagName("Models")[0].getElementsByTagName("Model")[0]
modelUri = modelTag.attributes["ModelUri"].nodeValue
except:
# Ignore exception and try to use namespace array
modelUri = None


# Create the namespace mapping
orig_namespaces = extractNamespaces(xmlfile) # List of namespaces used in the xml file
if modelUri is None and len(orig_namespaces) > 0:
modelUri = orig_namespaces[0]

if modelUri is None:
raise Exception(self, self.originXML + " does not define the nodeset URI in Models/Model/ModelUri or NamespaceUris array.")


for ns in orig_namespaces:
self.addNamespace(ns)
nsMapping = self.createNamespaceMapping(orig_namespaces)
self.namespaceMapping[modelUri] = self.createNamespaceMapping(orig_namespaces)

# Extract the aliases
for nd in nodeset.childNodes:
Expand All @@ -231,11 +251,11 @@ def addNodeSet(self, xmlfile, hidden=False, typesArray="UA_TYPES"):
for nd in nodeset.childNodes:
if nd.nodeType != nd.ELEMENT_NODE:
continue
node = self.createNode(nd, nsMapping, hidden)
node = self.createNode(nd, modelUri, hidden)
if not node:
continue
node.replaceAliases(self.aliases)
node.replaceNamespaces(nsMapping)
node.replaceNamespaces(self.namespaceMapping[modelUri])
node.typesArray = typesArray

# Add the node the the global dict
Expand Down

0 comments on commit 87e3a9e

Please sign in to comment.