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

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


            }
        }
    }
   
    public void testCorbaEnumHandler() {
        Enum enumType = new Enum();
        enumType.setName("EnumType");
        enumType.setRepositoryID("IDL:EnumType:1.0");
       
        Enumerator enumerator0 = new Enumerator();
        enumerator0.setValue("ENUM0");
        Enumerator enumerator1 = new Enumerator();
        enumerator1.setValue("ENUM1");
        Enumerator enumerator2 = new Enumerator();
        enumerator2.setValue("ENUM2");
        enumType.getEnumerator().add(enumerator0);
        enumType.getEnumerator().add(enumerator1);
        enumType.getEnumerator().add(enumerator2);
       
        QName enumName = new QName("EnumType");
        QName enumIdlType =
            new QName(CorbaConstants.NU_WSDL_CORBA, "EnumType", CorbaConstants.NP_WSDL_CORBA);
        String members[] = new String[3];
        members[0] = enumerator0.getValue();
        members[1] = enumerator1.getValue();
        members[2] = enumerator2.getValue();
        TypeCode enumTC = orb.create_enum_tc(enumType.getRepositoryID(), enumType.getName(), members);
       
        CorbaEnumHandler obj = new CorbaEnumHandler(enumName, enumIdlType, enumTC, enumType);
        assertNotNull(obj);
       
        obj.setValue(members[1]);
View Full Code Here


        return processPrimitiveType(qname);
    }

    private Enum createCorbaEnum(XmlSchemaSimpleTypeRestriction restrictionType, QName name,
                                 QName schematypeName) {
        Enum corbaEnum = new Enum();
        corbaEnum.setType(schematypeName);
        corbaEnum.setName(name.getLocalPart());
        corbaEnum.setQName(name);

        corbaEnum.setRepositoryID(REPO_STRING + name.getLocalPart().replace('.', '/') + IDL_VERSION);
        Iterator enums = restrictionType.getFacets().getIterator();

        while (enums.hasNext()) {
            XmlSchemaEnumerationFacet val = (XmlSchemaEnumerationFacet)enums.next();
            Enumerator enumerator = new Enumerator();
            enumerator.setValue(val.getValue().toString());
            corbaEnum.getEnumerator().add(enumerator);
        }
        return corbaEnum;
    }
