OpenSplice Java 5 DCPS  v6.x
OpenSplice Java 5 OpenSplice Data Distribution Service Data-Centric Publish-Subscribe API
IteratorProtobuf.java
Go to the documentation of this file.
1 /*
2  * Vortex OpenSplice
3  *
4  * This software and documentation are Copyright 2006 to 2024 ADLINK
5  * Technology Limited, its affiliated companies and licensors. All rights
6  * reserved.
7  *
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  * http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  *
20  */
21 package org.opensplice.dds.sub;
22 
23 import java.lang.reflect.Field;
24 import java.util.ArrayList;
25 
26 import org.omg.dds.sub.Sample;
31 
32 import DDS.SampleInfoSeqHolder;
33 
34 public class IteratorProtobuf<PROTOBUF_TYPE, DDS_TYPE> extends
35  AbstractIterator<PROTOBUF_TYPE> implements
36  Sample.Iterator<PROTOBUF_TYPE> {
37  private ArrayList<PROTOBUF_TYPE> data;
38 
41  Object sampleSeqHolder, Field dataSeqHolderValue,
42  SampleInfoSeqHolder infoSeqHolder) {
43  super(environment, reader, sampleSeqHolder, dataSeqHolderValue,
44  infoSeqHolder);
45  }
46 
47  @SuppressWarnings("unchecked")
48  @Override
50  try {
52  DDS_TYPE[] ddsData;
53 
55  .getTopicDescription().getTypeSupport();
56  ddsData = (DDS_TYPE[]) dataSeqHolderValue.get(sampleSeqHolder);
57 
58  this.data = new ArrayList<PROTOBUF_TYPE>(ddsData.length);
59 
60  for (int i = 0; i < ddsData.length; i++) {
61  if (this.infoSeqHolder.value[i].valid_data) {
62  this.data.add(typeSupport.ddsToProtobuf(ddsData[i]));
63  } else {
64  this.data.add(typeSupport.ddsKeyToProtobuf(ddsData[i]));
65  }
66  }
67  } catch (SecurityException e) {
69  "Not allowed to access field "
70  + dataSeqHolderValue.getName() + " in "
71  + dataSeqHolderValue.getClass().getName() + "("
72  + e.getMessage() + ").");
73  } catch (IllegalArgumentException e) {
74  throw new DDSExceptionImpl(environment, "Cannot find "
75  + dataSeqHolderValue.getName() + " in "
76  + dataSeqHolderValue.getClass().getName() + "("
77  + e.getMessage() + ").");
78  } catch (IllegalAccessException e) {
79  throw new DDSExceptionImpl(environment, "No access to field "
80  + dataSeqHolderValue.getName() + " in "
81  + dataSeqHolderValue.getClass().getName() + "("
82  + e.getMessage() + ").");
83  }
84  return new SampleImpl[this.data.size()];
85  }
86 
87  @Override
88  protected PROTOBUF_TYPE getData(int index) {
89  return this.data.get(index);
90  }
91 }
A Sample represents an atom of data information (i.e., one value for one instance) as returned by a o...
Definition: Sample.java:116
IteratorProtobuf(OsplServiceEnvironment environment, DataReaderProtobuf< PROTOBUF_TYPE, DDS_TYPE > reader, Object sampleSeqHolder, Field dataSeqHolderValue, SampleInfoSeqHolder infoSeqHolder)
abstract PROTOBUF_TYPE ddsToProtobuf(DDS_TYPE ddsData)
abstract PROTOBUF_TYPE ddsKeyToProtobuf(DDS_TYPE ddsData)
SampleImpl< PROTOBUF_TYPE > [] setupSampleList()