use of org.apache.cxf.binding.corba.types.CorbaSequenceHandler in project cxf by apache.
the class CorbaObjectWriterTest method testWriteSequence.
@Test
public void testWriteSequence() {
String[] data = { "one", "one", "two", "three", "five", "eight", "thirteen", "twenty-one" };
// create an sequence of strings
QName stringIdlType = new QName(CorbaConstants.NU_WSDL_CORBA, "string", CorbaConstants.NP_WSDL_CORBA);
QName seqIdlType = new QName(CorbaConstants.NU_WSDL_CORBA, "sequence", CorbaConstants.NP_WSDL_CORBA);
Sequence seqType = new Sequence();
seqType.setBound(data.length);
seqType.setElemtype(stringIdlType);
// name and respoitory ID of the sequence are not needed for this test
// build the object holder for a sequence.
TypeCode seqTC = orb.create_sequence_tc(data.length, orb.get_primitive_tc(TCKind.tk_string));
CorbaSequenceHandler obj = new CorbaSequenceHandler(new QName("Seq"), seqIdlType, seqTC, seqType);
for (int i = 0; i < data.length; ++i) {
CorbaPrimitiveHandler nestedObj = new CorbaPrimitiveHandler(new QName("item"), stringIdlType, orb.get_primitive_tc(TCKind.tk_string), null);
nestedObj.setValueFromData(data[i]);
obj.addElement(nestedObj);
}
OutputStream oStream = orb.create_output_stream();
CorbaObjectWriter writer = new CorbaObjectWriter(oStream);
writer.writeSequence(obj);
InputStream iStream = oStream.create_input_stream();
int length = iStream.read_long();
for (int i = 0; i < length; ++i) {
String val = iStream.read_string();
assertTrue(val.equals(data[i]));
}
}
use of org.apache.cxf.binding.corba.types.CorbaSequenceHandler in project cxf by apache.
the class CorbaObjectReader method readSequence.
// CHECKSTYLE:ON
public void readSequence(CorbaObjectHandler obj) throws CorbaBindingException {
if (obj instanceof CorbaOctetSequenceHandler) {
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<>(length);
// 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));
}
}
}
use of org.apache.cxf.binding.corba.types.CorbaSequenceHandler in project cxf by apache.
the class CorbaObjectReader method initializeCorbaObjectHandler.
private CorbaObjectHandler initializeCorbaObjectHandler(CorbaObjectHandler template) {
Constructor<?> templateConstructor = template.getClass().getDeclaredConstructors()[0];
Object[] params = new Object[4];
// of a sequence and needs to have the name "item" in order
if (template.isRecursive()) {
// Revisit: Is this always the case?
params[0] = new QName("item");
} else {
params[0] = template.getName();
}
params[1] = template.getIdlType();
params[2] = template.getTypeCode();
params[3] = template.getType();
CorbaObjectHandler handler = null;
try {
handler = (CorbaObjectHandler) templateConstructor.newInstance(params);
// the template object.
if (template instanceof CorbaAnyHandler) {
((CorbaAnyHandler) handler).setTypeMap(((CorbaAnyHandler) template).getTypeMap());
}
} catch (java.lang.Exception ex) {
throw new CorbaBindingException("Unable to instantiate sequence element", ex);
}
if (template instanceof CorbaSequenceHandler) {
CorbaSequenceHandler templateSeq = (CorbaSequenceHandler) template;
((CorbaSequenceHandler) handler).setTemplateElement(templateSeq.getTemplateElement());
} else if (template instanceof CorbaStructHandler) {
CorbaStructHandler templateStruct = (CorbaStructHandler) template;
CorbaStructHandler struct = (CorbaStructHandler) handler;
struct.setRecursive(template.isRecursive());
List<CorbaObjectHandler> members = templateStruct.getMembers();
for (int i = 0; i < members.size(); i++) {
CorbaObjectHandler member = initializeCorbaObjectHandler(members.get(i));
struct.addMember(member);
}
} else if (template instanceof CorbaArrayHandler) {
CorbaArrayHandler templateArray = (CorbaArrayHandler) template;
CorbaArrayHandler array = (CorbaArrayHandler) handler;
List<CorbaObjectHandler> elements = templateArray.getElements();
for (int i = 0; i < elements.size(); i++) {
CorbaObjectHandler element = initializeCorbaObjectHandler(elements.get(i));
array.addElement(element);
}
} else if (template instanceof CorbaUnionHandler) {
CorbaUnionHandler templateUnion = (CorbaUnionHandler) template;
CorbaUnionHandler union = (CorbaUnionHandler) handler;
union.setRecursive(template.isRecursive());
union.setDiscriminator(initializeCorbaObjectHandler(templateUnion.getDiscriminator()));
List<CorbaObjectHandler> cases = templateUnion.getCases();
for (int i = 0; i < cases.size(); i++) {
union.addCase(initializeCorbaObjectHandler(cases.get(i)));
}
}
return handler;
}
use of org.apache.cxf.binding.corba.types.CorbaSequenceHandler in project cxf by apache.
the class CorbaObjectWriter method writeSequence.
public void writeSequence(CorbaObjectHandler obj) throws CorbaBindingException {
if (obj instanceof CorbaOctetSequenceHandler) {
byte[] value = ((CorbaOctetSequenceHandler) obj).getValue();
stream.write_ulong(value.length);
stream.write_octet_array(value, 0, value.length);
} else {
CorbaSequenceHandler seqHandler = (CorbaSequenceHandler) obj;
List<CorbaObjectHandler> seqElements = seqHandler.getElements();
int length = seqElements.size();
stream.write_ulong(length);
for (int i = 0; i < length; ++i) {
this.write(seqElements.get(i));
}
}
}
use of org.apache.cxf.binding.corba.types.CorbaSequenceHandler in project cxf by apache.
the class CorbaObjectReaderTest method testReadSequence.
@Test
public void testReadSequence() {
String[] data = { "one", "one", "two", "three", "five", "eight", "thirteen", "twenty-one" };
OutputStream oStream = orb.create_output_stream();
oStream.write_long(data.length);
for (int i = 0; i < data.length; ++i) {
oStream.write_string(data[i]);
}
InputStream iStream = oStream.create_input_stream();
CorbaObjectReader reader = new CorbaObjectReader(iStream);
// create an sequence of strings
QName stringIdlType = new QName(CorbaConstants.NU_WSDL_CORBA, "string", CorbaConstants.NP_WSDL_CORBA);
QName seqIdlType = new QName(CorbaConstants.NU_WSDL_CORBA, "sequence", CorbaConstants.NP_WSDL_CORBA);
Sequence seqType = new Sequence();
seqType.setBound(data.length);
seqType.setElemtype(stringIdlType);
// name and respoitory ID of the sequence are not needed for this test
// build the object holder for a sequence.
TypeCode seqTC = orb.create_sequence_tc(data.length, orb.get_primitive_tc(TCKind.tk_string));
CorbaSequenceHandler obj = new CorbaSequenceHandler(new QName("Seq"), seqIdlType, seqTC, seqType);
for (int i = 0; i < data.length; ++i) {
CorbaPrimitiveHandler nestedObj = new CorbaPrimitiveHandler(new QName("item"), stringIdlType, orb.get_primitive_tc(TCKind.tk_string), null);
obj.addElement(nestedObj);
}
reader.readSequence(obj);
int length = obj.getElements().size();
for (int i = 0; i < length; ++i) {
assertTrue(((CorbaPrimitiveHandler) obj.getElement(i)).getDataFromValue().equals(data[i]));
}
}
Aggregations