20:45, EEST
February 21, 2014
I generated VariableTypeNode implementations from a nodeset.xml file. For some custom code (static factory method) which I want to add to the generated class I need to access the namespaceUri (actually the namespaceIndex) of the type definition. This information can be seen in the @TypeDefinitionId() annotation of the class.
Is there any way to access this information in code within that class?
Thanks,
Hans-Uwe
7:40, EEST
April 3, 2012
Hi,
You can use the com.prosysopc.ua.AnnotationUtils.readTypeDefinitionId(Class) static method. It is the same which NodeManagerUaNode.createInstance uses internally, if you use createInstance methods which take Class parameter.
Just in case the factory method you are talking would be used to instantiated the said class (without NodeManagerUaNode.createInstance/NodeBuilder):
The generated nodes should not be instantiated manually, only through createInstance methods or using NodeBuilder class directly (which the createInstance methods do internally). The reason is that usually the type contains other nodes (e.g. Property nodes or in case of Object nodes also InstanceDeclarations); calling just the constructor of the generated node only does create the top level node and nothing else (this is why it is generated as protected). The NodeBuilder looks the type information from the server’s typespace and instantiates all the nodes and creates correct References between them + e.g. the HasTypeDefinition reference which points to the type. In addition the NodeBuilder sets the Attributes of the newly created node and does call the afterCreate method.
– Bjarne
13:04, EEST
February 21, 2014
Hi,
thanks for your solution. This works great.
The static factory method internally uses the NodeBuilder to create the node instances. The factory adds and sets custom non-OPC UA properties of the Variable nodes, as I wanted to avoid public setter methods for those properties. It also automates the configuration of optional properties based on some input parameters (e.g. the presence of an engineering unit string)
Many thanks,
Hans-Uwe
Most Users Ever Online: 1919
Currently Online: mithun
57 Guest(s)
Currently Browsing this Page:
1 Guest(s)
Top Posters:
Heikki Tahvanainen: 402
hbrackel: 144
rocket science: 88
pramanj: 86
Francesco Zambon: 83
Ibrahim: 78
Sabari: 62
kapsl: 57
gjevremovic: 49
Xavier: 43
Member Stats:
Guest Posters: 0
Members: 738
Moderators: 7
Admins: 1
Forum Stats:
Groups: 3
Forums: 15
Topics: 1524
Posts: 6450
Newest Members:
jonathonmcintyre, fannielima, kristiewinkle8, rust, christamcdowall, redaahern07571, nigelbdhmp, travistimmons, AnnelCib, dalenegettingerModerators: Jouni Aro: 1026, Pyry: 1, Petri: 0, Bjarne Boström: 1026, Jimmy Ni: 26, Matti Siponen: 346, Lusetti: 0
Administrators: admin: 1