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
Setting PlainVariable value: IllegalArgumentException
June 4, 2015
9:57, EEST
Avatar
danko
Member
Members
Forum Posts: 6
Member Since:
June 4, 2015
sp_UserOfflineSmall Offline

Hi everyone,

I’m experiencing problems when setting the value of a PlainVariable. Can’t a PlainVariable handle any type of content?

PlainVariable myVariable = new PlainVariable (nodeManager, myVarId, "my variable", Locale.ENGLISH);
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?

June 4, 2015
11:57, EEST
Avatar
Bjarne Boström
Moderator
Moderators
Forum Posts: 983
Member Since:
April 3, 2012
sp_UserOfflineSmall Offline

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

June 5, 2015
13:02, EEST
Avatar
danko
Member
Members
Forum Posts: 6
Member Since:
June 4, 2015
sp_UserOfflineSmall Offline

Hi,

thanks for the clear reply! This shines a little light into variables.
I’ll have a look at code generation next. : )

Forum Timezone: Europe/Helsinki

Most Users Ever Online: 518

Currently Online:
26 Guest(s)

Currently Browsing this Page:
1 Guest(s)

Top Posters:

hbrackel: 135

pramanj: 86

Francesco Zambon: 81

rocket science: 77

ibrahim: 75

Sabari: 62

kapsl: 57

gjevremovic: 49

Xavier: 43

fred: 41

Member Stats:

Guest Posters: 0

Members: 680

Moderators: 16

Admins: 1

Forum Stats:

Groups: 3

Forums: 15

Topics: 1467

Posts: 6259

Newest Members:

sagarchau, elviralangwell4, Donnavek, Eddiefauth, DonaldPooma, fidelduke938316, Jan-Pfizer, DavidROunc, fen.pang@woodside.com, aytule

Moderators: Jouni Aro: 1009, Otso Palonen: 32, Tuomas Hiltunen: 5, Pyry: 1, Petri: 0, Bjarne Boström: 983, Heikki Tahvanainen: 402, Jukka Asikainen: 1, moldzh08: 0, Jimmy Ni: 26, Teppo Uimonen: 21, Markus Johansson: 42, Niklas Nurminen: 0, Matti Siponen: 321, Lusetti: 0, Ari-Pekka Soikkeli: 5

Administrators: admin: 1