use of org.apache.cxf.binding.corba.wsdl.Array 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(Integer.parseInt(((CorbaPrimitiveHandler) obj.getElement(i)).getDataFromValue()) == data[i]);
}
}
use of org.apache.cxf.binding.corba.wsdl.Array 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.wsdl.Array in project cxf by apache.
the class CorbaArrayHandlerTest method testArrayHandler.
@Test
public void testArrayHandler() {
objName = new QName("object");
objIdlType = new QName(CorbaConstants.NU_WSDL_CORBA, "arrayType", CorbaConstants.NP_WSDL_CORBA);
objTypeCode = orb.create_array_tc(5, orb.get_primitive_tc(TCKind.tk_long));
Array arrayType = new Array();
arrayType.setName("arrayType");
arrayType.setElemtype(CorbaConstants.NT_CORBA_LONG);
arrayType.setBound(5);
arrayType.setRepositoryID("IDL:ArrayType:1.0");
obj = new CorbaArrayHandler(objName, objIdlType, objTypeCode, arrayType);
assertNotNull(obj);
int[] arrayData = { 2, 4, 6, 8, 10 };
for (int i = 0; i < arrayData.length; ++i) {
QName elName = new QName("item");
QName elIdlType = CorbaConstants.NT_CORBA_LONG;
TypeCode elTC = orb.get_primitive_tc(TCKind.tk_long);
CorbaPrimitiveHandler el = new CorbaPrimitiveHandler(elName, elIdlType, elTC, null);
el.setValue(Integer.valueOf(arrayData[i]));
obj.addElement(el);
}
QName nameResult = obj.getName();
assertNotNull(nameResult);
assertEquals(objName, nameResult);
QName idlTypeResult = obj.getIdlType();
assertNotNull(idlTypeResult);
assertEquals(idlTypeResult, objIdlType);
TypeCode tcResult = obj.getTypeCode();
assertNotNull(tcResult);
assertTrue(tcResult.kind().value() == objTypeCode.kind().value());
Object objDefResult = obj.getType();
assertNotNull(objDefResult);
assertTrue(objDefResult instanceof Array);
int countResult = obj.getNumberOfElements();
for (int i = 0; i < countResult; ++i) {
CorbaObjectHandler elResult = obj.getElement(i);
assertNotNull(elResult);
}
}
use of org.apache.cxf.binding.corba.wsdl.Array in project cxf by apache.
the class WSDLTypes method mapToArray.
public static CorbaType mapToArray(QName name, QName schematypeName, QName arrayType, QName elName, int bound, boolean anonymous) {
final CorbaType corbatype;
if (!anonymous) {
// Create an Array
Array corbaArray = new Array();
corbaArray.setName(name.getLocalPart());
corbaArray.setType(schematypeName);
corbaArray.setElemtype(arrayType);
corbaArray.setElemname(elName);
corbaArray.setBound(bound);
corbaArray.setRepositoryID(WSDLToCorbaHelper.REPO_STRING + name.getLocalPart().replace('.', '/') + WSDLToCorbaHelper.IDL_VERSION);
corbaArray.setQName(name);
corbatype = corbaArray;
} else {
// Create an Anonymous Array
Anonarray corbaArray = new Anonarray();
corbaArray.setName(name.getLocalPart());
corbaArray.setType(schematypeName);
corbaArray.setElemtype(arrayType);
corbaArray.setElemname(elName);
corbaArray.setBound(bound);
corbaArray.setQName(name);
corbatype = corbaArray;
}
return corbatype;
}
use of org.apache.cxf.binding.corba.wsdl.Array in project cxf by apache.
the class WSDLToCorbaBindingTest method assertMixedArraysMappingDifficultArrays.
/**
* @param typeMap
*/
private void assertMixedArraysMappingDifficultArrays(CorbaTypeMap typeMap) {
String corbaTm = "http://schemas.apache.org/idl/anon.idl/corba/typemap/";
// p11 is unwrapped, so the same case as p9
Array p11 = (Array) typeMap.getType("MixedArrayType.p11-anonymous-unwrapped-non-primitive-arrayArray");
assertEquals(new QName("", "p11-anonymous-unwrapped-non-primitive-array"), p11.getElemname());
assertEquals(new QName(corbaTm, "MixedArrayType.p11-anonymous-unwrapped-non-primitive-array"), p11.getElemtype());
assertFalse(p11.isQualified());
assertFalse(p11.isWrapped());
Struct p11item = (Struct) typeMap.getType("MixedArrayType.p11-anonymous-unwrapped-non-primitive-array");
assertEquals(1, p11item.getMember().size());
assertEquals(new QName(CorbaConstants.NU_WSDL_CORBA, "string"), p11item.getMember().get(0).getIdltype());
assertEquals("item", p11item.getMember().get(0).getName());
Array p11q = (Array) typeMap.getType("MixedArrayType.p11-anonymous-unwrapped-non-primitive-array-qArray");
assertEquals(new QName("http://schemas.apache.org/idltypes/anon.idl", "p11-anonymous-unwrapped-non-primitive-array-q"), p11q.getElemname());
assertEquals(new QName(corbaTm, "MixedArrayType.p11-anonymous-unwrapped-non-primitive-array-q"), p11q.getElemtype());
assertTrue(p11q.isQualified());
assertFalse(p11q.isWrapped());
Struct p11qitem = (Struct) typeMap.getType("MixedArrayType.p11-anonymous-unwrapped-non-primitive-array-q");
assertEquals(1, p11qitem.getMember().size());
assertEquals(new QName(CorbaConstants.NU_WSDL_CORBA, "string"), p11qitem.getMember().get(0).getIdltype());
assertEquals("item", p11qitem.getMember().get(0).getName());
// p12 us wrapped - see p10
Anonarray p12 = (Anonarray) typeMap.getType("MixedArrayType.p12-anonymous-wrapped-non-primitive-arrayType");
assertEquals(new QName("", "item"), p12.getElemname());
assertEquals(new QName(corbaTm, "MixedArrayType.p12-anonymous-wrapped-non-primitive-array.item"), p12.getElemtype());
assertFalse(p12.isQualified());
assertTrue(p12.isWrapped());
Struct p12item = (Struct) typeMap.getType("MixedArrayType.p12-anonymous-wrapped-non-primitive-array.item");
assertEquals(p12item.getMember().size(), 1);
assertEquals(new QName(CorbaConstants.NU_WSDL_CORBA, "string"), p12item.getMember().get(0).getIdltype());
assertEquals("item", p12item.getMember().get(0).getName());
assertFalse(p12item.getMember().get(0).isSetQualified());
Anonarray p12q = (Anonarray) typeMap.getType("MixedArrayType.p12-anonymous-wrapped-non-primitive-array-qType");
assertEquals(new QName("http://schemas.apache.org/idltypes/anon.idl", "item"), p12q.getElemname());
assertEquals(new QName(corbaTm, "MixedArrayType.p12-anonymous-wrapped-non-primitive-array-q.item"), p12q.getElemtype());
assertTrue(p12q.isQualified());
assertTrue(p12q.isWrapped());
Struct p12qitem = (Struct) typeMap.getType("MixedArrayType.p12-anonymous-wrapped-non-primitive-array-q.item");
assertEquals(p12qitem.getMember().size(), 1);
assertEquals(new QName(CorbaConstants.NU_WSDL_CORBA, "string"), p12qitem.getMember().get(0).getIdltype());
assertEquals("item", p12qitem.getMember().get(0).getName());
assertTrue(p12qitem.getMember().get(0).isQualified());
}
Aggregations