use of org.omg.CORBA.TypeCode in project cxf by apache.
the class CorbaUtils method getComplexTypeCode.
public static TypeCode getComplexTypeCode(ORB orb, QName type, Object obj, CorbaTypeMap typeMap, Stack<QName> seenTypes) {
TypeCode tc = getAnonTypeCode(orb, type, obj, typeMap, seenTypes);
if (tc == null) {
if (obj instanceof Alias) {
Alias aliasType = (Alias) obj;
tc = orb.create_alias_tc(aliasType.getRepositoryID(), getTypeCodeName(aliasType.getName()), getTypeCode(orb, aliasType.getBasetype(), typeMap, seenTypes));
} else if (obj instanceof Array) {
Array arrayType = (Array) obj;
tc = orb.create_array_tc((int) arrayType.getBound(), getTypeCode(orb, arrayType.getElemtype(), typeMap, seenTypes));
} else if (obj instanceof Enum) {
Enum enumType = (Enum) obj;
String name = enumType.getName();
List<Enumerator> enums = enumType.getEnumerator();
String[] members = new String[enums.size()];
for (int i = 0; i < members.length; ++i) {
members[i] = enums.get(i).getValue();
}
name = getTypeCodeName(name);
tc = orb.create_enum_tc(enumType.getRepositoryID(), name, members);
} else if (obj instanceof Exception) {
Exception exceptType = (Exception) obj;
List<MemberType> list = exceptType.getMember();
StructMember[] members = new StructMember[list.size()];
for (int i = 0; i < members.length; ++i) {
MemberType member = list.get(i);
members[i] = new StructMember(member.getName(), getTypeCode(orb, member.getIdltype(), typeMap, seenTypes), null);
}
String name = getTypeCodeName(exceptType.getName());
tc = orb.create_exception_tc(exceptType.getRepositoryID(), name, members);
} else if (obj instanceof Fixed) {
Fixed fixedType = (Fixed) obj;
tc = orb.create_fixed_tc((short) fixedType.getDigits(), (short) fixedType.getScale());
} else if (obj instanceof org.apache.cxf.binding.corba.wsdl.Object) {
org.apache.cxf.binding.corba.wsdl.Object objType = (org.apache.cxf.binding.corba.wsdl.Object) obj;
if ("CORBA.Object".equals(objType.getName())) {
tc = orb.create_interface_tc(objType.getRepositoryID(), "Object");
} else {
tc = orb.create_interface_tc(objType.getRepositoryID(), getTypeCodeName(objType.getName()));
}
} else if (obj instanceof Sequence) {
Sequence seqType = (Sequence) obj;
tc = orb.create_sequence_tc((int) seqType.getBound(), getTypeCode(orb, seqType.getElemtype(), typeMap, seenTypes));
} else if (obj instanceof Struct) {
Struct structType = (Struct) obj;
if (seenTypes.contains(new QName(structType.getName()))) {
tc = orb.create_recursive_tc(structType.getRepositoryID());
} else {
seenTypes.push(new QName(structType.getName()));
List<MemberType> list = structType.getMember();
StructMember[] members = new StructMember[list.size()];
for (int i = 0; i < members.length; ++i) {
MemberType member = list.get(i);
members[i] = new StructMember(member.getName(), getTypeCode(orb, member.getIdltype(), typeMap, seenTypes), null);
}
String name = getTypeCodeName(structType.getName());
tc = orb.create_struct_tc(structType.getRepositoryID(), name, members);
seenTypes.pop();
}
} else if (obj instanceof Union) {
tc = getUnionTypeCode(orb, obj, typeMap, seenTypes);
}
}
return tc;
}
use of org.omg.CORBA.TypeCode in project cxf by apache.
the class CorbaServerConduitTest method testBuildRequestResultArgumentReturn.
@Test
public void testBuildRequestResultArgumentReturn() {
CorbaStreamable[] arguments = new CorbaStreamable[1];
QName objName = new QName("object");
QName objIdlType = new QName(CorbaConstants.NU_WSDL_CORBA, "short", CorbaConstants.NP_WSDL_CORBA);
TypeCode objTypeCode = orb.get_primitive_tc(TCKind.tk_short);
CorbaPrimitiveHandler obj = new CorbaPrimitiveHandler(objName, objIdlType, objTypeCode, null);
CorbaStreamable arg = new CorbaStreamableImpl(obj, objName);
arguments[0] = arg;
arguments[0].setMode(org.omg.CORBA.ARG_OUT.value);
NVList nvlist = orb.create_list(2);
Any value = orb.create_any();
value.insert_Streamable(arguments[0]);
nvlist.add_value(arguments[0].getName(), value, arguments[0].getMode());
CorbaServerConduit conduit = setupCorbaServerConduit(false);
CorbaMessage msg = control.createMock(CorbaMessage.class);
Exchange exchange = control.createMock(Exchange.class);
ServerRequest request = control.createMock(ServerRequest.class);
EasyMock.expect(exchange.getBus()).andReturn(bus);
EasyMock.expect(msg.getExchange()).andReturn(exchange);
EasyMock.expect(exchange.get(ServerRequest.class)).andReturn(request);
EasyMock.expect(exchange.isOneWay()).andReturn(false);
EasyMock.expect(msg.getExchange()).andReturn(exchange);
Message message = new MessageImpl();
CorbaMessage corbaMessage = new CorbaMessage(message);
corbaMessage.setList(nvlist);
EasyMock.expect(exchange.getInMessage()).andReturn(corbaMessage);
EasyMock.expect(msg.getStreamableException()).andReturn(null);
EasyMock.expect(msg.getStreamableArguments()).andReturn(arguments);
EasyMock.expect(msg.getStreamableReturn()).andReturn(arg);
control.replay();
conduit.buildRequestResult(msg);
control.verify();
}
use of org.omg.CORBA.TypeCode in project cxf by apache.
the class CorbaObjectReaderTest method testReadFixed.
@Test
public void testReadFixed() {
if (System.getProperty("java.vendor").contains("IBM")) {
// to the stream.
return;
}
OutputStream oStream = orb.create_output_stream();
// create the following fixed
// fixed<5,2>
oStream.write_fixed(new java.math.BigDecimal("12345.67").movePointRight(2));
InputStream iStream = oStream.create_input_stream();
CorbaObjectReader reader = new CorbaObjectReader(iStream);
Fixed fixedType = new Fixed();
fixedType.setDigits(5);
fixedType.setScale(2);
// These values don't matter to the outcome of the test but are needed during construction
QName fixedName = new QName("TestFixed");
QName fixedIdlType = new QName("corbatm:TestFixed");
TypeCode fixedTC = orb.create_fixed_tc((short) fixedType.getDigits(), (short) fixedType.getScale());
CorbaFixedHandler obj = new CorbaFixedHandler(fixedName, fixedIdlType, fixedTC, fixedType);
reader.readFixed(obj);
assertEquals(obj.getValue(), new java.math.BigDecimal("12345.67"));
}
use of org.omg.CORBA.TypeCode 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) {
assertEquals(((CorbaPrimitiveHandler) obj.getElement(i)).getDataFromValue(), data[i]);
}
}
use of org.omg.CORBA.TypeCode in project cxf by apache.
the class CorbaObjectReaderTest method testReadEnum.
@Test
public void testReadEnum() {
OutputStream oStream = orb.create_output_stream();
// create the following enum
// enum { RED, GREEN, BLUE };
oStream.write_long(1);
InputStream iStream = oStream.create_input_stream();
CorbaObjectReader reader = new CorbaObjectReader(iStream);
String[] enums = { "RED", "GREEN", "BLUE" };
Enum enumType = new Enum();
Enumerator enumRed = new Enumerator();
enumRed.setValue(enums[0]);
Enumerator enumGreen = new Enumerator();
enumGreen.setValue(enums[1]);
Enumerator enumBlue = new Enumerator();
enumBlue.setValue(enums[2]);
enumType.getEnumerator().add(enumRed);
enumType.getEnumerator().add(enumGreen);
enumType.getEnumerator().add(enumBlue);
// These values don't matter to the outcome of the test but are needed during construction
QName enumName = new QName("TestEnum");
QName enumIdlType = new QName("corbatm:TestEnum");
TypeCode enumTC = orb.create_enum_tc("IDL:TestEnum:1.0", enumName.getLocalPart(), enums);
CorbaEnumHandler obj = new CorbaEnumHandler(enumName, enumIdlType, enumTC, enumType);
reader.readEnum(obj);
assertEquals(obj.getValue(), enums[1]);
}
Aggregations