Search in sources :

Example 1 with StructMember

use of org.omg.CORBA.StructMember in project ACS by ACS-Community.

the class BACIIntrospector method getStructDef.

private DataStruct getStructDef(TypeCode tc) {
    if (tc.kind() != TCKind.tk_struct)
        return null;
    try {
        DataStruct ds = new DataStruct(tc.id());
        Contained ctd = ra.lookupId(tc.id());
        StructDef sd = StructDefHelper.narrow(ctd);
        StructMember[] mems = sd.members();
        for (int i = 0; i < mems.length; i++) {
            DataType dt = new BACIDataType(getClassType(mems[i].type));
            dt.setElement(getDef(mems[i].type));
            ds.add(mems[i].name, dt);
        }
        return ds;
    } catch (org.omg.CORBA.TypeCodePackage.BadKind e) {
        e.printStackTrace();
        return null;
    }
}
Also used : DataStruct(si.ijs.acs.objectexplorer.engine.DataStruct) Contained(org.omg.CORBA.Contained) DataType(si.ijs.acs.objectexplorer.engine.DataType) StructMember(org.omg.CORBA.StructMember) StructDef(org.omg.CORBA.StructDef)

Example 2 with StructMember

use of org.omg.CORBA.StructMember in project cxf by apache.

the class CorbaObjectReaderTest method testReadException.

@Test
public void testReadException() {
    OutputStream oStream = orb.create_output_stream();
    // create the following exception
    // exception TestExcept {
    // short code;
    // string message;
    // }
    short code = 12345;
    String message = "54321";
    oStream.write_string("IDL:org.apache.cxf.TestException/1.0");
    oStream.write_short(code);
    oStream.write_string(message);
    InputStream iStream = oStream.create_input_stream();
    CorbaObjectReader reader = new CorbaObjectReader(iStream);
    QName exceptIdlType = new QName(CorbaConstants.NU_WSDL_CORBA, "exception", CorbaConstants.NP_WSDL_CORBA);
    QName shortIdlType = new QName(CorbaConstants.NU_WSDL_CORBA, "short", CorbaConstants.NP_WSDL_CORBA);
    QName stringIdlType = new QName(CorbaConstants.NU_WSDL_CORBA, "string", CorbaConstants.NP_WSDL_CORBA);
    Exception exceptType = new Exception();
    exceptType.setName("TestException");
    MemberType m1 = new MemberType();
    m1.setIdltype(shortIdlType);
    m1.setName("code");
    MemberType m2 = new MemberType();
    m2.setIdltype(stringIdlType);
    m2.setName("message");
    exceptType.getMember().add(m1);
    exceptType.getMember().add(m2);
    // build the object holder
    StructMember[] exceptMembers = new StructMember[2];
    exceptMembers[0] = new StructMember("code", orb.get_primitive_tc(TCKind.tk_short), null);
    exceptMembers[1] = new StructMember("message", orb.get_primitive_tc(TCKind.tk_string), null);
    TypeCode exceptTC = orb.create_exception_tc("IDL:org.apache.cxf.TestException/1.0", "TestException", exceptMembers);
    CorbaExceptionHandler obj = new CorbaExceptionHandler(new QName("TestException"), exceptIdlType, exceptTC, exceptType);
    obj.addMember(new CorbaPrimitiveHandler(new QName("code"), shortIdlType, exceptMembers[0].type, null));
    obj.addMember(new CorbaPrimitiveHandler(new QName("message"), stringIdlType, exceptMembers[1].type, null));
    reader.readException(obj);
    List<CorbaObjectHandler> nestedObjs = obj.getMembers();
    assertTrue(new Short(((CorbaPrimitiveHandler) nestedObjs.get(0)).getDataFromValue()).shortValue() == code);
    assertTrue(((CorbaPrimitiveHandler) nestedObjs.get(1)).getDataFromValue().equals(message));
}
Also used : TypeCode(org.omg.CORBA.TypeCode) InputStream(org.omg.CORBA.portable.InputStream) QName(javax.xml.namespace.QName) OutputStream(org.omg.CORBA.portable.OutputStream) StructMember(org.omg.CORBA.StructMember) Exception(org.apache.cxf.binding.corba.wsdl.Exception) IOException(java.io.IOException) CorbaPrimitiveHandler(org.apache.cxf.binding.corba.types.CorbaPrimitiveHandler) CorbaExceptionHandler(org.apache.cxf.binding.corba.types.CorbaExceptionHandler) MemberType(org.apache.cxf.binding.corba.wsdl.MemberType) CorbaObjectHandler(org.apache.cxf.binding.corba.types.CorbaObjectHandler) Test(org.junit.Test)

