Search in sources :

Example 6 with Enum

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

the class WSDLToCorbaHelper method processOMGUnion.

private CorbaType 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<XmlSchemaSequenceMember> it = stype.getItems().iterator();
    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;
    }
    CorbaType disctype = convertSchemaToCorbaType(discEl.getSchemaType(), discEl.getQName(), discEl.getSchemaType(), null, false);
    corbaUnion.setDiscriminator(disctype.getQName());
    List<MemberType> fields = processContainerAsMembers(choice, defaultName, schematypeName);
    List<String> caselist = new ArrayList<>();
    if (disctype instanceof Enum) {
        Enum corbaenum = (Enum) disctype;
        Iterator<Enumerator> iterator = corbaenum.getEnumerator().iterator();
        while (iterator.hasNext()) {
            Enumerator enumerator = iterator.next();
            caselist.add(enumerator.getValue());
        }
    } else if (SUPPORTEDDISTYPES.contains(disctype.getQName().getLocalPart())) {
        if (disctype.getQName().getLocalPart().equals("long") || disctype.getQName().getLocalPart().equals("short")) {
            for (int i = 0; i < fields.size(); i++) {
                caselist.add(Integer.toString(i));
            }
        } else if (disctype.getQName().getLocalPart().equals("char")) {
            for (int i = 0; i < fields.size(); i++) {
                caselist.add(Integer.toString(i));
            }
        } else if (disctype.getQName().getLocalPart().equals("char")) {
            for (int i = 0; i < fields.size(); i++) {
                caselist.add(Integer.toString(i));
            }
        } else if (disctype.getQName().getLocalPart().equals("boolean")) {
            if (fields.size() == 2) {
                caselist.add("TRUE");
                caselist.add("FALSE");
            } else if (fields.size() == 1) {
                caselist.add("TRUE");
            } else {
                String msg = "Discriminator Type doesnt match number of Choices in Union:" + name;
                LOG.log(Level.WARNING, msg);
            }
        }
    }
    WSDLTypes.processUnionBranches(corbaUnion, fields, caselist);
    return corbaUnion;
}
Also used : Enum(org.apache.cxf.binding.corba.wsdl.Enum) QName(javax.xml.namespace.QName) XmlSchemaElement(org.apache.ws.commons.schema.XmlSchemaElement) ArrayList(java.util.ArrayList) XmlSchemaParticle(org.apache.ws.commons.schema.XmlSchemaParticle) Union(org.apache.cxf.binding.corba.wsdl.Union) XmlSchemaSequence(org.apache.ws.commons.schema.XmlSchemaSequence) CorbaType(org.apache.cxf.binding.corba.wsdl.CorbaType) MemberType(org.apache.cxf.binding.corba.wsdl.MemberType) Enumerator(org.apache.cxf.binding.corba.wsdl.Enumerator) XmlSchemaSequenceMember(org.apache.ws.commons.schema.XmlSchemaSequenceMember) XmlSchemaChoice(org.apache.ws.commons.schema.XmlSchemaChoice)

Example 7 with Enum

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

the class WSDLToIDLAction method createType.

