int length = stream.read_ulong();
byte[] value = new byte[length];
stream.read_octet_array(value, 0, length);
((CorbaOctetSequenceHandler) obj).setValue(value);
} else {
CorbaSequenceHandler sequenceObj = (CorbaSequenceHandler)obj;
List<CorbaObjectHandler> seqElements = sequenceObj.getElements();
int length = stream.read_ulong();
List<CorbaObjectHandler> elements = new ArrayList<CorbaObjectHandler>(length);
// Simply checking the bound won't handle our recursive types. We need to check for the
// existance of template, which will be present for all unbounded sequences and for bound
// sequences with recursive type elements. Use the template element to construct each
// object that is in the input stream.
if (sequenceObj.getTemplateElement() != null) {
sequenceObj.clear();
CorbaObjectHandler template = sequenceObj.getTemplateElement();
for (int i = 0; i < length; ++i) {
CorbaObjectHandler seqElement;
if (i < seqElements.size()) {
seqElement = seqElements.get(i);
} else {
seqElement = initializeCorbaObjectHandler(template);
}
read(seqElement);
elements.add(seqElement);
}
sequenceObj.setElements(elements);
} else {
// We have a bounded sequence and the object should already be pre-built
for (int i = 0; i < length; ++i) {
read(seqElements.get(i));
}
sequenceObj.setElements(seqElements.subList(0, length));
}
}
}