Example 3 with StructMember

use of org.omg.CORBA.StructMember in project cxf by apache.

the class CorbaObjectReaderTest method testReadStruct.

@Test
public void testReadStruct() {
    OutputStream oStream = orb.create_output_stream();
    // create the following struct
    // struct TestStruct {
    // long member1;
    // string member2;
    // boolean member3;
    // }
    int member1 = 12345;
    String member2 = "54321";
    boolean member3 = true;
    oStream.write_long(member1);
    oStream.write_string(member2);
    oStream.write_boolean(member3);
    InputStream iStream = oStream.create_input_stream();
    CorbaObjectReader reader = new CorbaObjectReader(iStream);
    QName structIdlType = new QName(CorbaConstants.NU_WSDL_CORBA, "struct", CorbaConstants.NP_WSDL_CORBA);
    QName longIdlType = new QName(CorbaConstants.NU_WSDL_CORBA, "long", CorbaConstants.NP_WSDL_CORBA);
    QName stringIdlType = new QName(CorbaConstants.NU_WSDL_CORBA, "string", CorbaConstants.NP_WSDL_CORBA);
    QName boolIdlType = new QName(CorbaConstants.NU_WSDL_CORBA, "boolean", CorbaConstants.NP_WSDL_CORBA);
    Struct structType = new Struct();
    structType.setName("TestStruct");
    MemberType m1 = new MemberType();
    m1.setIdltype(longIdlType);
    m1.setName("member1");
    MemberType m2 = new MemberType();
    m2.setIdltype(stringIdlType);
    m2.setName("member2");
    MemberType m3 = new MemberType();
    m3.setIdltype(boolIdlType);
    m3.setName("member3");
    structType.getMember().add(m1);
    structType.getMember().add(m2);
    structType.getMember().add(m3);
    // build the object holder
    StructMember[] structMembers = new StructMember[3];
    structMembers[0] = new StructMember("member1", orb.get_primitive_tc(TCKind.tk_long), null);
    structMembers[1] = new StructMember("member2", orb.get_primitive_tc(TCKind.tk_string), null);
    structMembers[2] = new StructMember("member3", orb.get_primitive_tc(TCKind.tk_boolean), null);
    TypeCode structTC = orb.create_struct_tc("IDL:org.apache.cxf.TestStruct/1.0", "TestStruct", structMembers);
    CorbaStructHandler obj = new CorbaStructHandler(new QName("TestStruct"), structIdlType, structTC, structType);
    obj.addMember(new CorbaPrimitiveHandler(new QName("member1"), longIdlType, structMembers[0].type, null));
    obj.addMember(new CorbaPrimitiveHandler(new QName("member2"), stringIdlType, structMembers[1].type, null));
    obj.addMember(new CorbaPrimitiveHandler(new QName("member3"), boolIdlType, structMembers[2].type, null));
    reader.readStruct(obj);
    List<CorbaObjectHandler> nestedObjs = obj.getMembers();
    assertTrue(new Integer(((CorbaPrimitiveHandler) nestedObjs.get(0)).getDataFromValue()).intValue() == member1);
    assertTrue(((CorbaPrimitiveHandler) nestedObjs.get(1)).getDataFromValue().equals(member2));
    assertTrue(Boolean.valueOf(((CorbaPrimitiveHandler) nestedObjs.get(2)).getDataFromValue()).booleanValue() == member3);
}
Also used : TypeCode(org.omg.CORBA.TypeCode) InputStream(org.omg.CORBA.portable.InputStream) QName(javax.xml.namespace.QName) OutputStream(org.omg.CORBA.portable.OutputStream) CorbaStructHandler(org.apache.cxf.binding.corba.types.CorbaStructHandler) StructMember(org.omg.CORBA.StructMember) Struct(org.apache.cxf.binding.corba.wsdl.Struct) CorbaPrimitiveHandler(org.apache.cxf.binding.corba.types.CorbaPrimitiveHandler) BigInteger(java.math.BigInteger) MemberType(org.apache.cxf.binding.corba.wsdl.MemberType) CorbaObjectHandler(org.apache.cxf.binding.corba.types.CorbaObjectHandler) Test(org.junit.Test)

