use of org.apache.cxf.binding.corba.types.CorbaArrayHandler in project cxf by apache.
the class CorbaObjectReaderTest method testReadArray.
// need to add tests for arrays, sequences, struct, exceptions
@Test
public void testReadArray() {
int[] data = { 1, 1, 2, 3, 5, 8, 13, 21 };
OutputStream oStream = orb.create_output_stream();
oStream.write_long_array(data, 0, data.length);
InputStream iStream = oStream.create_input_stream();
CorbaObjectReader reader = new CorbaObjectReader(iStream);
// create an array of longs
QName longIdlType = new QName(CorbaConstants.NU_WSDL_CORBA, "long", CorbaConstants.NP_WSDL_CORBA);
QName arrayIdlType = new QName(CorbaConstants.NU_WSDL_CORBA, "array", CorbaConstants.NP_WSDL_CORBA);
Array arrayType = new Array();
arrayType.setBound(data.length);
arrayType.setElemtype(longIdlType);
// name and respoitory ID of the array are not needed for this test
// build the object holder for an array.
TypeCode arrayTC = orb.create_array_tc(data.length, orb.get_primitive_tc(TCKind.tk_long));
CorbaArrayHandler obj = new CorbaArrayHandler(new QName("Array"), arrayIdlType, arrayTC, arrayType);
for (int i = 0; i < data.length; ++i) {
CorbaObjectHandler nestedObj = new CorbaPrimitiveHandler(new QName("item"), longIdlType, orb.get_primitive_tc(TCKind.tk_long), null);
obj.addElement(nestedObj);
}
reader.readArray(obj);
int length = obj.getElements().size();
for (int i = 0; i < length; ++i) {
assertTrue(new Long(((CorbaPrimitiveHandler) obj.getElement(i)).getDataFromValue()).intValue() == data[i]);
}
}
use of org.apache.cxf.binding.corba.types.CorbaArrayHandler in project cxf by apache.
the class CorbaObjectWriterTest method testWriteArray.
@Test
public void testWriteArray() {
int[] data = { 1, 1, 2, 3, 5, 8, 13, 21 };
// create an array of longs
QName longIdlType = new QName(CorbaConstants.NU_WSDL_CORBA, "long", CorbaConstants.NP_WSDL_CORBA);
QName arrayIdlType = new QName(CorbaConstants.NU_WSDL_CORBA, "array", CorbaConstants.NP_WSDL_CORBA);
Array arrayType = new Array();
arrayType.setBound(data.length);
arrayType.setElemtype(longIdlType);
// name and respoitory ID of the array are not needed for this test
// build the object holder for an array.
TypeCode arrayTC = orb.create_array_tc(data.length, orb.get_primitive_tc(TCKind.tk_long));
CorbaArrayHandler obj = new CorbaArrayHandler(new QName("Array"), arrayIdlType, arrayTC, arrayType);
for (int i = 0; i < data.length; ++i) {
CorbaPrimitiveHandler nestedObj = new CorbaPrimitiveHandler(new QName("item"), longIdlType, orb.get_primitive_tc(TCKind.tk_long), null);
nestedObj.setValueFromData(Integer.toString(data[i]));
obj.addElement(nestedObj);
}
OutputStream oStream = orb.create_output_stream();
CorbaObjectWriter writer = new CorbaObjectWriter(oStream);
writer.writeArray(obj);
InputStream iStream = oStream.create_input_stream();
for (int i = 0; i < data.length; ++i) {
int val = iStream.read_long();
assertTrue(val == data[i]);
}
}
use of org.apache.cxf.binding.corba.types.CorbaArrayHandler 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;
}
Aggregations