Search in sources :

Example 86 with XmlSchema

use of org.apache.ws.commons.schema.XmlSchema in project cxf by apache.

the class IDLToWSDLProcessor method writeImportedDefinitionsAndSchemas.

private void writeImportedDefinitionsAndSchemas(WSDLASTVisitor visitor) throws Exception {
    Map<File, Definition> defns = visitor.getManager().getImportedWSDLDefinitions();
    Map<File, XmlSchema> schemas = visitor.getManager().getImportedXmlSchemas();
    if (importDefnWriters != null) {
        assert importDefnWriters.size() == defns.size();
    }
    if (importSchemaWriters != null) {
        assert importSchemaWriters.size() == schemas.size();
    }
    for (Entry<File, Definition> entry : defns.entrySet()) {
        Writer writer = null;
        if (importDefnWriters != null) {
            writer = getOutputWriter(importDefnWriters.get(entry.getValue().getTargetNamespace()));
        }
        if (writer == null) {
            writer = getOutputWriter(entry.getKey());
        }
        visitor.writeDefinition(entry.getValue(), writer);
        writer.close();
    }
    for (Entry<File, XmlSchema> entry : schemas.entrySet()) {
        Writer writer = null;
        if (importSchemaWriters != null) {
            writer = getOutputWriter(importSchemaWriters.get(entry.getValue().getTargetNamespace()));
        }
        if (writer == null) {
            writer = getOutputWriter(entry.getKey());
        }
        visitor.writeSchema(entry.getValue(), writer);
        writer.close();
    }
}
Also used : XmlSchema(org.apache.ws.commons.schema.XmlSchema) Definition(javax.wsdl.Definition) File(java.io.File) Writer(java.io.Writer)

Example 87 with XmlSchema

use of org.apache.ws.commons.schema.XmlSchema 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 88 with XmlSchema

use of org.apache.ws.commons.schema.XmlSchema in project cxf by apache.

the class ObjectReferenceVisitor method isDuplicateReference.

private void isDuplicateReference(QName referenceName, QName bindingName, Scope refScope, XmlSchemaType wsaType, AST node) {
    XmlSchema refSchema = null;
    if (!mapper.isDefaultMapping()) {
        String tns = mapper.map(refScope.getParent());
        String refSchemaFileName = getWsdlVisitor().getOutputDir() + System.getProperty("file.separator") + refScope.getParent().toString("_") + ".xsd";
        refSchema = manager.getXmlSchema(tns);
        if (refSchema == null) {
            refSchema = manager.createXmlSchema(tns, wsdlVisitor.getSchemas());
        }
        addWSAddressingImport(refSchema);
        manager.addXmlSchemaImport(schema, refSchema, refSchemaFileName);
    } else {
        refSchema = schema;
    }
    // we have, then there is no need to add it to the schema again.
    if (!isReferenceSchemaTypeDefined(referenceName, refSchema)) {
        // We need to add a new element definition to the schema section of our WSDL.
        // For custom endpoint types, this should contain an annotation which points
        // to the binding which will be used for this endpoint type.
        XmlSchemaElement refElement = new XmlSchemaElement(schema, true);
        refElement.setName(referenceName.getLocalPart());
        refElement.setSchemaType(wsaType);
        refElement.setSchemaTypeName(wsaType.getQName());
        // Create an annotation which contains the CORBA binding for the element
        XmlSchemaAnnotation annotation = new XmlSchemaAnnotation();
        XmlSchemaAppInfo appInfo = new XmlSchemaAppInfo();
        try {
            DocumentBuilder db = DocumentBuilderFactory.newInstance().newDocumentBuilder();
            Document doc = db.newDocument();
            Element el = doc.createElement("appinfo");
            el.setTextContent("corba:binding=" + bindingName.getLocalPart());
            // TODO: This is correct but the appinfo markup is never added to the
            // schema.  Investigate.
            appInfo.setMarkup(el.getChildNodes());
        } catch (ParserConfigurationException ex) {
            throw new RuntimeException("[ObjectReferenceVisitor: error creating endpoint schema]");
        }
        annotation.getItems().add(appInfo);
        refElement.setAnnotation(annotation);
    }
}
Also used : XmlSchemaAnnotation(org.apache.ws.commons.schema.XmlSchemaAnnotation) XmlSchema(org.apache.ws.commons.schema.XmlSchema) DocumentBuilder(javax.xml.parsers.DocumentBuilder) XmlSchemaElement(org.apache.ws.commons.schema.XmlSchemaElement) XmlSchemaElement(org.apache.ws.commons.schema.XmlSchemaElement) Element(org.w3c.dom.Element) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) Document(org.w3c.dom.Document) XmlSchemaAppInfo(org.apache.ws.commons.schema.XmlSchemaAppInfo)

