Search in sources :

Example 81 with XmlSchema

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

the class WSDLSchemaManager method createXmlSchemaForDefinition.

public XmlSchema createXmlSchemaForDefinition(Definition defn, String schemans, XmlSchemaCollection schemaCol) {
    XmlSchema xmlSchema = createXmlSchema(schemans, schemaCol);
    defnSchemas.put(schemans, xmlSchema);
    return xmlSchema;
}
Also used : XmlSchema(org.apache.ws.commons.schema.XmlSchema)

Example 82 with XmlSchema

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

the class WSDLParameter method findSchemaType.

// This willl search the current schemas and any included
// schemas for the schema type.
private static XmlSchemaType findSchemaType(XmlSchema xmlSchema, QName typeName) {
    XmlSchemaType schemaType = xmlSchema.getTypeByName(typeName);
    if (schemaType == null) {
        for (XmlSchemaExternal ext : xmlSchema.getExternals()) {
            if (ext instanceof XmlSchemaImport) {
                XmlSchemaImport xmlImport = (XmlSchemaImport) ext;
                if (xmlImport.getNamespace().equals(typeName.getNamespaceURI())) {
                    XmlSchema importSchema = xmlImport.getSchema();
                    schemaType = importSchema.getTypeByName(typeName);
                } else {
                    schemaType = findSchemaType(ext.getSchema(), typeName);
                    if (schemaType != null) {
                        return schemaType;
                    }
                }
            }
        }
        if (schemaType != null) {
            return schemaType;
        }
    }
    return schemaType;
}
Also used : XmlSchemaExternal(org.apache.ws.commons.schema.XmlSchemaExternal) XmlSchema(org.apache.ws.commons.schema.XmlSchema) XmlSchemaImport(org.apache.ws.commons.schema.XmlSchemaImport) XmlSchemaType(org.apache.ws.commons.schema.XmlSchemaType)

Example 83 with XmlSchema

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

the class JAXBDataBinding method addedEnumClassToCollector.

// JAXB bug. JAXB ClassNameCollector may not be invoked when generated
// class is an enum. We need to use this method to add the missed file
// to classCollector.
private void addedEnumClassToCollector(SchemaCollection schemaCollection, ClassNameAllocatorImpl allocator) {
    // for (Element schemaElement : schemaList.values()) {
    for (XmlSchema schema : schemaCollection.getXmlSchemas()) {
        String targetNamespace = schema.getTargetNamespace();
        if (StringUtils.isEmpty(targetNamespace)) {
            continue;
        }
        String packageName = context.mapPackageName(targetNamespace);
        if (!addedToClassCollector(packageName)) {
            allocator.assignClassName(packageName, "*");
        }
    }
}
Also used : XmlSchema(org.apache.ws.commons.schema.XmlSchema)

Example 84 with XmlSchema

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

the class ProcessorUtil method isSchemaFormQualified.

public static boolean isSchemaFormQualified(ToolContext context, QName partElement) {
    ServiceInfo serviceInfo = context.get(ServiceInfo.class);
    SchemaCollection schemaCol = serviceInfo.getXmlSchemaCollection();
    XmlSchema schema = schemaCol.getSchemaForElement(partElement);
    if (schema != null) {
        return schema.getElementFormDefault() == XmlSchemaForm.QUALIFIED;
    }
    return false;
}
Also used : ServiceInfo(org.apache.cxf.service.model.ServiceInfo) XmlSchema(org.apache.ws.commons.schema.XmlSchema) SchemaCollection(org.apache.cxf.common.xmlschema.SchemaCollection)

Example 85 with XmlSchema

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

the class WSDLToJavaContainer method generateLocalWSDL.

