Search in sources :

Example 96 with XmlSchema

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

the class ImportRepairTest method newSchema.

private XmlSchema newSchema(String uri) {
    XmlSchema schema = collection.newXmlSchemaInCollection(uri);
    NamespaceMap map = new NamespaceMap();
    map.add("", XMLConstants.W3C_XML_SCHEMA_NS_URI);
    schema.setNamespaceContext(map);
    return schema;
}
Also used : XmlSchema(org.apache.ws.commons.schema.XmlSchema) NamespaceMap(org.apache.ws.commons.schema.utils.NamespaceMap)

Example 97 with XmlSchema

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

the class AttributeInfo method factoryCommon.

private static void factoryCommon(XmlSchemaAnnotated annotated, XmlSchema currentSchema, SchemaCollection schemaCollection, NamespacePrefixAccumulator prefixAccumulator, AttributeInfo attributeInfo) {
    if (annotated instanceof XmlSchemaAttribute) {
        XmlSchemaAttribute attribute = (XmlSchemaAttribute) annotated;
        String attributeNamespaceURI = attribute.getQName().getNamespaceURI();
        boolean attributeNoNamespace = "".equals(attributeNamespaceURI);
        XmlSchema attributeSchema = null;
        if (!attributeNoNamespace) {
            attributeSchema = schemaCollection.getSchemaByTargetNamespace(attributeNamespaceURI);
            if (attributeSchema == null) {
                throw new RuntimeException("Missing schema " + attributeNamespaceURI);
            }
        }
        boolean qualified = !attributeNoNamespace && XmlSchemaUtils.isAttributeQualified(attribute, true, currentSchema, attributeSchema);
        attributeInfo.xmlName = prefixAccumulator.xmlAttributeString(attribute, qualified);
        // we are assuming here that we are not dealing, in close proximity,
        // with elements with identical local names and different
        // namespaces.
        attributeInfo.javascriptName = attribute.getQName().getLocalPart();
        attributeInfo.defaultValue = attribute.getDefaultValue();
        attributeInfo.fixedValue = attribute.getFixedValue();
        attributeInfo.use = attribute.getUse();
        factorySetupType(attribute, schemaCollection, attributeInfo);
    } else {
        // any
        attributeInfo.any = true;
        // unknown until runtime.
        attributeInfo.xmlName = null;
        attributeInfo.javascriptName = "any";
        // runtime for any.
        attributeInfo.type = null;
        attributeInfo.use = XmlSchemaUse.OPTIONAL;
    }
}
Also used : XmlSchema(org.apache.ws.commons.schema.XmlSchema) XmlSchemaAttribute(org.apache.ws.commons.schema.XmlSchemaAttribute)

Example 98 with XmlSchema

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

the class ServiceJavascriptBuilder method generateGlobalElementDictionary.

private void generateGlobalElementDictionary() {
    // to handle 'any', we need a dictionary of all the global elements of all the schemas.
    utils.appendLine("this.globalElementSerializers = [];");
    utils.appendLine("this.globalElementDeserializers = [];");
    for (XmlSchema schemaInfo : xmlSchemaCollection.getXmlSchemas()) {
        for (Map.Entry<QName, XmlSchemaElement> e : schemaInfo.getElements().entrySet()) {
            QName name = e.getKey();
            XmlSchemaElement element = e.getValue();
            // That comes later to improve deserialization.
            if (JavascriptUtils.notVeryComplexType(element.getSchemaType())) {
                continue;
            }
            // If the element uses a named type, we use the functions for the type.
            XmlSchemaComplexType elementType = (XmlSchemaComplexType) element.getSchemaType();
            if (elementType != null && elementType.getQName() != null) {
                name = elementType.getQName();
            }
            utils.appendLine("this.globalElementSerializers['" + name.toString() + "'] = " + nameManager.getJavascriptName(name) + "_serialize;");
            utils.appendLine("this.globalElementDeserializers['" + name.toString() + "'] = " + nameManager.getJavascriptName(name) + "_deserialize;");
        }
        for (Map.Entry<QName, XmlSchemaType> e : schemaInfo.getSchemaTypes().entrySet()) {
            QName name = e.getKey();
            XmlSchemaType type = e.getValue();
            // For now, at least, don't handle simple types.
            if (JavascriptUtils.notVeryComplexType(type)) {
                continue;
            }
            // the names are misleading, but that's OK.
            utils.appendLine("this.globalElementSerializers['" + name.toString() + "'] = " + nameManager.getJavascriptName(name) + "_serialize;");
            utils.appendLine("this.globalElementDeserializers['" + name.toString() + "'] = " + nameManager.getJavascriptName(name) + "_deserialize;");
        }
    }
}
Also used : XmlSchema(org.apache.ws.commons.schema.XmlSchema) QName(javax.xml.namespace.QName) XmlSchemaElement(org.apache.ws.commons.schema.XmlSchemaElement) XmlSchemaComplexType(org.apache.ws.commons.schema.XmlSchemaComplexType) XmlSchemaType(org.apache.ws.commons.schema.XmlSchemaType) HashMap(java.util.HashMap) Map(java.util.Map)

