TK_UNION of structures Java. How to change discriminator

2 posts / 0 new
Last post
Offline
Last seen: 7 years 2 months ago
Joined: 11/08/2014
Posts: 19
TK_UNION of structures Java. How to change discriminator

Hi

I've got a set of IDLs which I use to create a dynamic data tree in Java which I can then edit and publish the various topics.  This has been working well for years until someone decided that unions of structures would be a good idea.  I used the examples for unions of simple types as a basis for changing the discriminator (there appear to be no examples of complex types) and my code looks like this... 

discriminatorType = dynamicDataInstance.get_type().discriminator_type();

//get_member_info_by_index_crashes
dynamicDataInstance.get_member_info(thisInfo, null, 0);


discriminatorVal=thisInfo.member_id;

memberCount = dynamicDataInstance.get_type().member_count();

TypeCode newType = dynamicDataInstance.get_type().member_type(memberCount-1);


DynamicData unionMember = new DynamicData(newType, DynamicData.PROPERTY_DEFAULT);


dynamicDataInstance.set_complex_member("aName", DynamicData.MEMBER_ID_UNSPECIFIED,unionMember);

 

It all makes sense until I try to create a new union member at which point it crashes...

 

 

Exception in thread "AWT-EventQueue-0" com.rti.dds.infrastructure.RETCODE_ERROR
at com.rti.dds.dynamicdata.DynamicData.create_native_dynamic_data(Unknown Source)
at com.rti.dds.dynamicdata.DynamicData.<init>(Unknown Source)

 

 

Obviously I've tried many combinations of this as well as trying to directly change the discriminator but with similar issues.  Can someone point me in the right direction please.

 

Thanks

 

John

 

Organization:
Offline
Last seen: 7 years 2 months ago
Joined: 11/08/2014
Posts: 19

I've come a long way since I asked this question and I'm managing to manipulate unions fairly succesfully.  If anyone wants an answer to related union questions I'll be happy to answer. I'm about to raise another question which I think justifies another post.