Search in sources :

Example 66 with CorbaType

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

the class IDLToWSDLProcessor method cleanUpTypeMap.

public void cleanUpTypeMap(TypeMappingType typeMap) {
    List<CorbaType> types = typeMap.getStructOrExceptionOrUnion();
    if (types != null) {
        for (int i = 0; i < types.size(); i++) {
            CorbaType type = types.get(i);
            if (type.getQName() != null) {
                type.setName(type.getQName().getLocalPart());
                type.setQName(null);
            }
        }
    }
}
Also used : CorbaType(org.apache.cxf.binding.corba.wsdl.CorbaType)

Example 67 with CorbaType

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

the class IDLToWSDLProcessor method addTypeMapSchemaImports.

public void addTypeMapSchemaImports(Definition def, WSDLASTVisitor visitor) {
    List<CorbaType> types = visitor.getTypeMap().getStructOrExceptionOrUnion();
    ModuleToNSMapper mapper = visitor.getModuleToNSMapper();
    WSDLSchemaManager manager = visitor.getManager();
    Collection<String> namespaces = CastUtils.cast(def.getNamespaces().values());
    Set<Map.Entry<String, String>> userModuleMappings = mapper.getUserMapping().entrySet();
    if (types != null) {
        for (int i = 0; i < types.size(); i++) {
            CorbaType type = types.get(i);
            QName schemaType = type.getType();
            if (schemaType != null) {
                String typeNamespace = schemaType.getNamespaceURI();
                try {
                    // a remote location.
                    if (!namespaces.contains(typeNamespace) && typeNamespace.equals(ReferenceConstants.WSADDRESSING_NAMESPACE)) {
                        // build up the ws-addressing schema import
                        Schema wsdlSchema = (Schema) def.getExtensionRegistry().createExtension(Types.class, new QName(Constants.URI_2001_SCHEMA_XSD, "schema"));
                        SchemaImport schemaimport = wsdlSchema.createImport();
                        schemaimport.setNamespaceURI(ReferenceConstants.WSADDRESSING_NAMESPACE);
                        schemaimport.setSchemaLocationURI(ReferenceConstants.WSADDRESSING_LOCATION);
                        wsdlSchema.addImport(schemaimport);
                        // add the import and the prefix to the definition
                        def.getTypes().addExtensibilityElement(wsdlSchema);
                        CastUtils.cast(def.getNamespaces(), String.class, String.class).put(ReferenceConstants.WSADDRESSING_PREFIX, typeNamespace);
                    } else if (!namespaces.contains(typeNamespace)) {
                        String prefix = getModulePrefixForNamespace(userModuleMappings, mapper, typeNamespace);
                        // prefix = mapper.mapNSToPrefix(typeNamespace);
                        XmlSchema schema = manager.getXmlSchema(typeNamespace);
                        // TODO: REVISIT - Is this the only way we can create the file name for the
                        // imported schema?
                        String importFile = visitor.getOutputDir() + System.getProperty("file.separator") + prefix + ".xsd";
                        manager.addWSDLSchemaImport(def, typeNamespace, importFile);
                        manager.getImportedXmlSchemas().put(new File(importFile), schema);
                        CastUtils.cast(def.getNamespaces(), String.class, String.class).put(prefix, typeNamespace);
                    }
                } catch (Exception ex) {
                    throw new ToolException("Unable to add schema import for namespace" + typeNamespace);
                }
            }
        }
    }
}
Also used : Types(javax.wsdl.Types) SchemaImport(javax.wsdl.extensions.schema.SchemaImport) QName(javax.xml.namespace.QName) XmlSchema(org.apache.ws.commons.schema.XmlSchema) Schema(javax.wsdl.extensions.schema.Schema) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) ToolException(org.apache.cxf.tools.common.ToolException) Entry(java.util.Map.Entry) CorbaType(org.apache.cxf.binding.corba.wsdl.CorbaType) XmlSchema(org.apache.ws.commons.schema.XmlSchema) ToolException(org.apache.cxf.tools.common.ToolException) File(java.io.File)

Example 68 with CorbaType

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

the class ExceptionVisitor method visit.

