Search in sources :

Example 36 with XmlSchemaComplexType

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

the class WSDLServiceBuilder method checkForWrapped.

public static void checkForWrapped(OperationInfo opInfo, boolean allowRefs, boolean relaxed, Level logLevel) {
    MessageInfo inputMessage = opInfo.getInput();
    MessageInfo outputMessage = opInfo.getOutput();
    boolean passedRule = true;
    // input message must exist
    if (inputMessage == null || inputMessage.size() == 0 || (inputMessage.size() > 1 && !relaxed)) {
        passedRule = false;
    }
    if (outputMessage != null && outputMessage.size() > 1) {
        passedRule = false;
    }
    if (!passedRule) {
        org.apache.cxf.common.i18n.Message message = new org.apache.cxf.common.i18n.Message("WRAPPED_RULE_1", LOG, opInfo.getName());
        LOG.log(logLevel, message.toString());
        return;
    }
    SchemaCollection schemas = opInfo.getInterface().getService().getXmlSchemaCollection();
    XmlSchemaElement inputEl = null;
    XmlSchemaElement outputEl = null;
    // RULE No.2:
    // The input message part refers to a global element declaration whose
    // local name is equal to the operation name.
    MessagePartInfo inputPart = inputMessage.getMessagePartByIndex(0);
    if (!inputPart.isElement()) {
        passedRule = false;
    } else {
        QName inputElementName = inputPart.getElementQName();
        inputEl = schemas.getElementByQName(inputElementName);
        if (inputEl == null) {
            passedRule = false;
        } else if (!opInfo.getName().getLocalPart().equals(inputElementName.getLocalPart())) {
            passedRule = relaxed;
        }
    }
    if (!passedRule) {
        org.apache.cxf.common.i18n.Message message = new org.apache.cxf.common.i18n.Message("WRAPPED_RULE_2", LOG, opInfo.getName());
        LOG.log(logLevel, message.toString());
        return;
    }
    // RULE No.3:
    // The output message part refers to a global element declaration
    MessagePartInfo outputPart = null;
    if (outputMessage != null && outputMessage.size() == 1) {
        outputPart = outputMessage.getMessagePartByIndex(0);
        if (outputPart != null) {
            if (!outputPart.isElement() || schemas.getElementByQName(outputPart.getElementQName()) == null) {
                passedRule = false;
            } else {
                outputEl = schemas.getElementByQName(outputPart.getElementQName());
            }
        }
    }
    if (!passedRule) {
        org.apache.cxf.common.i18n.Message message = new org.apache.cxf.common.i18n.Message("WRAPPED_RULE_3", LOG, opInfo.getName());
        LOG.log(logLevel, message.toString());
        return;
    }
    // RULE No.4 and No5:
    // wrapper element should be pure complex type
    // Now lets see if we have any attributes...
    // This should probably look at the restricted and substitute types too.
    OperationInfo unwrapped = new UnwrappedOperationInfo(opInfo);
    MessageInfo unwrappedInput = new MessageInfo(unwrapped, MessageInfo.Type.INPUT, inputMessage.getName());
    MessageInfo unwrappedOutput = null;
    XmlSchemaComplexType xsct = null;
    if (inputEl.getSchemaType() instanceof XmlSchemaComplexType) {
        xsct = (XmlSchemaComplexType) inputEl.getSchemaType();
        if (hasAttributes(xsct) || (inputEl.isNillable() && !relaxed) || !isWrappableSequence(xsct, inputEl.getQName().getNamespaceURI(), unwrappedInput, allowRefs)) {
            passedRule = false;
        }
    } else {
        passedRule = false;
    }
    if (!passedRule) {
        org.apache.cxf.common.i18n.Message message = new org.apache.cxf.common.i18n.Message("WRAPPED_RULE_4", LOG, opInfo.getName());
        LOG.log(logLevel, message.toString());
        return;
    }
    if (outputMessage != null) {
        unwrappedOutput = new MessageInfo(unwrapped, MessageInfo.Type.OUTPUT, outputMessage.getName());
        if (outputEl != null && outputEl.getSchemaType() instanceof XmlSchemaComplexType) {
            xsct = (XmlSchemaComplexType) outputEl.getSchemaType();
            if (xsct.isAbstract()) {
                passedRule = false;
            }
            if (hasAttributes(xsct) || (outputEl.isNillable() && !relaxed) || !isWrappableSequence(xsct, outputEl.getQName().getNamespaceURI(), unwrappedOutput, allowRefs)) {
                passedRule = false;
            }
        } else {
            passedRule = false;
        }
    }
    if (!passedRule) {
        org.apache.cxf.common.i18n.Message message = new org.apache.cxf.common.i18n.Message("WRAPPED_RULE_5", LOG, opInfo.getName());
        LOG.log(logLevel, message.toString());
        return;
    }
    // we are wrappable!!
    opInfo.setUnwrappedOperation(unwrapped);
    unwrapped.setInput(opInfo.getInputName(), unwrappedInput);
    if (outputMessage != null) {
        unwrapped.setOutput(opInfo.getOutputName(), unwrappedOutput);
    }
}
Also used : OperationInfo(org.apache.cxf.service.model.OperationInfo) BindingOperationInfo(org.apache.cxf.service.model.BindingOperationInfo) UnwrappedOperationInfo(org.apache.cxf.service.model.UnwrappedOperationInfo) Message(javax.wsdl.Message) UnwrappedOperationInfo(org.apache.cxf.service.model.UnwrappedOperationInfo) XmlSchemaElement(org.apache.ws.commons.schema.XmlSchemaElement) QName(javax.xml.namespace.QName) MessagePartInfo(org.apache.cxf.service.model.MessagePartInfo) MessageInfo(org.apache.cxf.service.model.MessageInfo) BindingMessageInfo(org.apache.cxf.service.model.BindingMessageInfo) XmlSchemaComplexType(org.apache.ws.commons.schema.XmlSchemaComplexType) SchemaCollection(org.apache.cxf.common.xmlschema.SchemaCollection)

