Package org.apache.schemas.yoko.bindings.corba

Examples of org.apache.schemas.yoko.bindings.corba.Union


        long scale = fixedHandler.getScale();
        stream.write_fixed(fixedHandler.getValue().movePointRight((int)scale));
    }

    public void writeUnion(CorbaObjectHandler obj) throws CorbaBindingException {
        Union unionType = (Union) obj.getType();
        List<Unionbranch> branches = unionType.getUnionbranch();
        if (branches.size() > 0) {
            CorbaObjectHandler discriminator = ((CorbaUnionHandler)obj).getDiscriminator();
            this.write(discriminator);
            CorbaObjectHandler unionValue = ((CorbaUnionHandler)obj).getValue();
            if (unionValue != null) {
View Full Code Here


        }
        return tc;
    }
   
    public static TypeCode getUnionTypeCode(ORB orb, Object obj, List<CorbaTypeMap> typeMaps) {
        Union unionType = (Union)obj;
       
        TypeCode discTC = getTypeCode(orb, unionType.getDiscriminator(), typeMaps);
        Map<String, UnionMember> members = new LinkedHashMap<String, UnionMember>();
        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();
                UnionMember member = new UnionMember();
                member.name = branch.getName();
                member.type = getTypeCode(orb, branch.getIdltype(), typeMaps);
                member.label = orb.create_any();
               
                // We need to insert the labels in a way that depends on the type of the discriminator. 
                // According to the CORBA specification, the following types are permissable as
                // discriminator types:
                //    * signed & unsigned short
                //    * signed & unsigned long
                //    * signed & unsigned long long
                //    * char
                //    * boolean
                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;
                default:
                    // TODO: Throw exception since this is an unsupported discriminator type
                }
                // Yoko orb is 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);
            }
        }
        return orb.create_union_tc(unionType.getRepositoryID(),
                                   unionType.getName(),
                                   discTC,
                                   (UnionMember[])members.values().toArray(new UnionMember[members.size()]));
    }
View Full Code Here

   
    protected MemberType processComplexContentStructChoice(XmlSchemaChoice choice,
                                                     QName schematypeName, QName defaultName)
        throws Exception {
        QName choicename = createQNameTargetNamespace(schematypeName.getLocalPart() + "ChoiceType");
        Union choiceunion = createUnion(choicename, choice,
                                        defaultName, schematypeName);

        String repoId = REPO_STRING + choiceunion.getQName().getLocalPart().replace('.', '/')
            + IDL_VERSION;
        choiceunion.setRepositoryID(repoId);                               
       
        MemberType choicemem = new MemberType();
        choicemem.setName(choiceunion.getQName().getLocalPart() + "_f");
        choicemem.setIdltype(createQNameCorbaNamespace(choiceunion.getQName().getLocalPart()));         
       
        if ((choiceunion != null) && (!isDuplicate(choiceunion))) {
            choiceunion.setQName(null);
            typeMappingType.getStructOrExceptionOrUnion().add(choiceunion);
        }
       
        return choicemem;
    }                   
View Full Code Here

        return choicemem;
    }                   
   
    protected CorbaTypeImpl createNillableUnion(QName name, QName schemaType, QName membertype) {       
       
        Union nilUnion = new Union();
        nilUnion.setName(name.getLocalPart());
        nilUnion.setType(schemaType);
        nilUnion.setQName(name);
        nilUnion.setDiscriminator(CorbaConstants.NT_CORBA_BOOLEAN);
        String id = REPO_STRING + nilUnion.getQName().getLocalPart().replace('.', '/') + IDL_VERSION;
        nilUnion.setRepositoryID(id);

        Unionbranch branch = new Unionbranch();
        branch.setName("value");
        branch.setIdltype(membertype);
        branch.setDefault(false);
        CaseType caseType = new CaseType();
        caseType.setLabel("TRUE");
        branch.getCase().add(caseType);
        nilUnion.getUnionbranch().add(branch);      
       
        return nilUnion;
    }