public void visit(AST node) {
    // <exception_dcl> ::= "exception" <identifier> "{" <member>* "}"
    // <member> ::= <type_spec> <declarators> ";"
    // <type_spec> visited by TypesVisitor
    // Following should be visited by a separate visitor
    // <declarators> ::= <declarator> { "," <declarator> }*
    // <declarator> ::= <simple_declarator>
    // | <complex_declarator>
    // <simple_declarator> ::= <identifier>
    // <complex_declarator> ::= <array_declarator>
    // <array_declarator> ::= <identifier> <fixed_array_size>+
    // <fixed_array_size> ::= "[" <positive_int_const> "]"
    AST identifierNode = node.getFirstChild();
    Scope exceptionScope = new Scope(getScope(), identifierNode);
    // xmlschema:exception
    Scope scopedName = new Scope(getScope(), identifierNode);
    String exceptionName = mapper.mapToQName(scopedName);
    XmlSchemaElement element = new XmlSchemaElement(schema, true);
    element.setName(mapper.mapToQName(scopedName));
    String exceptionTypeName = exceptionName + TYPE_SUFFIX;
    XmlSchemaComplexType complexType = new XmlSchemaComplexType(schema, true);
    complexType.setName(exceptionTypeName);
    // complexType.setQName(new QName(schema.getTargetNamespace(), exceptionTypeName));
    XmlSchemaSequence sequence = new XmlSchemaSequence();
    complexType.setParticle(sequence);
    element.setSchemaTypeName(complexType.getQName());
    // corba:exception
    org.apache.cxf.binding.corba.wsdl.Exception exception = new org.apache.cxf.binding.corba.wsdl.Exception();
    exception.setQName(new QName(typeMap.getTargetNamespace(), exceptionName));
    exception.setType(complexType.getQName());
    exception.setRepositoryID(scopedName.toIDLRepositoryID());
    // exception members
    AST memberTypeNode = identifierNode.getNextSibling();
    while (memberTypeNode != null) {
        AST memberNode = TypesUtils.getCorbaTypeNameNode(memberTypeNode);
        TypesVisitor visitor = new TypesVisitor(exceptionScope, definition, schema, wsdlVisitor, null);
        visitor.visit(memberTypeNode);
        XmlSchemaType stype = visitor.getSchemaType();
        CorbaType ctype = visitor.getCorbaType();
        Scope fullyQualifiedName = visitor.getFullyQualifiedName();
        // needed for anonymous arrays in exceptions
        if (ArrayVisitor.accept(memberNode)) {
            Scope anonScope = new Scope(exceptionScope, TypesUtils.getCorbaTypeNameNode(memberTypeNode));
            ArrayVisitor arrayVisitor = new ArrayVisitor(anonScope, definition, schema, wsdlVisitor, null, fullyQualifiedName);
            arrayVisitor.setSchemaType(stype);
            arrayVisitor.setCorbaType(ctype);
            arrayVisitor.visit(memberNode);
            stype = arrayVisitor.getSchemaType();
            ctype = arrayVisitor.getCorbaType();
        }
        XmlSchemaElement member = createElementType(memberNode, stype, fullyQualifiedName);
        sequence.getItems().add(member);
        MemberType memberType = createMemberType(memberNode, ctype, fullyQualifiedName);
        exception.getMember().add(memberType);
        memberTypeNode = memberNode.getNextSibling();
    }
    // add exception to corba typemap
    typeMap.getStructOrExceptionOrUnion().add(exception);
    setSchemaType(complexType);
    setCorbaType(exception);
    createFaultMessage(element.getQName());
}
Also used : AST(antlr.collections.AST) XmlSchemaElement(org.apache.ws.commons.schema.XmlSchemaElement) QName(javax.xml.namespace.QName) XmlSchemaType(org.apache.ws.commons.schema.XmlSchemaType) XmlSchemaSequence(org.apache.ws.commons.schema.XmlSchemaSequence) CorbaType(org.apache.cxf.binding.corba.wsdl.CorbaType) MemberType(org.apache.cxf.binding.corba.wsdl.MemberType) XmlSchemaComplexType(org.apache.ws.commons.schema.XmlSchemaComplexType)

Example 69 with CorbaType

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

the class FixedVisitor method visit.