View Full Code Here

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

        List<String> caselist = new ArrayList<String>();

        if (disctype instanceof Enum) {
            Enum corbaenum = (Enum)disctype;
            Iterator iterator = corbaenum.getEnumerator().iterator();

            while (iterator.hasNext()) {
                Enumerator enumerator = (Enumerator)iterator.next();
                caselist.add(enumerator.getValue());
            }
View Full Code Here

        int enumIndex = 0;
        objName = new QName("member3");
        objIdlType = new QName(nestedNamespaceURI, "BasicEnum", nestedPrefix);
        type = CorbaUtils.getCorbaType(objIdlType, bindingImpl.getCorbaTypeMaps());
        assertTrue(type instanceof Enum);
        Enum enumType = (Enum)type;
        objTypeCode = CorbaUtils.getTypeCode(orb, objIdlType, bindingImpl.getCorbaTypeMaps());
        CorbaEnumHandler member3Obj = new CorbaEnumHandler(objName, objIdlType, objTypeCode, enumType);
        assertNotNull(member3Obj);
        obj.addMember(member3Obj);
       
        // Create member 4, a Basic Enum
        Float floatValue = 123456.678f;
        objName = new QName("member4");
        objIdlType = CorbaConstants.NT_CORBA_FLOAT;
        objTypeCode = CorbaUtils.getTypeCode(orb, objIdlType, bindingImpl.getCorbaTypeMaps());
        CorbaPrimitiveHandler member4Obj = new CorbaPrimitiveHandler(objName, objIdlType, objTypeCode, null);
        assertNotNull(member4Obj);
        obj.addMember(member4Obj);

        // Write to an output stream the way a CORBA application would marshal the data for the nested
        // struct.
        Buffer buf = new Buffer();
        OutputStream oStream = new OutputStream(buf);
       
        oStream.write_string(nestedMember1Value);
        oStream.write_boolean(nestedMember2Value.booleanValue());
        oStream.write_fixed(fixedValue.movePointRight(2));
        oStream.write_long(enumIndex);
        oStream.write_float(floatValue.floatValue());
       
        InputStream iStream = oStream.create_input_stream();
        CorbaObjectReader reader = new CorbaObjectReader(iStream);
        reader.read(obj);       
       
        // Now that the Object has its values, try and write it to Stax
        XMLInputFactory inputFactory = XMLInputFactory.newInstance();
        XMLOutputFactory outputFactory = XMLOutputFactory.newInstance();
        outputFactory.setProperty(XMLOutputFactory.IS_REPAIRING_NAMESPACES, Boolean.TRUE);
     
        ByteArrayOutputStream outStream = new ByteArrayOutputStream();
        XMLEventWriter evtWriter = null;
        try {
            evtWriter = outputFactory.createXMLEventWriter(outStream);
        } catch (XMLStreamException ex) {
            assertTrue(false);
        }
        assertNotNull(evtWriter);
       
        XMLEventFactory factory = XMLEventFactory.newInstance();
        try {
            bindingImpl.writeObjectToStax(obj, evtWriter, factory, false);
            evtWriter.flush();
        } catch (XMLStreamException ex) {
            assertTrue(false);
        }
       
        byte[] b = outStream.toByteArray();
        for (int i = 0; i < b.length; ++i) {
            System.out.print((char)b[i]);
        }
        System.out.println();
       
        ByteArrayInputStream inStream = new ByteArrayInputStream(outStream.toByteArray());       
        XMLEventReader evtReader = null;
        try {           
            evtReader = inputFactory.createXMLEventReader(inStream);
        } catch (XMLStreamException ex) {
            assertTrue(false);
        }
        assertNotNull(evtReader);
       
        // Now use the Stax data to re-create a new object
        CorbaObjectHandler result =
            bindingImpl.readObjectFromStax(evtReader,
                                           new QName(nestedNamespaceURI, "NestedStruct", nestedPrefix),
                                           false);
       
        // Verify that the object has the correct values
        assertTrue(result instanceof CorbaStructHandler);       
        CorbaStructHandler nestedStructResult = (CorbaStructHandler)result;
       
        result = nestedStructResult.getMember(0);
        assertTrue(result instanceof CorbaStructHandler);
        CorbaStructHandler structResult = (CorbaStructHandler)result;

        // These are from the struct nested inside our other struct
        result = structResult.getMember(0);
        assertTrue(result instanceof CorbaPrimitiveHandler);
        CorbaPrimitiveHandler structPrimitiveMemberResult = (CorbaPrimitiveHandler)result;
        assertTrue(structPrimitiveMemberResult.getValueData().equals(nestedMember1Value.toString()));
        result = structResult.getMember(1);
        assertTrue(result instanceof CorbaPrimitiveHandler);
        structPrimitiveMemberResult = (CorbaPrimitiveHandler)result;
        assertTrue(structPrimitiveMemberResult.getValueData().equals(nestedMember2Value.toString()));
       
        // This is the fixed nested inside our struct
        result = nestedStructResult.getMember(1);
        assertTrue(result instanceof CorbaFixedHandler);
        CorbaFixedHandler fixedResult = (CorbaFixedHandler)result;
        assertTrue(fixedResult.getValue().equals(fixedValue));

        // This is the enum nested inside our struct
        result = nestedStructResult.getMember(2);
        assertTrue(result instanceof CorbaEnumHandler);
        CorbaEnumHandler enumResult = (CorbaEnumHandler)result;
        assertTrue(enumResult.getValue().equals(enumType.getEnumerator().get(enumIndex).getValue()));
       
        // This is the primitive nested inside our struct
        result = nestedStructResult.getMember(3);
        assertTrue(result instanceof CorbaPrimitiveHandler);
        CorbaPrimitiveHandler primitiveResult = (CorbaPrimitiveHandler)result;
View Full Code Here

        //XmlSchemaSimpleTypeContent xmlSchemaSimpleTypeContent = enumSchemaSimpleTypeRestriction;
        enumSchemaSimpleType.setContent(enumSchemaSimpleTypeRestriction);

       
        // corba:enum
        Enum corbaEnum = new Enum();
        corbaEnum.setQName(new QName(typeMap.getTargetNamespace(), enumNameNode.toString()));
        corbaEnum.setRepositoryID(CorbaConstants.REPO_STRING
                                  + enumNameNode.toString()
                                  + CorbaConstants.IDL_VERSION);
        corbaEnum.setType(enumSchemaSimpleType.getQName());
       
       
        AST node = enumNameNode.getNextSibling();
        while (node != null) {
            // xmlschema:enumeration
            XmlSchemaEnumerationFacet enumeration = new XmlSchemaEnumerationFacet();
            enumeration.setValue(node.toString());
            enumSchemaSimpleTypeRestriction.getFacets().add(enumeration);

            // corba:enumerator
            Enumerator enumerator = new Enumerator();
            enumerator.setValue(node.toString());
            corbaEnum.getEnumerator().add(enumerator);
           
            node = node.getNextSibling();
        }
       
        // add xmlschema:enum
View Full Code Here

    public void testReadWriteStaxEnum() {
        QName objName = new QName("object");
        QName objIdlType = new QName(staxTestNamespaceURI, "TestEnum", staxTestPrefix);
        CorbaTypeImpl type = CorbaUtils.getCorbaType(objIdlType, staxBindingImpl.getCorbaTypeMaps());
        assertTrue(type instanceof Enum);
        Enum enumType = (Enum)type;
        List<Enumerator> enumerators = enumType.getEnumerator();
        String[] enums = new String[enumerators.size()];
        for (int i = 0; i < enumerators.size(); ++i) {
            Enumerator e = enumerators.get(i);
            enums[i] = e.getValue();
        }
View Full Code Here

        } else if (discriminator.getTypeCodeKind().value() == TCKind._tk_enum) {
            // Get the list of possible enumerations in the enumerator and compare these to the
            // labels we obtained from the Union definition.  In order for the union/enum
            // combination to be syntactically correct, there must be one enumeration not included
            // as a case for the default case to be valid.
            Enum enumType = (Enum)discriminator.getType();
            List<Enumerator> enumerators = enumType.getEnumerator();
            if (labels.isEmpty()) {
                // Any value will do since we only have a default case.
                label = enumerators.get(0).getValue();                 
            } else {
                String enumLabel = null;
View Full Code Here

            if (currentNode.getNodeName().equals("corba:const")) {
                Const constType = getConstDefinition(currentNode, def);
                mappingType.getStructOrExceptionOrUnion().add(constType);
            } else if (currentNode.getNodeName().equals("corba:enum")) {
                Enum enumType = getEnumDefinition(currentNode, def);
                mappingType.getStructOrExceptionOrUnion().add(enumType);
            } else if (currentNode.getNodeName().equals("corba:struct")) {
                Struct structType = getStructDefinition(currentNode, def);
                mappingType.getStructOrExceptionOrUnion().add(structType);
            } else if (currentNode.getNodeName().equals("corba:exception")) {
View Full Code Here

        }
        return constType;
    }

    public Enum getEnumDefinition(Node node, Definition def) {
        Enum enumType = new Enum();
        NamedNodeMap enumAttributes = node.getAttributes();
       
        // Store information about the enum
        for (int i = 0; i < enumAttributes.getLength(); ++i) {
            if (enumAttributes.item(i).getNodeName().equals("name")) {
                enumType.setName(enumAttributes.item(i).getNodeValue());
            } else if (enumAttributes.item(i).getNodeName().equals("repositoryID")) {
                enumType.setRepositoryID(enumAttributes.item(i).getNodeValue());
            }
        }

        // Store information about the enumerations
        NodeList enumChildNodes = node.getChildNodes();
        for (int i = 0; i < enumChildNodes.getLength(); ++i) {
            Node currentNode = enumChildNodes.item(i);
           
            // The spec uses corba:enumeration but the tool we have uses corba:enumerator.
            // REVISIT: Which one is correct?
            //if (currentNode.getNodeName().equals("corba:enumeration")) {
            if (currentNode.getNodeName().equals("corba:enumerator")) {
                Enumerator enumerator = new Enumerator();
                NamedNodeMap enumeratorAttrs = currentNode.getAttributes();

                for (int j = 0; j < enumeratorAttrs.getLength(); ++j) {
                    Node enumeratorAttrNode = enumeratorAttrs.item(j);
                    if (enumeratorAttrNode.getNodeName().equals("value")) {
                        enumerator.setValue(enumeratorAttrNode.getNodeValue());
                    }
                }
                enumType.getEnumerator().add(enumerator);
            }
        }

        return enumType;
    }
View Full Code Here

        throws CorbaBindingException {
        CorbaEnumHandler obj = null;
        CorbaTypeImpl typeDefinition = CorbaUtils.getCorbaType(idlType, typeMaps);
       
        try {
            Enum enumType = (Enum)typeDefinition;
            StartElement enumStartEl = reader.nextEvent().asStartElement();
            obj = new CorbaEnumHandler(enumStartEl.getName(), idlType, tc, enumType);
            Characters enumCharEl = reader.nextEvent().asCharacters();
            obj.setValue(enumCharEl.getData());
            reader.nextEvent().asEndElement();
View Full Code Here

TOP

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

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.