Example 37 with XmlSchemaComplexType

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

the class JavascriptUtils method getContentElements.

public static List<XmlSchemaObject> getContentElements(XmlSchemaComplexType type, SchemaCollection collection) {
    List<XmlSchemaObject> results = new ArrayList<>();
    QName baseTypeName = XmlSchemaUtils.getBaseType(type);
    if (baseTypeName != null) {
        XmlSchemaComplexType baseType = (XmlSchemaComplexType) collection.getTypeByQName(baseTypeName);
        // recurse onto the base type ...
        results.addAll(getContentElements(baseType, collection));
        // and now process our sequence.
        XmlSchemaSequence extSequence = getContentSequence(type);
        if (extSequence != null) {
            for (XmlSchemaSequenceMember item : extSequence.getItems()) {
                /*
                     * For now, leave the return type alone. Fix some day.
                     */
                results.add((XmlSchemaObject) item);
            }
        }
        return results;
    }
    // no base type, the simple case.
    XmlSchemaSequence sequence = getSequence(type);
    for (XmlSchemaSequenceMember item : sequence.getItems()) {
        results.add((XmlSchemaObject) item);
    }
    return results;
}
Also used : XmlSchemaSequence(org.apache.ws.commons.schema.XmlSchemaSequence) XmlSchemaObject(org.apache.ws.commons.schema.XmlSchemaObject) QName(javax.xml.namespace.QName) XmlSchemaSequenceMember(org.apache.ws.commons.schema.XmlSchemaSequenceMember) ArrayList(java.util.ArrayList) XmlSchemaComplexType(org.apache.ws.commons.schema.XmlSchemaComplexType)

Example 38 with XmlSchemaComplexType

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

the class ServiceJavascriptBuilder method createResponseDeserializer.

