Avatar

Please consider registering
guest

sp_LogInOut Log In sp_Registration Register

Register | Lost password?
Advanced Search

— Forum Scope —




— Match —





— Forum Options —





Minimum search word length is 3 characters - maximum search word length is 84 characters

sp_Feed Topic RSS sp_TopicIcon
Access to namespaceUri of generated VariableTypeNode implementations from within the generated class
September 3, 2015
20:45, EEST
Avatar
hbrackel
Member
Members
Forum Posts: 144
Member Since:
February 21, 2014
sp_UserOfflineSmall Offline

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

September 4, 2015
7:40, EEST
Avatar
Bjarne Boström
Moderator
Moderators
Forum Posts: 1032
Member Since:
April 3, 2012
sp_UserOfflineSmall Offline

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

September 4, 2015
13:04, EEST
Avatar
hbrackel
Member
Members
Forum Posts: 144
Member Since:
February 21, 2014
sp_UserOfflineSmall Offline

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

Forum Timezone: Europe/Helsinki

Most Users Ever Online: 1919

Currently Online:
16 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: 731

Moderators: 7

Admins: 1

Forum Stats:

Groups: 3

Forums: 15

Topics: 1529

Posts: 6471

Newest Members:

inilarythikibia, rickykennion, PromotionToold, HypromeImpupe, toneylapham544, rondawolinski7, Marypof5711, roycedelargie91, kourtneyquisenbe, ellis87832073466

Moderators: Jouni Aro: 1026, Pyry: 1, Petri: 0, Bjarne Boström: 1032, Jimmy Ni: 26, Matti Siponen: 349, Lusetti: 0

Administrators: admin: 1