Example 89 with XmlSchema

use of org.apache.ws.commons.schema.XmlSchema in project cxf by apache.

the class ObjectReferenceVisitor method visitCustomTypeObjectReference.

private void visitCustomTypeObjectReference(AST node) {
    QName bindingName = null;
    QName referenceName = null;
    String repositoryID = null;
    Scope currentScope = getScope();
    Scope customScope = null;
    if ((node.getFirstChild() == null) || (node.getFirstChild() != null && node.getFirstChild().getType() != IDLTokenTypes.SCOPEOP)) {
        while (bindingName == null && currentScope != currentScope.getParent()) {
            if (ScopedNameVisitor.isFullyScopedName(node)) {
                customScope = ScopedNameVisitor.getFullyScopedName(currentScope, node);
            } else {
                customScope = new Scope(currentScope, node);
            }
            if (mapper.isDefaultMapping()) {
                referenceName = new QName(schema.getTargetNamespace(), customScope.toString() + "Ref");
            } else {
                String tns = mapper.map(customScope.getParent());
                referenceName = new QName(tns, customScope.tail() + "Ref");
            }
            repositoryID = customScope.toIDLRepositoryID();
            bindingName = getBindingQNameByID(definition, repositoryID, objRefWsdlVisitor);
            currentScope = currentScope.getParent();
        }
    }
    if (bindingName == null) {
        // Global scope is our last chance to resolve the node
        if (ScopedNameVisitor.isFullyScopedName(node)) {
            customScope = ScopedNameVisitor.getFullyScopedName(new Scope(), node);
            if (mapper.isDefaultMapping()) {
                referenceName = new QName(schema.getTargetNamespace(), customScope.toString() + "Ref");
            } else {
                String tns = mapper.map(customScope.getParent());
                referenceName = new QName(tns, customScope.tail() + "Ref");
            }
        } else {
            // customScope = currentScope;
            customScope = new Scope(new Scope(), node);
            if (mapper.isDefaultMapping()) {
                referenceName = new QName(schema.getTargetNamespace(), customScope.toString() + "Ref");
            } else {
                String tns = mapper.map(customScope.getParent());
                referenceName = new QName(tns, customScope.tail() + "Ref");
            }
        }
        repositoryID = customScope.toIDLRepositoryID();
        bindingName = getBindingQNameByID(definition, repositoryID, objRefWsdlVisitor);
        if (bindingName == null) {
            // check bindingName with prefix
            customScope.setPrefix(objRefWsdlVisitor.getPragmaPrefix());
            repositoryID = customScope.toIDLRepositoryID();
            bindingName = getBindingQNameByID(definition, repositoryID, objRefWsdlVisitor);
        }
    }
    if (bindingName == null) {
        // We need to have a binding for this kind of object reference to work
        throw new RuntimeException("[ObjectReferenceVisitor: No binding available for endpoint]");
    }
    // Create a schema namespace for WS addressing and use it to create an endpoint
    // reference type.  This will be used as the type for our endpoint reference.
    XmlSchema[] scs = schemas.getXmlSchema(ReferenceConstants.WSADDRESSING_NAMESPACE);
    XmlSchema wsaSchema = null;
    if (scs != null) {
        for (XmlSchema sc : scs) {
            if (ReferenceConstants.WSADDRESSING_NAMESPACE.equals(sc.getTargetNamespace())) {
                wsaSchema = sc;
                break;
            }
        }
    }
    if (wsaSchema == null) {
        wsaSchema = new XmlSchema(ReferenceConstants.WSADDRESSING_NAMESPACE, schemas);
    }
    XmlSchemaType wsaType = new XmlSchemaSimpleType(wsaSchema, true);
    wsaType.setName(ReferenceConstants.WSADDRESSING_LOCAL_NAME);
    // Check to see if we have already defined an element for this reference type.  If
    // we have, then there is no need to add it to the schema again.
    isDuplicateReference(referenceName, bindingName, customScope, wsaType, node);
    setSchemaType(wsaType);
    // Build and assign the corba:object to the visitor
    Object corbaObject = new Object();
    corbaObject.setBinding(bindingName);
    corbaObject.setQName(new QName(typeMap.getTargetNamespace(), customScope.toString()));
    corbaObject.setRepositoryID(repositoryID);
    corbaObject.setType(wsaType.getQName());
    setCorbaType(corbaObject);
    // type once.
    if (!isReferenceCORBATypeDefined(corbaObject.getQName())) {
        typeMap.getStructOrExceptionOrUnion().add(corbaObject);
    }
}
Also used : XmlSchema(org.apache.ws.commons.schema.XmlSchema) QName(javax.xml.namespace.QName) XmlSchemaSimpleType(org.apache.ws.commons.schema.XmlSchemaSimpleType) Object(org.apache.cxf.binding.corba.wsdl.Object) XmlSchemaObject(org.apache.ws.commons.schema.XmlSchemaObject) XmlSchemaType(org.apache.ws.commons.schema.XmlSchemaType)