// This ignores 'wrapped', because it assumes one part that we can use one way or
// the other. For simple cases, this is certainly OK.
private void createResponseDeserializer(MessageInfo outputMessage) {
    List<MessagePartInfo> parts = outputMessage.getMessageParts();
    if (parts.size() != 1) {
        unsupportedConstruct("MULTIPLE_OUTPUTS", outputMessage.getName().toString());
    }
    List<ParticleInfo> elements = new ArrayList<>();
    String functionName = outputDeserializerFunctionName(outputMessage);
    code.append("function " + functionName + "(cxfjsutils, partElement) {\n");
    getElementsForParts(outputMessage, elements);
    ParticleInfo element = elements.get(0);
    XmlSchemaType type = null;
    if (isRPC) {
        utils.appendLine("cxfjsutils.trace('rpc element: ' + cxfjsutils.traceElementName(partElement));");
        utils.appendLine("partElement = cxfjsutils.getFirstElementChild(partElement);");
        utils.appendLine("cxfjsutils.trace('rpc element: ' + cxfjsutils.traceElementName(partElement));");
    }
    type = element.getType();
    if (!element.isEmpty()) {
        if (type instanceof XmlSchemaComplexType) {
            String typeObjectName = nameManager.getJavascriptName(element.getControllingName());
            utils.appendLine("var returnObject = " + typeObjectName + "_deserialize (cxfjsutils, partElement);\n");
            utils.appendLine("return returnObject;");
        } else if (type instanceof XmlSchemaSimpleType) {
            XmlSchemaSimpleType simpleType = (XmlSchemaSimpleType) type;
            utils.appendLine("var returnText = cxfjsutils.getNodeText(partElement);");
            utils.appendLine("var returnObject = " + utils.javascriptParseExpression(simpleType, "returnText") + ";");
            utils.appendLine("return returnObject;");
        } else if (type != null) {
            utils.appendLine("// Unsupported construct " + type.getClass());
        } else {
            utils.appendLine("// No type for element " + element.getXmlName());
        }
    }
    code.append("}\n");
}
Also used : XmlSchemaSimpleType(org.apache.ws.commons.schema.XmlSchemaSimpleType) ParticleInfo(org.apache.cxf.javascript.ParticleInfo) ArrayList(java.util.ArrayList) XmlSchemaComplexType(org.apache.ws.commons.schema.XmlSchemaComplexType) XmlSchemaType(org.apache.ws.commons.schema.XmlSchemaType) MessagePartInfo(org.apache.cxf.service.model.MessagePartInfo)

Example 39 with XmlSchemaComplexType

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

the class SchemaJavascriptBuilder method deserializeElement.