protected IdlType createType(QName idlType, String[] name, CorbaType corbaType) throws Exception {
    if (idlType.getLocalPart().equals("CORBA.Object")) {
        return IdlInterface.create(null, "Object");
    }
    CorbaType corbaTypeImpl = corbaType;
    if (corbaTypeImpl == null) {
        corbaTypeImpl = getCorbaType(idlType);
    }
    if (corbaTypeImpl == null) {
        String msgStr = "Type " + idlType.getLocalPart() + " not found.";
        org.apache.cxf.common.i18n.Message msg = new org.apache.cxf.common.i18n.Message(msgStr, LOG);
        throw new Exception(msg.toString());
    }
    IdlScopeBase scope = root;
    StringBuilder dotScopedName = new StringBuilder("");
    for (int i = 0; i < name.length - 1; ++i) {
        dotScopedName.append(name[i]);
        // name array.
        if ("CORBA".equals(dotScopedName.toString()) && name.length == 2 && i == 0 && name[1].equals("Object")) {
            break;
        }
        IdlDefn idlDef = scope.lookup(name[i]);
        if (idlDef == null) {
            // Before creating module, check to see if a Corba type
            // represent this name aleady exists.
            // For example if type is a.b.c and we are about to create
            // module b, look to see if a.b
            // is an interface that needs to be processed
            QName qname = new QName(corbaTypeImpl.getType().getNamespaceURI(), dotScopedName.toString());
            // Check to see if CORBAType exists. If so, create type for it
            // otherwise
            // create module for this scope
            CorbaType possibleCorbaType = getCorbaType(qname);
            if (possibleCorbaType != null) {
                idlDef = findType(qname);
            }
            if (idlDef == null) {
                idlDef = IdlModule.create(scope, name[i]);
                scope.addToScope(idlDef);
            }
        }
        dotScopedName.append(".");
        scope = (IdlScopeBase) idlDef;
    }
    IdlType result = null;
    String local = name[name.length - 1];
    if (corbaTypeImpl instanceof Enum) {
        result = createEnum((Enum) corbaTypeImpl, scope, local);
    } else if (corbaTypeImpl instanceof Sequence) {
        result = createSequence((Sequence) corbaTypeImpl, scope, local);
    } else if (corbaTypeImpl instanceof Anonsequence) {
        result = createAnonSequence((Anonsequence) corbaTypeImpl, scope, local);
    } else if (corbaTypeImpl instanceof org.apache.cxf.binding.corba.wsdl.Exception) {
        result = createIdlException((org.apache.cxf.binding.corba.wsdl.Exception) corbaTypeImpl, scope, local);
    } else if (corbaTypeImpl instanceof Struct) {
        result = createStruct((Struct) corbaTypeImpl, scope, local);
    } else if (corbaTypeImpl instanceof Union) {
        result = createUnion((Union) corbaTypeImpl, scope, local);
    } else if (corbaTypeImpl instanceof Alias) {
        result = createTypedef((Alias) corbaTypeImpl, scope, local);
    } else if (corbaTypeImpl instanceof Array) {
        result = createArray((Array) corbaTypeImpl, scope, local);
    } else if (corbaTypeImpl instanceof Anonarray) {
        result = createAnonArray((Anonarray) corbaTypeImpl, scope, local);
    } else if (corbaTypeImpl instanceof Fixed) {
        result = createFixed((Fixed) corbaTypeImpl, scope, local);
    } else if (corbaTypeImpl instanceof Anonfixed) {
        result = createAnonFixed((Anonfixed) corbaTypeImpl, scope, local);
    } else if (corbaTypeImpl instanceof Const) {
        result = createConst((Const) corbaTypeImpl, scope, local);
    } else {
        result = checkAnon(corbaTypeImpl, scope, local);
    }
    if (result == null && corbaTypeImpl instanceof org.apache.cxf.binding.corba.wsdl.Object) {
        result = createInterface((org.apache.cxf.binding.corba.wsdl.Object) corbaTypeImpl, scope, local);
    }
    return result;
}
Also used : IdlEnum(org.apache.cxf.tools.corba.common.idltypes.IdlEnum) Enum(org.apache.cxf.binding.corba.wsdl.Enum) IdlString(org.apache.cxf.tools.corba.common.idltypes.IdlString) IdlType(org.apache.cxf.tools.corba.common.idltypes.IdlType) Union(org.apache.cxf.binding.corba.wsdl.Union) IdlUnion(org.apache.cxf.tools.corba.common.idltypes.IdlUnion) IdlStruct(org.apache.cxf.tools.corba.common.idltypes.IdlStruct) Struct(org.apache.cxf.binding.corba.wsdl.Struct) Anonarray(org.apache.cxf.binding.corba.wsdl.Anonarray) IdlFixed(org.apache.cxf.tools.corba.common.idltypes.IdlFixed) IdlAnonFixed(org.apache.cxf.tools.corba.common.idltypes.IdlAnonFixed) Fixed(org.apache.cxf.binding.corba.wsdl.Fixed) QName(javax.xml.namespace.QName) IdlDefn(org.apache.cxf.tools.corba.common.idltypes.IdlDefn) Const(org.apache.cxf.binding.corba.wsdl.Const) IdlConst(org.apache.cxf.tools.corba.common.idltypes.IdlConst) IdlScopeBase(org.apache.cxf.tools.corba.common.idltypes.IdlScopeBase) IdlAnonSequence(org.apache.cxf.tools.corba.common.idltypes.IdlAnonSequence) Sequence(org.apache.cxf.binding.corba.wsdl.Sequence) IdlSequence(org.apache.cxf.tools.corba.common.idltypes.IdlSequence) IdlException(org.apache.cxf.tools.corba.common.idltypes.IdlException) IdlAnonArray(org.apache.cxf.tools.corba.common.idltypes.IdlAnonArray) Array(org.apache.cxf.binding.corba.wsdl.Array) IdlArray(org.apache.cxf.tools.corba.common.idltypes.IdlArray) Anonfixed(org.apache.cxf.binding.corba.wsdl.Anonfixed) CorbaType(org.apache.cxf.binding.corba.wsdl.CorbaType) Alias(org.apache.cxf.binding.corba.wsdl.Alias) Anonsequence(org.apache.cxf.binding.corba.wsdl.Anonsequence)

Example 8 with Enum

use of org.apache.cxf.binding.corba.wsdl.Enum 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)

Example 9 with Enum

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

the class CorbaObjectWriter method writeEnum.

// -- complex types --
public void writeEnum(CorbaEnumHandler enumHandler) throws CorbaBindingException {
    Enum enumType = (Enum) enumHandler.getType();
    String enumLabel = enumHandler.getValue();
    List<Enumerator> enumerators = enumType.getEnumerator();
    for (int i = 0; i < enumerators.size(); ++i) {
        if (enumerators.get(i).getValue().equals(enumLabel)) {
            stream.write_long(i);
            return;
        }
    }
    throw new CorbaBindingException("CorbaObjectWriter: unable to find enumeration label");
}
Also used : Enum(org.apache.cxf.binding.corba.wsdl.Enum) CorbaBindingException(org.apache.cxf.binding.corba.CorbaBindingException) Enumerator(org.apache.cxf.binding.corba.wsdl.Enumerator)

Example 10 with Enum

use of org.apache.cxf.binding.corba.wsdl.Enum 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 {
            String enumLabel = null;
            for (Iterator<Enumerator> enumIter = enumerators.iterator(); enumIter.hasNext(); ) {
                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)

Aggregations

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