public void visit(AST fixedNode) {
    // "typedef" <type_declarator>
    // <type_declarator> ::= <type_spec> <declarators>
    // <type_spec> ::= <simple_type_spec>
    // | <constr_type_spec>
    // <simple_type_spec> ::= <base_type_spec>
    // | <template_type_spec>
    // | <scoped_name>
    // <base_type_spec> ::= ... omitted (integer, char, octect, etc)
    // <template_type_spec> ::= <sequence_type>
    // | <string_type>
    // | <wstring_type>
    // | <fixed_pt_type>
    // <constr_type_spec> ::= <struct_type>
    // | <union_type>
    // | <enum_type>
    // <declarators> ::= <declarator> {"," <declarator>}*
    // <declarator> ::= <simple_declarator>
    // | <complex_declarator>
    // <simple_declarator> ::= <identifier>
    // <complex_declarator> ::= <array_declarator>
    // <array_declarator> ::= <identifier> <fixed_array_size>+
    // <fixed_array_size> ::= "[" <positive_int_const> "]"
    AST digitsNode = fixedNode.getFirstChild();
    AST scaleNode = digitsNode.getNextSibling();
    final Scope scopedName;
    if (identifierNode == null) {
        scopedName = TypesUtils.generateAnonymousScopedName(getScope(), schema);
    } else {
        scopedName = new Scope(getScope(), identifierNode);
    }
    // validate digits and scale
    Long digits = Long.valueOf(digitsNode.toString());
    Long scale = Long.valueOf(scaleNode.toString());
    if (digits < 1 || digits > 31) {
        // throw IllegalIDLException();
        System.out.println("Digits cannot be greater than 31");
        return;
    }
    if (scale.compareTo(digits) > 0) {
        // throw IllegalIDLException();
        System.out.println("Scale cannot be greater than digits");
        return;
    }
    // xmlschema:fixed
    XmlSchemaSimpleType fixedSimpleType = new XmlSchemaSimpleType(schema, true);
    XmlSchemaSimpleTypeRestriction fixedRestriction = new XmlSchemaSimpleTypeRestriction();
    fixedRestriction.setBaseTypeName(Constants.XSD_DECIMAL);
    XmlSchemaTotalDigitsFacet fixedTotalDigits = new XmlSchemaTotalDigitsFacet();
    fixedTotalDigits.setValue(digitsNode.toString());
    XmlSchemaFractionDigitsFacet fixedFractionDigits = new XmlSchemaFractionDigitsFacet();
    fixedFractionDigits.setValue(scaleNode.toString());
    fixedFractionDigits.setFixed(true);
    fixedRestriction.getFacets().add(fixedTotalDigits);
    fixedRestriction.getFacets().add(fixedFractionDigits);
    fixedSimpleType.setName(mapper.mapToQName(scopedName));
    fixedSimpleType.setContent(fixedRestriction);
    // add xmlschema:fixed
    setSchemaType(fixedSimpleType);
    final CorbaType type;
    if (identifierNode != null) {
        // corba:fixed
        Fixed corbaFixed = new Fixed();
        corbaFixed.setQName(new QName(typeMap.getTargetNamespace(), scopedName.toString()));
        corbaFixed.setDigits(digits);
        corbaFixed.setScale(scale);
        corbaFixed.setRepositoryID(scopedName.toIDLRepositoryID());
        // corbaFixed.setType(Constants.XSD_DECIMAL);
        corbaFixed.setType(fixedSimpleType.getQName());
        type = corbaFixed;
    } else {
        // corba:anonfixed
        Anonfixed corbaFixed = new Anonfixed();
        corbaFixed.setQName(new QName(typeMap.getTargetNamespace(), scopedName.toString()));
        corbaFixed.setDigits(digits);
        corbaFixed.setScale(scale);
        // corbaFixed.setType(Constants.XSD_DECIMAL);
        corbaFixed.setType(fixedSimpleType.getQName());
        typeMap.getStructOrExceptionOrUnion().add(corbaFixed);
        type = corbaFixed;
    }
    // add corba:fixed
    setCorbaType(type);
}
Also used : Anonfixed(org.apache.cxf.binding.corba.wsdl.Anonfixed) AST(antlr.collections.AST) XmlSchemaTotalDigitsFacet(org.apache.ws.commons.schema.XmlSchemaTotalDigitsFacet) XmlSchemaFractionDigitsFacet(org.apache.ws.commons.schema.XmlSchemaFractionDigitsFacet) CorbaType(org.apache.cxf.binding.corba.wsdl.CorbaType) XmlSchemaSimpleType(org.apache.ws.commons.schema.XmlSchemaSimpleType) QName(javax.xml.namespace.QName) XmlSchemaSimpleTypeRestriction(org.apache.ws.commons.schema.XmlSchemaSimpleTypeRestriction) Fixed(org.apache.cxf.binding.corba.wsdl.Fixed)