private void deserializeElement(XmlSchemaComplexType type, ParticleInfo itemInfo) {
    if (itemInfo.isGroup()) {
        for (ParticleInfo childElement : itemInfo.getChildren()) {
            deserializeElement(type, childElement);
        }
        return;
    }
    XmlSchemaType itemType = itemInfo.getType();
    boolean simple = itemType instanceof XmlSchemaSimpleType || JavascriptUtils.notVeryComplexType(itemType);
    boolean mtomCandidate = JavascriptUtils.mtomCandidateType(itemType);
    String accessorName = "set" + StringUtils.capitalize(itemInfo.getJavascriptName());
    utils.appendLine("cxfjsutils.trace('processing " + itemInfo.getJavascriptName() + "');");
    XmlSchemaElement element = (XmlSchemaElement) itemInfo.getParticle();
    QName elementQName = XmlSchemaUtils.getElementQualifiedName(element, xmlSchema);
    String elementNamespaceURI = elementQName.getNamespaceURI();
    boolean elementNoNamespace = "".equals(elementNamespaceURI);
    XmlSchema elementSchema = null;
    if (!elementNoNamespace) {
        elementSchema = xmlSchemaCollection.getSchemaByTargetNamespace(elementNamespaceURI);
    }
    boolean qualified = !elementNoNamespace && XmlSchemaUtils.isElementQualified(element, itemInfo.isGlobal(), xmlSchema, elementSchema);
    if (!qualified) {
        elementNamespaceURI = "";
    }
    String localName = elementQName.getLocalPart();
    String valueTarget = "item";
    if (itemInfo.isOptional() || itemInfo.isArray()) {
        utils.startIf("curElement != null && cxfjsutils.isNodeNamedNS(curElement, '" + elementNamespaceURI + "', '" + localName + "')");
        if (itemInfo.isArray()) {
            utils.appendLine("item = [];");
            utils.startDo();
            valueTarget = "arrayItem";
            utils.appendLine("var arrayItem = null;");
        }
    }
    utils.appendLine("var value = null;");
    utils.startIf("!cxfjsutils.isElementNil(curElement)");
    if (itemInfo.isAnyType()) {
        // use our utility
        utils.appendLine(valueTarget + " = org_apache_cxf_deserialize_anyType(cxfjsutils, curElement);");
    } else if (simple) {
        if (mtomCandidate) {
            utils.appendLine(valueTarget + " = cxfjsutils.deserializeBase64orMom(curElement);");
        } else {
            utils.appendLine("value = cxfjsutils.getNodeText(curElement);");
            utils.appendLine(valueTarget + " = " + utils.javascriptParseExpression(itemType, "value") + ";");
        }
    } else {
        XmlSchemaComplexType complexType = (XmlSchemaComplexType) itemType;
        QName baseQName = complexType.getQName();
        if (baseQName == null) {
            baseQName = element.getQName();
        }
        String elTypeJsName = nameManager.getJavascriptName(baseQName);
        utils.appendLine(valueTarget + " = " + elTypeJsName + "_deserialize(cxfjsutils, curElement);");
    }
    // the if for the nil.
    utils.endBlock();
    if (itemInfo.isArray()) {
        utils.appendLine("item.push(arrayItem);");
        utils.appendLine("curElement = cxfjsutils.getNextElementSibling(curElement);");
        utils.endBlock();
        utils.appendLine("  while(curElement != null && cxfjsutils.isNodeNamedNS(curElement, '" + elementNamespaceURI + "', '" + localName + "'));");
    }
    utils.appendLine("newobject." + accessorName + "(item);");
    utils.appendLine("var item = null;");
    if (!itemInfo.isArray()) {
        utils.startIf("curElement != null");
        utils.appendLine("curElement = cxfjsutils.getNextElementSibling(curElement);");
        utils.endBlock();
    }
    if (itemInfo.isOptional() || itemInfo.isArray()) {
        utils.endBlock();
    }
}
Also used : XmlSchema(org.apache.ws.commons.schema.XmlSchema) XmlSchemaSimpleType(org.apache.ws.commons.schema.XmlSchemaSimpleType) XmlSchemaElement(org.apache.ws.commons.schema.XmlSchemaElement) QName(javax.xml.namespace.QName) ParticleInfo(org.apache.cxf.javascript.ParticleInfo) XmlSchemaComplexType(org.apache.ws.commons.schema.XmlSchemaComplexType) XmlSchemaType(org.apache.ws.commons.schema.XmlSchemaType)

Example 40 with XmlSchemaComplexType

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

the class SchemaJavascriptBuilder method generateCodeForSchema.

