Search in sources :

Example 51 with TypeCode

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;
}
Also used : RaisesType(org.apache.cxf.binding.corba.wsdl.RaisesType) TypeCode(org.omg.CORBA.TypeCode) HashMap(java.util.HashMap)

Example 52 with TypeCode

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());*/
}
Also used : CorbaPrimitiveHandler(org.apache.cxf.binding.corba.types.CorbaPrimitiveHandler) TypeCode(org.omg.CORBA.TypeCode) QName(javax.xml.namespace.QName) NVList(org.omg.CORBA.NVList) Any(org.omg.CORBA.Any) Test(org.junit.Test)

Example 53 with TypeCode

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();
}
Also used : Exchange(org.apache.cxf.message.Exchange) CorbaPrimitiveHandler(org.apache.cxf.binding.corba.types.CorbaPrimitiveHandler) CorbaStreamableImpl(org.apache.cxf.binding.corba.runtime.CorbaStreamableImpl) TypeCode(org.omg.CORBA.TypeCode) QName(javax.xml.namespace.QName) NVList(org.omg.CORBA.NVList) ServerRequest(org.omg.CORBA.ServerRequest) Test(org.junit.Test)

Example 54 with TypeCode

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()]));
}
Also used : Enum(org.apache.cxf.binding.corba.wsdl.Enum) CorbaBindingException(org.apache.cxf.binding.corba.CorbaBindingException) TypeCode(org.omg.CORBA.TypeCode) QName(javax.xml.namespace.QName) Union(org.apache.cxf.binding.corba.wsdl.Union) UnionMember(org.omg.CORBA.UnionMember) LinkedHashMap(java.util.LinkedHashMap) CaseType(org.apache.cxf.binding.corba.wsdl.CaseType) Enumerator(org.apache.cxf.binding.corba.wsdl.Enumerator) Unionbranch(org.apache.cxf.binding.corba.wsdl.Unionbranch)

Example 55 with TypeCode

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;
}
Also used : Anonfixed(org.apache.cxf.binding.corba.wsdl.Anonfixed) Anonwstring(org.apache.cxf.binding.corba.wsdl.Anonwstring) TypeCode(org.omg.CORBA.TypeCode) Anonarray(org.apache.cxf.binding.corba.wsdl.Anonarray) Anonsequence(org.apache.cxf.binding.corba.wsdl.Anonsequence) Anonstring(org.apache.cxf.binding.corba.wsdl.Anonstring)

Aggregations

TypeCode (org.omg.CORBA.TypeCode)70 QName (javax.xml.namespace.QName)49 Test (org.junit.Test)44 CorbaPrimitiveHandler (org.apache.cxf.binding.corba.types.CorbaPrimitiveHandler)18 InputStream (org.omg.CORBA.portable.InputStream)15 OutputStream (org.omg.CORBA.portable.OutputStream)14 StructMember (org.omg.CORBA.StructMember)9 CorbaBindingException (org.apache.cxf.binding.corba.CorbaBindingException)6 MemberType (org.apache.cxf.binding.corba.wsdl.MemberType)6 Any (org.omg.CORBA.Any)6 NVList (org.omg.CORBA.NVList)6 CorbaStreamable (org.apache.cxf.binding.corba.CorbaStreamable)5 CorbaObjectHandler (org.apache.cxf.binding.corba.types.CorbaObjectHandler)4 Array (org.apache.cxf.binding.corba.wsdl.Array)4 Enum (org.apache.cxf.binding.corba.wsdl.Enum)4 Enumerator (org.apache.cxf.binding.corba.wsdl.Enumerator)4 Sequence (org.apache.cxf.binding.corba.wsdl.Sequence)4 Struct (org.apache.cxf.binding.corba.wsdl.Struct)4 Exchange (org.apache.cxf.message.Exchange)4 IOException (java.io.IOException)3