Please consider registering

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
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
Bjarne Boström
Forum Posts: 684
Member Since:
April 3, 2012
sp_UserOfflineSmall Offline


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
Forum Posts: 6
Member Since:
June 4, 2015
sp_UserOfflineSmall Offline


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: 267

Currently Online:
19 Guest(s)

Currently Browsing this Page:
1 Guest(s)

Top Posters:

hbrackel: 111

pramanj: 86

ibrahim: 74

kapsl: 57

gjevremovic: 49

TimK: 41

fred: 41

Xavier: 40

Fransua33: 39

rocket science: 36

Member Stats:

Guest Posters: 0

Members: 1458

Moderators: 17

Admins: 1

Forum Stats:

Groups: 3

Forums: 15

Topics: 1178

Posts: 4983

Newest Members:

ThomasM, louiecrews, wyattcutler005, kristin3354, augustawalpole3, everettpulver, arron51869, roseannagoldschm, moosm, islamaddox

Moderators: Jouni Aro: 906, Otso Palonen: 32, Tuomas Hiltunen: 5, janimakela: 0, Pyry: 1, Terho: 0, Petri: 0, Bjarne Boström: 684, Heikki Tahvanainen: 402, Jukka Asikainen: 1, moldzh08: 0, Jimmy Ni: 24, Teppo Uimonen: 21, Markus Johansson: 36, Niklas Nurminen: 0, Matti Siponen: 151, Lusetti: 0

Administrators: admin: 1