public String generateCodeForSchema(XmlSchema schema) {
    xmlSchema = schema;
    code = new StringBuilder();
    code.append("//\n");
    code.append("// Definitions for schema: " + schema.getTargetNamespace());
    if (schema.getSourceURI() != null) {
        code.append("\n//  " + schema.getSourceURI());
    }
    code.append("\n//\n");
    Map<QName, XmlSchemaType> schemaTypes = schema.getSchemaTypes();
    for (Map.Entry<QName, XmlSchemaType> e : schemaTypes.entrySet()) {
        XmlSchemaType type = e.getValue();
        if (type instanceof XmlSchemaComplexType) {
            try {
                XmlSchemaComplexType complexType = (XmlSchemaComplexType) type;
                if (!JavascriptUtils.notVeryComplexType(complexType) && complexType.getName() != null) {
                    complexTypeConstructorAndAccessors(complexType.getQName(), complexType);
                    complexTypeSerializerFunction(complexType.getQName(), complexType);
                    domDeserializerFunction(complexType.getQName(), complexType);
                }
            } catch (UnsupportedConstruct usc) {
                LOG.warning(usc.toString());
                // it could be empty, but the style checker
                continue;
            // would complain.
            }
        } else if (type instanceof XmlSchemaSimpleType) {
            XmlSchemaSimpleType simpleType = (XmlSchemaSimpleType) type;
            if (XmlSchemaUtils.isEumeration(simpleType)) {
                List<String> values = XmlSchemaUtils.enumeratorValues(simpleType);
                code.append("//\n");
                code.append("// Simple type (enumeration) " + simpleType.getQName() + "\n");
                code.append("//\n");
                for (String value : values) {
                    code.append("// - " + value + "\n");
                }
            }
        }
    }
    for (Map.Entry<QName, XmlSchemaElement> e : schema.getElements().entrySet()) {
        XmlSchemaElement element = e.getValue();
        try {
            if (element.getSchemaTypeName() == null && element.getSchemaType() == null) {
                Message message = new Message("ELEMENT_MISSING_TYPE", LOG, element.getQName(), element.getSchemaTypeName(), schema.getTargetNamespace());
                LOG.warning(message.toString());
                continue;
            }
            XmlSchemaType type;
            if (element.getSchemaType() != null) {
                type = element.getSchemaType();
            } else {
                type = schema.getTypeByName(element.getSchemaTypeName());
            }
            if (!(type instanceof XmlSchemaComplexType)) {
                // we never make classes for simple type.
                continue;
            }
            XmlSchemaComplexType complexType = (XmlSchemaComplexType) type;
            // element.
            if (!JavascriptUtils.notVeryComplexType(complexType) && complexType.getName() == null) {
                complexTypeConstructorAndAccessors(element.getQName(), complexType);
                complexTypeSerializerFunction(element.getQName(), complexType);
                domDeserializerFunction(element.getQName(), complexType);
            }
        } catch (UnsupportedConstruct usc) {
            LOG.warning(usc.getMessage());
            // it could be empty, but the style checker
            continue;
        // would complain.
        }
    }
    String returnValue = code.toString();
    LOG.finer(returnValue);
    return returnValue;
}
Also used : Message(org.apache.cxf.common.i18n.Message) QName(javax.xml.namespace.QName) XmlSchemaElement(org.apache.ws.commons.schema.XmlSchemaElement) UnsupportedConstruct(org.apache.cxf.javascript.UnsupportedConstruct) XmlSchemaType(org.apache.ws.commons.schema.XmlSchemaType) XmlSchemaSimpleType(org.apache.ws.commons.schema.XmlSchemaSimpleType) XmlSchemaComplexType(org.apache.ws.commons.schema.XmlSchemaComplexType) List(java.util.List) Map(java.util.Map)

Aggregations

XmlSchemaComplexType (org.apache.ws.commons.schema.XmlSchemaComplexType)88 XmlSchemaElement (org.apache.ws.commons.schema.XmlSchemaElement)60 QName (javax.xml.namespace.QName)45 XmlSchemaSequence (org.apache.ws.commons.schema.XmlSchemaSequence)38 XmlSchemaSimpleType (org.apache.ws.commons.schema.XmlSchemaSimpleType)25 XmlSchemaType (org.apache.ws.commons.schema.XmlSchemaType)25 XmlSchema (org.apache.ws.commons.schema.XmlSchema)24 Test (org.junit.Test)18 XmlSchemaComplexContentExtension (org.apache.ws.commons.schema.XmlSchemaComplexContentExtension)13 XmlSchemaObject (org.apache.ws.commons.schema.XmlSchemaObject)12 XmlSchemaParticle (org.apache.ws.commons.schema.XmlSchemaParticle)12 XmlSchemaObjectCollection (org.apache.ws.commons.schema.XmlSchemaObjectCollection)11 XmlSchemaSequenceMember (org.apache.ws.commons.schema.XmlSchemaSequenceMember)11 XmlSchemaGroupBase (org.apache.ws.commons.schema.XmlSchemaGroupBase)10 FeatureMetacardType (org.codice.ddf.spatial.ogc.wfs.catalog.common.FeatureMetacardType)8 ParameterInfo (org.talend.designer.webservice.ws.wsdlinfo.ParameterInfo)8 ArrayList (java.util.ArrayList)7 AbstractAegisTest (org.apache.cxf.aegis.AbstractAegisTest)7 XmlSchemaAttribute (org.apache.ws.commons.schema.XmlSchemaAttribute)7 XmlSchemaComplexContentRestriction (org.apache.ws.commons.schema.XmlSchemaComplexContentRestriction)6