Search in sources :

Example 1 with CorbaEnumHandler

use of org.apache.cxf.binding.corba.types.CorbaEnumHandler in project cxf by apache.

the class CorbaObjectReader method readEnum.

// -- complex types --
public void readEnum(CorbaObjectHandler obj) throws CorbaBindingException {
    int enumIndex = stream.read_long();
    Enum enumType = (Enum) obj.getType();
    List<Enumerator> enumerators = enumType.getEnumerator();
    CorbaEnumHandler enumObj = (CorbaEnumHandler) obj;
    enumObj.setValue(enumerators.get(enumIndex).getValue());
}
Also used : Enum(org.apache.cxf.binding.corba.wsdl.Enum) Enumerator(org.apache.cxf.binding.corba.wsdl.Enumerator) CorbaEnumHandler(org.apache.cxf.binding.corba.types.CorbaEnumHandler)

Example 2 with CorbaEnumHandler

use of org.apache.cxf.binding.corba.types.CorbaEnumHandler in project cxf by apache.

the class CorbaObjectReader method readUnion.

public void readUnion(CorbaUnionHandler unionHandler) throws CorbaBindingException {
    Union unionType = (Union) unionHandler.getType();
    List<Unionbranch> branches = unionType.getUnionbranch();
    CorbaObjectHandler discriminator = unionHandler.getDiscriminator();
    if (!branches.isEmpty()) {
        String discLabel = null;
        if (discriminator.getTypeCodeKind().value() == TCKind._tk_enum) {
            CorbaEnumHandler disc = (CorbaEnumHandler) discriminator;
            readEnumDiscriminator(unionHandler, disc);
            discLabel = disc.getValue();
        } else {
            read(discriminator);
            discLabel = ((CorbaPrimitiveHandler) discriminator).getDataFromValue();
        }
        // Now find the label in the union to get the right case
        Unionbranch defaultBranch = null;
        boolean caseFound = false;
        for (Iterator<Unionbranch> branchIter = branches.iterator(); branchIter.hasNext(); ) {
            Unionbranch branch = branchIter.next();
            if (branch.isSetDefault() && branch.isDefault()) {
                defaultBranch = branch;
            }
            List<CaseType> cases = branch.getCase();
            for (Iterator<CaseType> caseIter = cases.iterator(); caseIter.hasNext(); ) {
                CaseType c = caseIter.next();
                if (c.getLabel().equalsIgnoreCase(discLabel)) {
                    CorbaObjectHandler branchObj = unionHandler.getBranchByName(branch.getName());
                    this.read(branchObj);
                    unionHandler.setValue(branch.getName(), branchObj);
                    caseFound = true;
                    break;
                }
            }
            if (caseFound) {
                break;
            }
        }
        // found the default case.
        if (!caseFound && defaultBranch != null) {
            CorbaObjectHandler branchObj = unionHandler.getBranchByName(defaultBranch.getName());
            this.read(branchObj);
            unionHandler.setValue(defaultBranch.getName(), branchObj);
        }
    }
}
Also used : CaseType(org.apache.cxf.binding.corba.wsdl.CaseType) CorbaObjectHandler(org.apache.cxf.binding.corba.types.CorbaObjectHandler) CorbaEnumHandler(org.apache.cxf.binding.corba.types.CorbaEnumHandler) Union(org.apache.cxf.binding.corba.wsdl.Union) Unionbranch(org.apache.cxf.binding.corba.wsdl.Unionbranch)

Example 3 with CorbaEnumHandler

use of org.apache.cxf.binding.corba.types.CorbaEnumHandler 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);
    assertTrue(obj.getValue().equals(enums[1]));
}
Also used : Enum(org.apache.cxf.binding.corba.wsdl.Enum) Enumerator(org.apache.cxf.binding.corba.wsdl.Enumerator) TypeCode(org.omg.CORBA.TypeCode) InputStream(org.omg.CORBA.portable.InputStream) QName(javax.xml.namespace.QName) OutputStream(org.omg.CORBA.portable.OutputStream) CorbaEnumHandler(org.apache.cxf.binding.corba.types.CorbaEnumHandler) Test(org.junit.Test)

Aggregations

CorbaEnumHandler (org.apache.cxf.binding.corba.types.CorbaEnumHandler)3 Enum (org.apache.cxf.binding.corba.wsdl.Enum)2 Enumerator (org.apache.cxf.binding.corba.wsdl.Enumerator)2 QName (javax.xml.namespace.QName)1 CorbaObjectHandler (org.apache.cxf.binding.corba.types.CorbaObjectHandler)1 CaseType (org.apache.cxf.binding.corba.wsdl.CaseType)1 Union (org.apache.cxf.binding.corba.wsdl.Union)1 Unionbranch (org.apache.cxf.binding.corba.wsdl.Unionbranch)1 Test (org.junit.Test)1 TypeCode (org.omg.CORBA.TypeCode)1 InputStream (org.omg.CORBA.portable.InputStream)1 OutputStream (org.omg.CORBA.portable.OutputStream)1