use of org.omg.CORBA.TypeCode in project cxf by apache.
the class CorbaConduit method getOperationExceptions.
public Map<TypeCode, RaisesType> getOperationExceptions(OperationType operation, CorbaTypeMap map) {
if (orb == null) {
prepareOrb();
}
Map<TypeCode, RaisesType> exceptions = new HashMap<>();
List<RaisesType> exList = operation.getRaises();
if (exList != null) {
for (int i = 0; i < exList.size(); ++i) {
RaisesType ex = exList.get(i);
TypeCode tc = CorbaUtils.getTypeCode(orb, ex.getException(), map);
exceptions.put(tc, ex);
}
}
return exceptions;
}
use of org.omg.CORBA.TypeCode in project cxf by apache.
the class CorbaMessageTest method testGetCorbaMessageAttributes.
@Test
public void testGetCorbaMessageAttributes() {
CorbaMessage msg = new CorbaMessage(message);
QName param1Name = new QName("param1");
QName param1IdlType = new QName(CorbaConstants.NU_WSDL_CORBA, "long", CorbaConstants.NP_WSDL_CORBA);
TypeCode param1TypeCode = orb.get_primitive_tc(TCKind.tk_long);
CorbaPrimitiveHandler param1 = new CorbaPrimitiveHandler(param1Name, param1IdlType, param1TypeCode, null);
CorbaStreamable p1 = msg.createStreamableObject(param1, param1Name);
QName param2Name = new QName("param2");
QName param2IdlType = new QName(CorbaConstants.NU_WSDL_CORBA, "string", CorbaConstants.NP_WSDL_CORBA);
TypeCode param2TypeCode = orb.get_primitive_tc(TCKind.tk_string);
CorbaPrimitiveHandler param2 = new CorbaPrimitiveHandler(param2Name, param2IdlType, param2TypeCode, null);
CorbaStreamable p2 = msg.createStreamableObject(param2, param2Name);
msg.addStreamableArgument(p1);
msg.addStreamableArgument(p2);
CorbaStreamable[] arguments = msg.getStreamableArguments();
assertTrue(arguments.length == 2);
assertNotNull(arguments[0]);
assertNotNull(arguments[1]);
QName param3Name = new QName("param3");
QName param3IdlType = new QName(CorbaConstants.NU_WSDL_CORBA, "short", CorbaConstants.NP_WSDL_CORBA);
TypeCode param3TypeCode = orb.get_primitive_tc(TCKind.tk_short);
CorbaPrimitiveHandler param3 = new CorbaPrimitiveHandler(param3Name, param3IdlType, param3TypeCode, null);
CorbaStreamable p3 = msg.createStreamableObject(param3, param3Name);
QName param4Name = new QName("param4");
QName param4IdlType = new QName(CorbaConstants.NU_WSDL_CORBA, "float", CorbaConstants.NP_WSDL_CORBA);
TypeCode param4TypeCode = orb.get_primitive_tc(TCKind.tk_float);
CorbaPrimitiveHandler param4 = new CorbaPrimitiveHandler(param4Name, param4IdlType, param4TypeCode, null);
CorbaStreamable p4 = msg.createStreamableObject(param4, param4Name);
CorbaStreamable[] args = new CorbaStreamable[2];
args[0] = p3;
args[1] = p4;
msg.setStreamableArguments(args);
arguments = msg.getStreamableArguments();
assertTrue(arguments.length == 4);
assertNotNull(arguments[0]);
assertNotNull(arguments[1]);
assertNotNull(arguments[2]);
assertNotNull(arguments[3]);
NVList list = orb.create_list(2);
Any value = orb.create_any();
value.insert_Streamable(p1);
list.add_value(p1.getName(), value, p1.getMode());
value.insert_Streamable(p2);
list.add_value(p2.getName(), value, p2.getMode());
msg.setList(list);
NVList resultList = msg.getList();
assertTrue(resultList.count() == 2);
QName returnName = new QName("param2");
QName returnIdlType = new QName(CorbaConstants.NU_WSDL_CORBA, "boolean", CorbaConstants.NP_WSDL_CORBA);
TypeCode returnTypeCode = orb.get_primitive_tc(TCKind.tk_boolean);
CorbaPrimitiveHandler returnValue = new CorbaPrimitiveHandler(returnName, returnIdlType, returnTypeCode, null);
CorbaStreamable ret = msg.createStreamableObject(returnValue, returnName);
msg.setStreamableReturn(ret);
CorbaStreamable retVal = msg.getStreamableReturn();
assertNotNull(retVal);
// NEED TO DO TEST FOR EXCEPTIONS
/*Exception ex = new CorbaBindingException("TestException");
msg.s.setException(ex);
Exception msgEx = msg.getException();
assertNotNull(msgEx);
assertEquals(msgEx.getMessage(), ex.getMessage());*/
}
use of org.omg.CORBA.TypeCode in project cxf by apache.
the class CorbaServerConduitTest method testBuildRequestResultException.
@Test
public void testBuildRequestResultException() {
NVList list = orb.create_list(0);
CorbaServerConduit conduit = setupCorbaServerConduit(false);
CorbaMessage msg = control.createMock(CorbaMessage.class);
Exchange exchange = control.createMock(Exchange.class);
ServerRequest request = control.createMock(ServerRequest.class);
EasyMock.expect(msg.getExchange()).andReturn(exchange);
EasyMock.expect(exchange.get(ServerRequest.class)).andReturn(request);
EasyMock.expect(exchange.isOneWay()).andReturn(false);
CorbaMessage inMsg = EasyMock.createMock(CorbaMessage.class);
EasyMock.expect(msg.getExchange()).andReturn(exchange);
EasyMock.expect(exchange.getInMessage()).andReturn(inMsg);
EasyMock.expect(exchange.getBus()).andReturn(bus);
EasyMock.expect(inMsg.getList()).andReturn(list);
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 exception = new CorbaStreamableImpl(obj, objName);
EasyMock.expect(msg.getStreamableException()).andReturn(exception);
EasyMock.expect(msg.getStreamableException()).andReturn(exception);
control.replay();
conduit.buildRequestResult(msg);
control.verify();
}
use of org.omg.CORBA.TypeCode in project cxf by apache.
the class CorbaUtils method getUnionTypeCode.
public static TypeCode getUnionTypeCode(ORB orb, Object obj, CorbaTypeMap typeMap, Stack<QName> seenTypes) {
Union unionType = (Union) obj;
if (seenTypes.contains(new QName(unionType.getName()))) {
return orb.create_recursive_tc(unionType.getRepositoryID());
}
seenTypes.push(new QName(unionType.getName()));
TypeCode discTC = getTypeCode(orb, unionType.getDiscriminator(), typeMap, seenTypes);
Map<String, UnionMember> members = new LinkedHashMap<>();
List<Unionbranch> branches = unionType.getUnionbranch();
for (Iterator<Unionbranch> branchIter = branches.iterator(); branchIter.hasNext(); ) {
Unionbranch branch = branchIter.next();
List<CaseType> cases = branch.getCase();
for (Iterator<CaseType> caseIter = cases.iterator(); caseIter.hasNext(); ) {
CaseType cs = caseIter.next();
if (!members.containsKey(cs.getLabel())) {
UnionMember member = new UnionMember();
member.name = branch.getName();
member.type = getTypeCode(orb, branch.getIdltype(), typeMap, seenTypes);
member.label = orb.create_any();
// * enum
switch(discTC.kind().value()) {
case TCKind._tk_short:
member.label.insert_short(Short.parseShort(cs.getLabel()));
break;
case TCKind._tk_ushort:
member.label.insert_ushort(Short.parseShort(cs.getLabel()));
break;
case TCKind._tk_long:
member.label.insert_long(Integer.parseInt(cs.getLabel()));
break;
case TCKind._tk_ulong:
member.label.insert_ulong(Integer.parseInt(cs.getLabel()));
break;
case TCKind._tk_longlong:
member.label.insert_longlong(Long.parseLong(cs.getLabel()));
break;
case TCKind._tk_ulonglong:
member.label.insert_ulonglong(Long.parseLong(cs.getLabel()));
break;
case TCKind._tk_char:
member.label.insert_char(cs.getLabel().charAt(0));
break;
case TCKind._tk_boolean:
member.label.insert_boolean(Boolean.parseBoolean(cs.getLabel()));
break;
case TCKind._tk_enum:
org.omg.CORBA.portable.OutputStream out = member.label.create_output_stream();
Enum enumVal = (Enum) getCorbaType(unionType.getDiscriminator(), typeMap);
List<Enumerator> enumerators = enumVal.getEnumerator();
for (int i = 0; i < enumerators.size(); ++i) {
Enumerator e = enumerators.get(i);
if (e.getValue().equals(cs.getLabel())) {
out.write_long(i);
}
}
member.label.read_value(out.create_input_stream(), discTC);
break;
default:
throw new CorbaBindingException("Unsupported discriminator type");
}
// Some orbs are strict on how the case labels are stored for
// each member. So we can't
// simply insert the labels as strings
members.put(cs.getLabel(), member);
}
}
}
seenTypes.pop();
return orb.create_union_tc(unionType.getRepositoryID(), getTypeCodeName(unionType.getName()), discTC, members.values().toArray(new UnionMember[members.size()]));
}
use of org.omg.CORBA.TypeCode in project cxf by apache.
the class CorbaUtils method getAnonTypeCode.
private static TypeCode getAnonTypeCode(ORB orb, QName type, Object obj, CorbaTypeMap typeMap, Stack<QName> seenTypes) {
TypeCode tc = null;
if (obj instanceof Anonarray) {
Anonarray anonArrayType = (Anonarray) obj;
tc = orb.create_array_tc((int) anonArrayType.getBound(), getTypeCode(orb, anonArrayType.getElemtype(), typeMap, seenTypes));
} else if (obj instanceof Anonfixed) {
Anonfixed anonFixedType = (Anonfixed) obj;
tc = orb.create_fixed_tc((short) anonFixedType.getDigits(), (short) anonFixedType.getScale());
} else if (obj instanceof Anonsequence) {
Anonsequence anonSeqType = (Anonsequence) obj;
tc = orb.create_sequence_tc((int) anonSeqType.getBound(), getTypeCode(orb, anonSeqType.getElemtype(), typeMap, seenTypes));
} else if (obj instanceof Anonstring) {
Anonstring anonStringType = (Anonstring) obj;
tc = orb.create_string_tc((int) anonStringType.getBound());
} else if (obj instanceof Anonwstring) {
Anonwstring anonWStringType = (Anonwstring) obj;
tc = orb.create_wstring_tc((int) anonWStringType.getBound());
}
return tc;
}
Aggregations