Search in sources :

Example 11 with Enumerator

use of org.apache.cxf.binding.corba.wsdl.Enumerator in project cxf by apache.

the class CorbaUnionHandler method createDefaultDiscriminatorLabel.

public String createDefaultDiscriminatorLabel() {
    String label = null;
    // discriminator from, these are the four cases we must check for.
    if (discriminator.getTypeCodeKind().value() == TCKind._tk_boolean) {
        // against the first label, if there is one.
        if (labels.isEmpty()) {
            label = "false";
        } else {
            boolean boolValue = Boolean.parseBoolean(labels.get(0));
            label = String.valueOf(!boolValue);
        }
    } else if (discriminator.getTypeCodeKind().value() == TCKind._tk_char) {
        if (labels.isEmpty()) {
            label = String.valueOf('0');
        } else {
            char charValue = labels.get(0).charAt(0);
            while (labels.contains(String.valueOf(charValue))) {
                charValue++;
            }
            label = String.valueOf(charValue);
        }
    } 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 {
            for (Iterator<Enumerator> enumIter = enumerators.iterator(); enumIter.hasNext(); ) {
                String enumLabel = enumIter.next().getValue();
                if (!labels.contains(enumLabel)) {
                    label = enumLabel;
                    break;
                }
            }
        }
    } else if ((discriminator.getTypeCodeKind().value() == TCKind._tk_short) || (discriminator.getTypeCodeKind().value() == TCKind._tk_ushort)) {
        if (labels.isEmpty()) {
            label = String.valueOf(Short.MAX_VALUE);
        }
        for (int i = Short.MAX_VALUE; i >= Short.MIN_VALUE; i--) {
            if (!labels.contains(String.valueOf(i))) {
                label = String.valueOf(i);
                break;
            }
        }
    } else if ((discriminator.getTypeCodeKind().value() == TCKind._tk_long) || (discriminator.getTypeCodeKind().value() == TCKind._tk_ulong)) {
        if (labels.isEmpty()) {
            label = String.valueOf(Integer.MAX_VALUE);
        }
        for (int i = Integer.MAX_VALUE; i >= Integer.MIN_VALUE; i--) {
            if (!labels.contains(String.valueOf(i))) {
                label = String.valueOf(i);
                break;
            }
        }
    }
    return label;
}
Also used : Enum(org.apache.cxf.binding.corba.wsdl.Enum) Enumerator(org.apache.cxf.binding.corba.wsdl.Enumerator)

Example 12 with Enumerator

use of org.apache.cxf.binding.corba.wsdl.Enumerator in project cxf by apache.

the class WSDLToIDLAction method createEnum.

private IdlType createEnum(Enum e, IdlScopeBase scope, String local) {
    IdlEnum enum1 = IdlEnum.create(scope, local);
    Iterator<Enumerator> it = e.getEnumerator().iterator();
    while (it.hasNext()) {
        // Enumerators are created in the same scope
        // as the enum, according to IDL grammar rules.
        String n = it.next().getValue();
        IdlEnumerator enumerator = IdlEnumerator.create(scope, n);
        scope.addToScope(enumerator);
        enum1.addEnumerator(enumerator);
    }
    scope.addToScope(enum1);
    return enum1;
}
Also used : Enumerator(org.apache.cxf.binding.corba.wsdl.Enumerator) IdlEnumerator(org.apache.cxf.tools.corba.common.idltypes.IdlEnumerator) IdlString(org.apache.cxf.tools.corba.common.idltypes.IdlString) IdlEnumerator(org.apache.cxf.tools.corba.common.idltypes.IdlEnumerator) IdlEnum(org.apache.cxf.tools.corba.common.idltypes.IdlEnum)

Example 13 with Enumerator

use of org.apache.cxf.binding.corba.wsdl.Enumerator in project cxf by apache.

the class EnumVisitor method visit.

public void visit(AST enumNode) {
    // <enum_type> ::= "enum" <identifier> "{" <enumerator> {"," <enumerator>}* "}"
    // <enumerator> ::= <identifier>
    AST enumNameNode = enumNode.getFirstChild();
    Scope enumNameScope = new Scope(getScope(), enumNameNode);
    // xmlschema:enum
    XmlSchemaSimpleType enumSchemaSimpleType = new XmlSchemaSimpleType(schema, true);
    enumSchemaSimpleType.setName(mapper.mapToQName(enumNameScope));
    XmlSchemaSimpleTypeRestriction enumSchemaSimpleTypeRestriction = new XmlSchemaSimpleTypeRestriction();
    enumSchemaSimpleTypeRestriction.setBaseTypeName(Constants.XSD_STRING);
    // XmlSchemaSimpleTypeContent xmlSchemaSimpleTypeContent = enumSchemaSimpleTypeRestriction;
    enumSchemaSimpleType.setContent(enumSchemaSimpleTypeRestriction);
    // corba:enum
    Enum corbaEnum = new Enum();
    corbaEnum.setQName(new QName(typeMap.getTargetNamespace(), enumNameScope.toString()));
    corbaEnum.setRepositoryID(enumNameScope.toIDLRepositoryID());
    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 corbaType
    typeMap.getStructOrExceptionOrUnion().add(corbaEnum);
    // REVISIT: are there assignments needed?
    setSchemaType(enumSchemaSimpleType);
    setCorbaType(corbaEnum);
}
Also used : Enum(org.apache.cxf.binding.corba.wsdl.Enum) AST(antlr.collections.AST) Enumerator(org.apache.cxf.binding.corba.wsdl.Enumerator) XmlSchemaSimpleType(org.apache.ws.commons.schema.XmlSchemaSimpleType) QName(javax.xml.namespace.QName) XmlSchemaSimpleTypeRestriction(org.apache.ws.commons.schema.XmlSchemaSimpleTypeRestriction) XmlSchemaEnumerationFacet(org.apache.ws.commons.schema.XmlSchemaEnumerationFacet)

Aggregations

Enumerator (org.apache.cxf.binding.corba.wsdl.Enumerator)13 Enum (org.apache.cxf.binding.corba.wsdl.Enum)12 QName (javax.xml.namespace.QName)6 TypeCode (org.omg.CORBA.TypeCode)4 CorbaBindingException (org.apache.cxf.binding.corba.CorbaBindingException)3 Union (org.apache.cxf.binding.corba.wsdl.Union)3 CorbaEnumHandler (org.apache.cxf.binding.corba.types.CorbaEnumHandler)2 MemberType (org.apache.cxf.binding.corba.wsdl.MemberType)2 XmlSchemaEnumerationFacet (org.apache.ws.commons.schema.XmlSchemaEnumerationFacet)2 Test (org.junit.Test)2 AST (antlr.collections.AST)1 ArrayList (java.util.ArrayList)1 LinkedHashMap (java.util.LinkedHashMap)1 List (java.util.List)1 Alias (org.apache.cxf.binding.corba.wsdl.Alias)1 Array (org.apache.cxf.binding.corba.wsdl.Array)1 CaseType (org.apache.cxf.binding.corba.wsdl.CaseType)1 CorbaType (org.apache.cxf.binding.corba.wsdl.CorbaType)1 Exception (org.apache.cxf.binding.corba.wsdl.Exception)1 Fixed (org.apache.cxf.binding.corba.wsdl.Fixed)1