9:57, EEST
June 4, 2015
Hi everyone,
I’m experiencing problems when setting the value of a PlainVariable. Can’t a PlainVariable handle any type of content?
myVariable.setCurrentValue(new MyOwnTestClass());
The trace tells me com.prosysopc.ua.server.nodes.PlainVariable.setCurrentValue throws an IllegalArgumentException because “Variant cannot be MyOwnTestClass”. I actually chose PlainVariable in order to store custom objects. Is there a way to do this?
On a related note, why does a PlainVariable still have its DataType set to BaseDataType? It only becomes String if I manually setDataTypeId(Identifiers.String). What exactly does the Type in PlainVariable type anyway?
11:57, EEST
April 3, 2012
Hi,
PlainVariable shoud be able to handle any UA content, but not “any”. In practice this is anything that a Variant accepts. This can be byte[], basic numeric java types (+ UnsignedXXX ones), DateTime, UUID, XmlElement, NodeId, ExpandedNodeId, StatusCode, QualifiedName, LocalizedText, ExtensionObject, DataValue, (Variant only when in array), or a Structure or Enumeration or (multidimensional)array of these. The generics parameter of a PlainVariable should be one of these (your code seems to use it as raw type, which is not intended).
Custom types are usually Structures. Currently the best option to create these is to use the codegen in the SDK to create java classes from a NodeSet-style xml, which can be created either by hand or UaModeler. For a sample NodeSet file look at the codegen folder in the SDK package (SampleTypes.xml). You can also create same kind of java code by hand without the codegeneration, but it’s not the easiest to do at the moment, because you would then need to create serializers for it manually. In practice all data transfered by UA is in binary at some point, therefore we need to know how to encode and decode it (unless we would handle it as raw binary all the time, but that is not very practical).
BaseDataType is the default because its the equivalent of java’s Object, and we do not know the UA DataType when we construct the object. Also the type hierarchies in UA can be different than java’s, and for some UA types the binary representation of 2 types could be the same Java type. Therefore the UA datatype must be a separate field, and cannot be easily determined from a java object (also because type erasure in generics, obtaining the genericsparameter is tricky)
– Bjarne
Most Users Ever Online: 1919
Currently Online:
10 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: 6451
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