Example 99 with XmlSchema

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

the class ServiceJavascriptBuilder method buildOperationFunction.

private void buildOperationFunction(StringBuilder parameterList) {
    String responseCallbackParams = "";
    if (!currentOperation.isOneWay()) {
        responseCallbackParams = "successCallback, errorCallback";
    }
    MessageInfo inputMessage = currentOperation.getInput();
    code.append("//\n");
    code.append("// Operation " + currentOperation.getName() + "\n");
    if (!isWrapped) {
        code.append("// - bare operation. Parameters:\n");
        for (ParticleInfo ei : unwrappedElementsAndNames) {
            code.append("// - " + getElementObjectName(ei) + "\n");
        }
    } else {
        code.append("// Wrapped operation.\n");
        QName contextQName = inputWrapperComplexType.getQName();
        if (contextQName == null) {
            contextQName = inputWrapperElement.getQName();
        }
        XmlSchemaSequence sequence = JavascriptUtils.getSequence(inputWrapperComplexType);
        XmlSchema wrapperSchema = xmlSchemaCollection.getSchemaByTargetNamespace(contextQName.getNamespaceURI());
        for (int i = 0; i < sequence.getItems().size(); i++) {
            code.append("// parameter " + inputParameterNames.get(i) + "\n");
            XmlSchemaSequenceMember sequenceItem = sequence.getItems().get(i);
            ParticleInfo itemInfo = ParticleInfo.forLocalItem((XmlSchemaObject) sequenceItem, wrapperSchema, xmlSchemaCollection, prefixAccumulator, contextQName);
            if (itemInfo.isArray()) {
                code.append("// - array\n");
            }
            // null for an any.
            XmlSchemaType type = itemInfo.getType();
            if (type instanceof XmlSchemaComplexType) {
                QName baseName;
                if (type.getQName() != null) {
                    baseName = type.getQName();
                } else {
                    baseName = ((XmlSchemaElement) sequenceItem).getQName();
                }
                code.append("// - Object constructor is " + nameManager.getJavascriptName(baseName) + "\n");
            } else if (type != null) {
                code.append("// - simple type " + type.getQName());
            }
        }
    }
    code.append("//\n");
    code.append("function " + opFunctionGlobalName + "(" + responseCallbackParams + ((parameterList.length() > 0 && !currentOperation.isOneWay()) ? ", " : "") + parameterList + ") {\n");
    utils.appendLine("this.client = new CxfApacheOrgClient(this.jsutils);");
    utils.appendLine("var xml = null;");
    if (inputMessage != null) {
        utils.appendLine("var args = new Array(" + inputParameterNames.size() + ");");
        int px = 0;
        for (String param : inputParameterNames) {
            utils.appendLine("args[" + px + "] = " + param + ";");
            px++;
        }
        utils.appendLine("xml = this." + getFunctionPropertyName(inputMessagesWithNameConflicts, inputMessage, inputMessage.getName()) + "_serializeInput" + "(this.jsutils, args);");
    }
    // functions.
    if (!currentOperation.isOneWay()) {
        utils.appendLine("this.client.user_onsuccess = successCallback;");
        utils.appendLine("this.client.user_onerror = errorCallback;");
        utils.appendLine("var closureThis = this;");
        // client will pass itself and the response XML.
        utils.appendLine("this.client.onsuccess = function(client, responseXml) { closureThis." + opFunctionPropertyName + "_onsuccess(client, responseXml); };");
        // client will pass itself.
        utils.appendLine("this.client.onerror = function(client) { closureThis." + opFunctionPropertyName + "_onerror(client); };");
    }
    utils.appendLine("var requestHeaders = [];");
    if (soapBindingInfo != null) {
        String action = soapBindingInfo.getSoapAction(currentOperation);
        utils.appendLine("requestHeaders['SOAPAction'] = '" + action + "';");
    }
    // default 'method' by passing null. Is there some place this lives in the
    // service model?
    String syncAsyncFlag;
    if (currentOperation.isOneWay()) {
        utils.appendLine("this.jsutils.trace('oneway operation');");
        syncAsyncFlag = "false";
    } else {
        utils.appendLine("this.jsutils.trace('synchronous = ' + this.synchronous);");
        syncAsyncFlag = "this.synchronous";
    }
    utils.appendLine("this.client.request(this.url, xml, null, " + syncAsyncFlag + ", requestHeaders);");
    code.append("}\n\n");
    code.append(currentInterfaceClassName + ".prototype." + opFunctionPropertyName + " = " + opFunctionGlobalName + ";\n\n");
}
Also used : XmlSchemaSequence(org.apache.ws.commons.schema.XmlSchemaSequence) XmlSchema(org.apache.ws.commons.schema.XmlSchema) QName(javax.xml.namespace.QName) ParticleInfo(org.apache.cxf.javascript.ParticleInfo) XmlSchemaSequenceMember(org.apache.ws.commons.schema.XmlSchemaSequenceMember) XmlSchemaComplexType(org.apache.ws.commons.schema.XmlSchemaComplexType) XmlSchemaType(org.apache.ws.commons.schema.XmlSchemaType) MessageInfo(org.apache.cxf.service.model.MessageInfo)