View Full Code Here

                           checkPrefix(typeName), maxOccurs, minOccurs, anonymous);    
    }
   
    private CorbaTypeImpl processOMGUnion(XmlSchemaComplexType complex, QName defaultName) throws Exception {
        QName name;
        Union corbaUnion = null;
        QName schematypeName = checkPrefix(complex.getQName());               

        if (schematypeName == null) {
            schematypeName = defaultName;
            name = createQNameCorbaNamespace(defaultName.getLocalPart() + "Type");
        } else {
            name = createQNameCorbaNamespace(schematypeName.getLocalPart());
        }

        corbaUnion = new Union();
        corbaUnion.setName(name.getLocalPart());
        corbaUnion.setQName(name);
        String id = REPO_STRING + name.getLocalPart().replace('.', '/') + IDL_VERSION;
        corbaUnion.setRepositoryID(id);
        corbaUnion.setType(schematypeName);

        XmlSchemaSequence stype = (XmlSchemaSequence)complex.getParticle();
        Iterator it = stype.getItems().getIterator();
        XmlSchemaParticle st1 = (XmlSchemaParticle)it.next();
        XmlSchemaParticle st2 = (XmlSchemaParticle)it.next();
        XmlSchemaElement discEl = null;
        XmlSchemaChoice choice = null;

        if (st1 instanceof XmlSchemaElement) {
            discEl = (XmlSchemaElement)st1;
            choice = (XmlSchemaChoice)st2;
        } else {
            discEl = (XmlSchemaElement)st2;
            choice = (XmlSchemaChoice)st1;
        }

        CorbaTypeImpl disctype = convertSchemaToCorbaType(discEl.getSchemaType(), discEl.getQName(), discEl
            .getSchemaType(), null, false);
        corbaUnion.setDiscriminator(disctype.getQName());

        List fields = processContainerAsMembers(choice, defaultName, schematypeName);

        List<String> caselist = new ArrayList<String>();
View Full Code Here

    }
   
    protected Union createUnion(QName name, XmlSchemaChoice choice, QName defaultName,
                                QName schematypeName)
        throws Exception {
        Union corbaUnion = new Union();
        corbaUnion.setName(name.getLocalPart());
        corbaUnion.setQName(name);       
        corbaUnion.setType(schematypeName);
        String id = REPO_STRING + name.getLocalPart().replace('.', '/') + IDL_VERSION;
        corbaUnion.setRepositoryID(id);

        //Set Integer as Discriminator
        corbaUnion.setDiscriminator(CorbaConstants.NT_CORBA_LONG);

        List fields = processContainerAsMembers(choice, defaultName, schematypeName);

        //Choose an Integer as a Discriminator
        List<String> caselist = new ArrayList<String>();       
View Full Code Here

            WSDLToIDLAction idlgen = new WSDLToIDLAction();
            idlgen.setBindingName("NillableCORBABinding");
            idlgen.setOutputFile("nillable.idl");
            idlgen.generateIDL(model);
           
            Union un = (Union)mapType.getStructOrExceptionOrUnion().get(2);
            assertEquals("Name is incorrect for Union Type", "long_nil",
                         un.getName());
            assertEquals("Type is incorrect for Union Type", "PEl",
                         un.getType().getLocalPart());
            Unionbranch unbranch = un.getUnionbranch().get(0);
            assertEquals("Name is incorrect for UnionBranch Type", "value",
                         unbranch.getName());
            assertEquals("Type is incorrect for UnionBranch Type", "long",
                         unbranch.getIdltype().getLocalPart());
View Full Code Here

            assertEquals("Name is incorrect for AnonString Type", "attrib2Type",
                         str.getName());
            assertEquals("Type is incorrect for AnonString Type", "string",
                         str.getType().getLocalPart());           

            Union un = (Union)mapType.getStructOrExceptionOrUnion().get(7);
            assertEquals("Name is incorrect for Union Type", "attrib2Type_nil",
                         un.getName());
            assertEquals("Type is incorrect for Union Type", "attrib2",
                         un.getType().getLocalPart());
            Unionbranch unbranch = un.getUnionbranch().get(0);
            assertEquals("Name is incorrect for UnionBranch Type", "value",
                         unbranch.getName());
            assertEquals("Type is incorrect for UnionBranch Type", "attrib2Type",
                         unbranch.getIdltype().getLocalPart());
View Full Code Here

        choice.setMaxOccurs(1);
        sequence.getItems().add(choice);
       
       
        // corba:union
        Union corbaUnion = new Union();
        corbaUnion.setQName(new QName(typeMap.getTargetNamespace(), identifierNode.toString()));
        corbaUnion.setRepositoryID(CorbaConstants.REPO_STRING
                                   + identifierNode.toString()
                                   + CorbaConstants.IDL_VERSION);
        corbaUnion.setType(unionSchemaComplexType.getQName());
        corbaUnion.setDiscriminator(TypesUtils.findCorbaType(typeMap, type.getQName()).getQName());
       
        processCaseNodes(caseNode, choice, corbaUnion);
           
       
        // add xmlschema:union
View Full Code Here

    public void testReadWriteUnion() {
        QName objName = new QName("object");
        QName objIdlType = new QName(staxTestNamespaceURI, "TestUnion", staxTestPrefix);
        CorbaTypeImpl type = CorbaUtils.getCorbaType(objIdlType, staxBindingImpl.getCorbaTypeMaps());
        assertTrue(type instanceof Union);
        Union unionType = (Union)type;
        TypeCode objTypeCode = CorbaUtils.getTypeCode(orb, objIdlType, staxBindingImpl.getCorbaTypeMaps());
        CorbaUnionHandler obj = new CorbaUnionHandler(objName, objIdlType, objTypeCode, unionType);
        assertNotNull(obj);
       
        Character unionValue = new Character('u');
        TypeCode unionValueTC = CorbaUtils.getTypeCode(orb, CorbaConstants.NT_CORBA_WCHAR,
                                                       staxBindingImpl.getCorbaTypeMaps());
        CorbaPrimitiveHandler unionValueObj = new CorbaPrimitiveHandler(new QName("case12"),
                                                                        CorbaConstants.NT_CORBA_WCHAR,
                                                                        unionValueTC,
                                                                        null);
        unionValueObj.setValue(unionValue);
        Short discriminatorValue = new Short((short)1);
        TypeCode discriminatorTC = CorbaUtils.getTypeCode(orb, unionType.getDiscriminator(),
                                                          staxBindingImpl.getCorbaTypeMaps());
        CorbaPrimitiveHandler discriminator = new CorbaPrimitiveHandler(new QName("discriminator"),
                                                                       unionType.getDiscriminator(),
                                                                       discriminatorTC,
                                                                       null);
        discriminator.setValue(discriminatorValue);

        obj.setDiscriminator(discriminator);
View Full Code Here

TOP

Related Classes of org.apache.schemas.yoko.bindings.corba.Union

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.