Example 90 with XmlSchema

use of org.apache.ws.commons.schema.XmlSchema in project cxf by apache.

the class ParamDeferredAction method execute.

public void execute(XmlSchemaType stype, CorbaTypeImpl ctype) {
    if (param != null) {
        param.setIdltype(ctype.getQName());
    }
    if (element != null) {
        element.setSchemaTypeName(stype.getQName());
        if (stype.getQName().equals(ReferenceConstants.WSADDRESSING_TYPE)) {
            element.setNillable(true);
        }
        if (manager == null) {
            return;
        }
        // Now we need to make sure we are importing any types we need
        XmlSchema importedSchema = null;
        if (stype.getQName().getNamespaceURI().equals(ReferenceConstants.WSADDRESSING_NAMESPACE)) {
            boolean alreadyImported = false;
            for (XmlSchemaExternal ext : schema.getExternals()) {
                if (ext instanceof XmlSchemaImport) {
                    XmlSchemaImport schemaImport = (XmlSchemaImport) ext;
                    if (schemaImport.getNamespace().equals(ReferenceConstants.WSADDRESSING_NAMESPACE)) {
                        alreadyImported = true;
                        break;
                    }
                }
            }
            if (!alreadyImported) {
                // We need to add an import statement to include the WS addressing types
                XmlSchemaImport wsaImport = new XmlSchemaImport(schema);
                wsaImport.setNamespace(ReferenceConstants.WSADDRESSING_NAMESPACE);
                wsaImport.setSchemaLocation(ReferenceConstants.WSADDRESSING_LOCATION);
            }
        } else if (!stype.getQName().getNamespaceURI().equals(schema.getTargetNamespace())) {
            importedSchema = manager.getXmlSchema(mapper.map(typeScope));
            manager.addXmlSchemaImport(schema, importedSchema, typeScope.toString("_"));
        }
    }
}
Also used : XmlSchemaExternal(org.apache.ws.commons.schema.XmlSchemaExternal) XmlSchema(org.apache.ws.commons.schema.XmlSchema) XmlSchemaImport(org.apache.ws.commons.schema.XmlSchemaImport)

Aggregations

XmlSchema (org.apache.ws.commons.schema.XmlSchema)116 QName (javax.xml.namespace.QName)61 XmlSchemaElement (org.apache.ws.commons.schema.XmlSchemaElement)52 Test (org.junit.Test)49 FeatureMetacardType (org.codice.ddf.spatial.ogc.wfs.catalog.common.FeatureMetacardType)37 XmlSchemaSimpleType (org.apache.ws.commons.schema.XmlSchemaSimpleType)32 XmlSchemaComplexType (org.apache.ws.commons.schema.XmlSchemaComplexType)23 XmlSchemaType (org.apache.ws.commons.schema.XmlSchemaType)18 SchemaInfo (org.apache.cxf.service.model.SchemaInfo)17 ArrayList (java.util.ArrayList)14 XmlSchemaSequence (org.apache.ws.commons.schema.XmlSchemaSequence)13 Element (org.w3c.dom.Element)12 AbstractAegisTest (org.apache.cxf.aegis.AbstractAegisTest)10 XmlSchemaCollection (org.apache.ws.commons.schema.XmlSchemaCollection)10 Document (org.w3c.dom.Document)10 HashMap (java.util.HashMap)9 Map (java.util.Map)8 NamespaceMap (org.apache.ws.commons.schema.utils.NamespaceMap)8 List (java.util.List)7 XmlSchemaSequenceMember (org.apache.ws.commons.schema.XmlSchemaSequenceMember)7