Example 4 with StructMember

use of org.omg.CORBA.StructMember in project cxf by apache.

the class CorbaObjectWriterTest method testWriteStruct.

@Test
public void testWriteStruct() {
    // create the following struct
    // struct TestStruct {
    // long member1;
    // string member2;
    // boolean member3;
    // }
    int member1 = 12345;
    String member2 = "54321";
    boolean member3 = true;
    QName structIdlType = new QName(CorbaConstants.NU_WSDL_CORBA, "struct", CorbaConstants.NP_WSDL_CORBA);
    QName longIdlType = new QName(CorbaConstants.NU_WSDL_CORBA, "long", CorbaConstants.NP_WSDL_CORBA);
    QName stringIdlType = new QName(CorbaConstants.NU_WSDL_CORBA, "string", CorbaConstants.NP_WSDL_CORBA);
    QName boolIdlType = new QName(CorbaConstants.NU_WSDL_CORBA, "boolean", CorbaConstants.NP_WSDL_CORBA);
    Struct structType = new Struct();
    structType.setName("TestStruct");
    MemberType m1 = new MemberType();
    m1.setIdltype(longIdlType);
    m1.setName("member1");
    MemberType m2 = new MemberType();
    m2.setIdltype(stringIdlType);
    m2.setName("member2");
    MemberType m3 = new MemberType();
    m3.setIdltype(boolIdlType);
    m3.setName("member3");
    structType.getMember().add(m1);
    structType.getMember().add(m2);
    structType.getMember().add(m3);
    // build the object holder
    StructMember[] structMembers = new StructMember[3];
    structMembers[0] = new StructMember("member1", orb.get_primitive_tc(TCKind.tk_long), null);
    structMembers[1] = new StructMember("member2", orb.get_primitive_tc(TCKind.tk_string), null);
    structMembers[2] = new StructMember("member3", orb.get_primitive_tc(TCKind.tk_boolean), null);
    TypeCode structTC = orb.create_struct_tc("IDL:org.apache.cxf.TestStruct/1.0", "TestStruct", structMembers);
    CorbaStructHandler obj = new CorbaStructHandler(new QName("TestStruct"), structIdlType, structTC, structType);
    CorbaPrimitiveHandler memberObj1 = new CorbaPrimitiveHandler(new QName("member1"), longIdlType, structMembers[0].type, null);
    CorbaPrimitiveHandler memberObj2 = new CorbaPrimitiveHandler(new QName("member2"), stringIdlType, structMembers[1].type, null);
    CorbaPrimitiveHandler memberObj3 = new CorbaPrimitiveHandler(new QName("member3"), boolIdlType, structMembers[2].type, null);
    memberObj1.setValueFromData(Integer.toString(member1));
    memberObj2.setValueFromData(member2);
    memberObj3.setValueFromData(Boolean.toString(member3));
    obj.addMember(memberObj1);
    obj.addMember(memberObj2);
    obj.addMember(memberObj3);
    OutputStream oStream = orb.create_output_stream();
    CorbaObjectWriter writer = new CorbaObjectWriter(oStream);
    writer.writeStruct(obj);
    InputStream iStream = oStream.create_input_stream();
    int readMember1 = iStream.read_long();
    assertTrue(readMember1 == member1);
    String readMember2 = iStream.read_string();
    assertTrue(readMember2.equals(member2));
    boolean readMember3 = iStream.read_boolean();
    assertTrue(readMember3 == member3);
}
Also used : TypeCode(org.omg.CORBA.TypeCode) QName(javax.xml.namespace.QName) InputStream(org.omg.CORBA.portable.InputStream) CorbaStructHandler(org.apache.cxf.binding.corba.types.CorbaStructHandler) OutputStream(org.omg.CORBA.portable.OutputStream) StructMember(org.omg.CORBA.StructMember) Struct(org.apache.cxf.binding.corba.wsdl.Struct) CorbaPrimitiveHandler(org.apache.cxf.binding.corba.types.CorbaPrimitiveHandler) MemberType(org.apache.cxf.binding.corba.wsdl.MemberType) Test(org.junit.Test)