@SuppressWarnings("unchecked")
private void generateLocalWSDL(ToolContext context) {
    String outputdir = (String) context.get(ToolConstants.CFG_CLASSDIR);
    File wsdlFile = new File(outputdir, (String) context.get(ToolConstants.CFG_WSDLLOCATION));
    Definition def = context.get(Definition.class);
    try {
        // get imported schemas
        int xsdCount = 0;
        SchemaCollection schemas = (SchemaCollection) context.get(ToolConstants.XML_SCHEMA_COLLECTION);
        Map<String, String> sourceMap = new HashMap<>();
        for (XmlSchema imp : schemas.getXmlSchemas()) {
            if (imp.getSourceURI() != null && !imp.getSourceURI().contains(".wsdl#")) {
                String schemaFileName = "schema" + (++xsdCount) + ".xsd";
                sourceMap.put(imp.getTargetNamespace(), schemaFileName);
            }
        }
        // get imported wsdls
        int wsdlImportCount = 0;
        List<Definition> defs = (List<Definition>) context.get(ToolConstants.IMPORTED_DEFINITION);
        Map<String, String> importWSDLMap = new HashMap<>();
        for (Definition importDef : defs) {
            File importedWsdlFile = null;
            if (!StringUtils.isEmpty(importDef.getDocumentBaseURI())) {
                importedWsdlFile = new File(importDef.getDocumentBaseURI());
            } else {
                importedWsdlFile = new File(importDef.getQName().getLocalPart() + ".wsdl");
            }
            if (!FileUtils.isValidFileName(importedWsdlFile.getName())) {
                importedWsdlFile = new File("import" + (++wsdlImportCount) + ".wsdl");
            }
            importWSDLMap.put(importDef.getTargetNamespace(), importedWsdlFile.getName());
        }
        OutputStreamCreator outputStreamCreator = null;
        if (context.get(OutputStreamCreator.class) != null) {
            outputStreamCreator = context.get(OutputStreamCreator.class);
        } else {
            outputStreamCreator = new OutputStreamCreator();
            context.put(OutputStreamCreator.class, outputStreamCreator);
        }
        Writer os = null;
        for (XmlSchema imp : schemas.getXmlSchemas()) {
            if (imp.getSourceURI() != null && !imp.getSourceURI().contains(".wsdl#")) {
                String schemaFileName = sourceMap.get(imp.getTargetNamespace());
                File impfile = new File(wsdlFile.getParentFile(), schemaFileName);
                Element el = imp.getSchemaDocument().getDocumentElement();
                updateImports(el, sourceMap);
                os = new FileWriterUtil(impfile.getParent(), context.get(OutputStreamCreator.class)).getWriter(impfile, StandardCharsets.UTF_8.name());
                StaxUtils.writeTo(el, os, 2);
                os.close();
            }
        }
        // change the import location in wsdl file
        OutputStream wsdloutput = new BufferedOutputStream(Files.newOutputStream(wsdlFile.toPath()));
        WSDLWriter wsdlWriter = WSDLFactory.newInstance().newWSDLWriter();
        LoadingByteArrayOutputStream bout = new LoadingByteArrayOutputStream();
        wsdlWriter.writeWSDL(def, bout);
        Element defEle = StaxUtils.read(bout.createInputStream()).getDocumentElement();
        List<Element> xsdElements = DOMUtils.findAllElementsByTagNameNS(defEle, WSDLConstants.NS_SCHEMA_XSD, "schema");
        for (Element xsdEle : xsdElements) {
            updateImports(xsdEle, sourceMap);
        }
        updateWSDLImports(defEle, importWSDLMap);
        StaxUtils.writeTo(defEle, wsdloutput);
        wsdloutput.close();
        for (Definition importDef : defs) {
            File importWsdlFile = new File(outputdir, importWSDLMap.get(importDef.getTargetNamespace()));
            OutputStream wsdlOs = new BufferedOutputStream(Files.newOutputStream(importWsdlFile.toPath()));
            bout = new LoadingByteArrayOutputStream();
            wsdlWriter.writeWSDL(importDef, bout);
            Element importEle = StaxUtils.read(bout.createInputStream()).getDocumentElement();
            xsdElements = DOMUtils.findAllElementsByTagNameNS(importEle, WSDLConstants.NS_SCHEMA_XSD, "schema");
            for (Element xsdEle : xsdElements) {
                updateImports(xsdEle, sourceMap);
            }
            updateWSDLImports(importEle, importWSDLMap);
            StaxUtils.writeTo(importEle, wsdlOs);
            wsdlOs.close();
        }
    } catch (Exception ex) {
        LOG.log(Level.SEVERE, "FAILED_TO_GEN_LOCAL_WSDL", ex);
        Message msg = new Message("FAILED_TO_GEN_LOCAL_WSDL", LOG);
        throw new ToolException(msg, ex);
    }
}
Also used : Message(org.apache.cxf.common.i18n.Message) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) FileWriterUtil(org.apache.cxf.tools.util.FileWriterUtil) Element(org.w3c.dom.Element) LoadingByteArrayOutputStream(org.apache.cxf.helpers.LoadingByteArrayOutputStream) BufferedOutputStream(java.io.BufferedOutputStream) JarOutputStream(java.util.jar.JarOutputStream) OutputStream(java.io.OutputStream) Definition(javax.wsdl.Definition) WSDLWriter(javax.wsdl.xml.WSDLWriter) BadUsageException(org.apache.cxf.tools.common.toolspec.parser.BadUsageException) IOException(java.io.IOException) ToolException(org.apache.cxf.tools.common.ToolException) LoadingByteArrayOutputStream(org.apache.cxf.helpers.LoadingByteArrayOutputStream) XmlSchema(org.apache.ws.commons.schema.XmlSchema) List(java.util.List) ArrayList(java.util.ArrayList) OutputStreamCreator(org.apache.cxf.tools.util.OutputStreamCreator) ToolException(org.apache.cxf.tools.common.ToolException) SchemaCollection(org.apache.cxf.common.xmlschema.SchemaCollection) File(java.io.File) BufferedOutputStream(java.io.BufferedOutputStream) Writer(java.io.Writer) WSDLWriter(javax.wsdl.xml.WSDLWriter)

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