IDL / XSD element with maxOccurs=3, how to access?

2 posts / 0 new
Last post
Offline
Last seen: 10 years 1 month ago
Joined: 10/09/2013
Posts: 4
IDL / XSD element with maxOccurs=3, how to access?

I'm using the Java APIs and have generated code from a supplied IDL.  The XSD defines the message type as a sequence of elements of type "x" having maxOccurs="3" .   How do I parse the indeterminate number of elements in my on_data_available(DataReader reader) method?

 

IDL / XSD

<xs:complexType name="My.XType">
<xs:sequence>
<xs:element name="Y" type="My.YType" maxOccurs="3">
<xs:annotation>
<xs:documentation>maximum of 3 occurencees</xs:documentation>
</xs:annotation>
</xs:element>
</xs:sequence>
</xs:complexType>


<xs:element name="X" type="My.XType">
<xs:annotation>
<xs:documentation>XLocation information</xs:documentation>
</xs:annotation>
</xs:element>

 

 

Code:

// ************************************************************************
// Implementation of the methods described in DataReaderListener interface
// ************************************************************************
public void on_data_available(DataReader reader) {

XTypeDataReader xReader = XTypeDataReader reader;

try
{
xReader.take(
_dataSeq,
_infoSeq,
ResourceLimitsQosPolicy.LENGTH_UNLIMITED,
SampleStateKind.ANY_SAMPLE_STATE,
ViewStateKind.ANY_VIEW_STATE,
InstanceStateKind.ANY_INSTANCE_STATE);

/* We process all the obtained samples for a particular instance */
for (int i = 0; i < _dataSeq.size(); ++i)
{
/* We first check if the sample includes valid data */
SampleInfo info = (SampleInfo)_infoSeq.get(i);
if (info.valid_data)
{
processData((XType)_dataSeq.get(i));
}
}
} catch (RETCODE_NO_DATA noData) {
// No data to process

} finally {
targetReader.return_loan(_dataSeq, _infoSeq);
}
}




/**************************************************************************
* Called for every valid sample received from DDS. */
private void processData(XType instance)
{

double dd = instance.XType.YType.value.double;

# how do I get the values from the other elements of YType (iterate through them?)

}

 

Keywords:
Offline
Last seen: 4 years 3 months ago
Joined: 09/10/2010
Posts: 32

Hello

     You can iterate across a sequence by using its length operation to get the current size of sequence:

for (int i = 0; i < data_seq.length(); ++i)

And you can access the individual members of the sequence by an array notation:

dataSeq[i]

Take a look at the example that is provided on this community site on how to work with Sequences for help.  Also, look at the online html docs for all of the operations you have available when working with sequences.