Example 70 with CorbaType

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

the class ArrayVisitor method visit.

public void visit(AST node) {
    // <array_declarator> ::= <identifier> <fixed_array_size>+
    // <fixed_array_size> ::= "[" <positive_int_const> "]"
    AST firstSizeNode = node.getFirstChild();
    AST nextSizeNode = firstSizeNode.getNextSibling();
    final Types result;
    // process all anonarrays, skip first array as it might not be anonymous
    if (nextSizeNode != null) {
        result = doAnonarray(nextSizeNode, getSchemaType(), getCorbaType());
    } else {
        result = new Types();
        result.setSchemaType(getSchemaType());
        result.setCorbaType(getCorbaType());
        result.setFullyQualifiedName(getFullyQualifiedName());
    }
    // process first array
    Long size = Long.valueOf(firstSizeNode.toString());
    final XmlSchemaType stype;
    final CorbaType ctype;
    if (identifierNode != null) {
        Scope scopedName = getScope();
        if (result.getSchemaType() != null) {
            stype = generateSchemaArray(scopedName, size, result.getSchemaType(), result.getFullyQualifiedName());
        } else {
            stype = generateSchemaArray(scopedName, size, null, result.getFullyQualifiedName());
        }
        if (result.getCorbaType() != null) {
            ctype = generateCorbaArray(scopedName, size, result.getCorbaType(), stype, getFullyQualifiedName());
        } else {
            ctype = generateCorbaArray(scopedName, size, null, stype, getFullyQualifiedName());
        }
    } else {
        // anonymous array
        Scope scopedName = TypesUtils.generateAnonymousScopedName(getScope(), schema);
        if (result.getSchemaType() != null) {
            stype = generateSchemaArray(scopedName, size, result.getSchemaType(), getFullyQualifiedName());
        } else {
            stype = generateSchemaArray(scopedName, size, null, getFullyQualifiedName());
        }
        if (result.getCorbaType() != null) {
            ctype = generateCorbaAnonarray(scopedName.toString(), size, result.getCorbaType(), stype, getFullyQualifiedName());
        } else {
            ctype = generateCorbaAnonarray(scopedName.toString(), size, null, stype, getFullyQualifiedName());
        }
    }
    // add corbaType
    typeMap.getStructOrExceptionOrUnion().add(ctype);
    setSchemaType(stype);
    setCorbaType(ctype);
}
Also used : AST(antlr.collections.AST) CorbaType(org.apache.cxf.binding.corba.wsdl.CorbaType) XmlSchemaType(org.apache.ws.commons.schema.XmlSchemaType)

Aggregations

CorbaType (org.apache.cxf.binding.corba.wsdl.CorbaType)72 QName (javax.xml.namespace.QName)45 XmlSchemaType (org.apache.ws.commons.schema.XmlSchemaType)23 MemberType (org.apache.cxf.binding.corba.wsdl.MemberType)13 AST (antlr.collections.AST)9 XmlSchemaElement (org.apache.ws.commons.schema.XmlSchemaElement)9 TypeMappingType (org.apache.cxf.binding.corba.wsdl.TypeMappingType)8 Test (org.junit.Test)8 XmlSchemaSequence (org.apache.ws.commons.schema.XmlSchemaSequence)7 Alias (org.apache.cxf.binding.corba.wsdl.Alias)6 Anonsequence (org.apache.cxf.binding.corba.wsdl.Anonsequence)6 Sequence (org.apache.cxf.binding.corba.wsdl.Sequence)6 Struct (org.apache.cxf.binding.corba.wsdl.Struct)6 Union (org.apache.cxf.binding.corba.wsdl.Union)6 File (java.io.File)5 Definition (javax.wsdl.Definition)5 ArrayList (java.util.ArrayList)4 Anonarray (org.apache.cxf.binding.corba.wsdl.Anonarray)4 Anonstring (org.apache.cxf.binding.corba.wsdl.Anonstring)4 Array (org.apache.cxf.binding.corba.wsdl.Array)4