Example 5 with StructMember

use of org.omg.CORBA.StructMember in project cxf by apache.

the class SystemExceptionHelper method _type.

public TypeCode _type() {
    if (typeCode == null) {
        ORB orb = ORB.init();
        StructMember[] smBuf = new StructMember[2];
        TypeCode minortc = orb.get_primitive_tc(TCKind.tk_long);
        smBuf[0] = new StructMember("minor", minortc, null);
        String[] csLabels = { "COMPLETED_YES", "COMPLETED_NO", "COMPLETED_MAYBE" };
        TypeCode completedtc = orb.create_enum_tc("IDL:omg.org/CORBA/CompletionStatus:1.0", "CompletionStatus", csLabels);
        smBuf[1] = new StructMember("completed", completedtc, null);
        String id;
        String name;
        if (value == null) {
            name = "SystemException";
            id = "IDL:omg.org/CORBA/SystemException:1.0";
        } else {
            String className = value.getClass().getName();
            name = className.substring(className.lastIndexOf('.') + 1);
            id = "IDL:omg.org/CORBA/" + name + ":1.0";
        }
        typeCode = orb.create_exception_tc(id, name, smBuf);
    }
    return typeCode;
}
Also used : TypeCode(org.omg.CORBA.TypeCode) StructMember(org.omg.CORBA.StructMember) ORB(org.omg.CORBA.ORB)

Aggregations

StructMember (org.omg.CORBA.StructMember)10 TypeCode (org.omg.CORBA.TypeCode)9 QName (javax.xml.namespace.QName)6 MemberType (org.apache.cxf.binding.corba.wsdl.MemberType)6 Test (org.junit.Test)5 CorbaPrimitiveHandler (org.apache.cxf.binding.corba.types.CorbaPrimitiveHandler)4 Struct (org.apache.cxf.binding.corba.wsdl.Struct)4 InputStream (org.omg.CORBA.portable.InputStream)4 OutputStream (org.omg.CORBA.portable.OutputStream)4 Exception (org.apache.cxf.binding.corba.wsdl.Exception)3 IOException (java.io.IOException)2 CorbaExceptionHandler (org.apache.cxf.binding.corba.types.CorbaExceptionHandler)2 CorbaObjectHandler (org.apache.cxf.binding.corba.types.CorbaObjectHandler)2 CorbaStructHandler (org.apache.cxf.binding.corba.types.CorbaStructHandler)2 BigInteger (java.math.BigInteger)1 List (java.util.List)1 CorbaBindingException (org.apache.cxf.binding.corba.CorbaBindingException)1 Alias (org.apache.cxf.binding.corba.wsdl.Alias)1 Array (org.apache.cxf.binding.corba.wsdl.Array)1 Enum (org.apache.cxf.binding.corba.wsdl.Enum)1