Example 100 with XmlSchema

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

the class DynamicClientFactory method addSchemas.

private void addSchemas(Options opts, SchemaCompiler schemaCompiler, List<ServiceInfo> serviceList, SchemaCollection schemaCollection) {
    Map<String, Element> done = new HashMap<>();
    Map<String, Element> notDone = new HashMap<>();
    OASISCatalogManager catalog = bus.getExtension(OASISCatalogManager.class);
    for (XmlSchema schema : schemaCollection.getXmlSchemas()) {
        if (XMLConstants.W3C_XML_SCHEMA_NS_URI.equals(schema.getTargetNamespace())) {
            continue;
        }
        String key = schema.getSourceURI();
        if (done.containsKey(key)) {
            continue;
        }
        if (!key.startsWith("file:") && !key.startsWith("jar:")) {
            XmlSchemaSerializer xser = new XmlSchemaSerializer();
            xser.setExtReg(schemaCollection.getExtReg());
            Document[] docs;
            try {
                docs = xser.serializeSchema(schema, false);
            } catch (XmlSchemaSerializerException e) {
                throw new RuntimeException(e);
            }
            Element ele = docs[0].getDocumentElement();
            ele = removeImportElement(ele, key, catalog, done, notDone);
            try {
                docs[0].setDocumentURI(key);
            } catch (Throwable t) {
            // ignore - DOM level 3
            }
            if (ele != null) {
                InputSource is = new InputSource((InputStream) null);
                // key = key.replaceFirst("#types[0-9]+$", "");
                is.setSystemId(key);
                is.setPublicId(key);
                opts.addGrammar(is);
                schemaCompiler.parseSchema(key, ele);
            }
        }
    }
    for (XmlSchema schema : schemaCollection.getXmlSchemas()) {
        if (XMLConstants.W3C_XML_SCHEMA_NS_URI.equals(schema.getTargetNamespace())) {
            continue;
        }
        String key = schema.getSourceURI();
        if (done.containsKey(key)) {
            continue;
        }
        if (key.startsWith("file:") || key.startsWith("jar:")) {
            InputStream in = null;
            try {
                if (key.contains("#")) {
                    for (ServiceInfo si : serviceList) {
                        for (SchemaInfo sci : si.getSchemas()) {
                            if (key != null && key.equals(sci.getSystemId())) {
                                key = null;
                            }
                        }
                    }
                }
                if (key == null) {
                    continue;
                }
                if (key.startsWith("file:")) {
                    in = Files.newInputStream(new File(new URI(key)).toPath());
                } else {
                    in = new URL(key).openStream();
                }
                XMLStreamReader reader = StaxUtils.createXMLStreamReader(key, in);
                reader = new LocationFilterReader(reader, catalog);
                InputSource is = new InputSource(key);
                opts.addGrammar(is);
                schemaCompiler.parseSchema(key, reader);
                reader.close();
            } catch (RuntimeException ex) {
                throw ex;
            } catch (Exception ex) {
                throw new RuntimeException(ex);
            } finally {
                if (in != null) {
                    try {
                        in.close();
                    } catch (IOException e) {
                    // ignore
                    }
                }
            }
        }
    }
    for (ServiceInfo si : serviceList) {
        for (SchemaInfo sci : si.getSchemas()) {
            String key = sci.getSystemId();
            if (done.containsKey(key)) {
                continue;
            }
            Element ele = sci.getElement();
            ele = removeImportElement(ele, key, catalog, done, notDone);
            if (ele != null) {
                InputSource is = new InputSource((InputStream) null);
                // key = key.replaceFirst("#types[0-9]+$", "");
                is.setSystemId(key);
                is.setPublicId(key);
                opts.addGrammar(is);
                schemaCompiler.parseSchema(key, StaxUtils.createXMLStreamReader(ele, key));
            }
        }
    }
    for (Map.Entry<String, Element> el : notDone.entrySet()) {
        InputSource is = new InputSource((InputStream) null);
        // key = key.replaceFirst("#types[0-9]+$", "");
        is.setSystemId(el.getKey());
        is.setPublicId(el.getKey());
        opts.addGrammar(is);
        schemaCompiler.parseSchema(el.getKey(), StaxUtils.createXMLStreamReader(el.getValue(), el.getKey()));
    }
}
Also used : InputSource(org.xml.sax.InputSource) XMLStreamReader(javax.xml.stream.XMLStreamReader) HashMap(java.util.HashMap) Element(org.w3c.dom.Element) Document(org.w3c.dom.Document) URI(java.net.URI) URL(java.net.URL) ServiceInfo(org.apache.cxf.service.model.ServiceInfo) OASISCatalogManager(org.apache.cxf.catalog.OASISCatalogManager) SchemaInfo(org.apache.cxf.service.model.SchemaInfo) InputStream(java.io.InputStream) XmlSchemaSerializer(org.apache.ws.commons.schema.XmlSchemaSerializer) IOException(java.io.IOException) URISyntaxException(java.net.URISyntaxException) XMLStreamException(javax.xml.stream.XMLStreamException) JAXBException(javax.xml.bind.JAXBException) SAXException(org.xml.sax.SAXException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) XmlSchemaSerializerException(org.apache.ws.commons.schema.XmlSchemaSerializer.XmlSchemaSerializerException) DOMException(org.w3c.dom.DOMException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) SAXParseException(org.xml.sax.SAXParseException) ServiceConstructionException(org.apache.cxf.service.factory.ServiceConstructionException) XmlSchema(org.apache.ws.commons.schema.XmlSchema) XmlSchemaSerializerException(org.apache.ws.commons.schema.XmlSchemaSerializer.XmlSchemaSerializerException) JarFile(java.util.jar.JarFile) File(java.io.File) Map(java.util.Map) HashMap(java.util.HashMap) NamedNodeMap(org.w3c.dom.NamedNodeMap)

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