Search in sources :

Example 81 with XmlSchemaComplexType

use of org.apache.ws.commons.schema.XmlSchemaComplexType 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 + "'] = " + nameManager.getJavascriptName(name) + "_serialize;");
            utils.appendLine("this.globalElementDeserializers['" + name + "'] = " + 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 + "'] = " + nameManager.getJavascriptName(name) + "_serialize;");
            utils.appendLine("this.globalElementDeserializers['" + name + "'] = " + 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 82 with XmlSchemaComplexType

use of org.apache.ws.commons.schema.XmlSchemaComplexType 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 ").append(currentOperation.getName()).append('\n');
    if (!isWrapped) {
        code.append("// - bare operation. Parameters:\n");
        for (ParticleInfo ei : unwrappedElementsAndNames) {
            code.append("// - ").append(getElementObjectName(ei)).append('\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 ").append(inputParameterNames.get(i)).append('\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 ").append(nameManager.getJavascriptName(baseName)).append('\n');
            } else if (type != null) {
                code.append("// - simple type ").append(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).append(".prototype.").append(opFunctionPropertyName).append(" = ").append(opFunctionGlobalName).append(";\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 83 with XmlSchemaComplexType

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

the class JavascriptUtils method generateCodeToSerializeElement.

/**
 * Given an element, generate the serialization code.
 *
 * @param elementInfo description of the element we are serializing
 * @param referencePrefix prefix to the Javascript variable. Nothing for
 *                args, this._ for members.
 * @param schemaCollection caller's schema collection.
 */
public void generateCodeToSerializeElement(ParticleInfo elementInfo, String referencePrefix, SchemaCollection schemaCollection) {
    if (elementInfo.isGroup()) {
        for (ParticleInfo childElement : elementInfo.getChildren()) {
            generateCodeToSerializeElement(childElement, referencePrefix, schemaCollection);
        }
        return;
    }
    XmlSchemaType type = elementInfo.getType();
    boolean nillable = elementInfo.isNillable();
    boolean optional = elementInfo.isOptional();
    boolean array = elementInfo.isArray();
    boolean mtom = treatAsMtom(elementInfo.getParticle());
    String jsVar = referencePrefix + elementInfo.getJavascriptName();
    appendLine("// block for local variables");
    // allow local variables.
    startBlock();
    // first question: optional?
    if (optional) {
        startIf(jsVar + " != null");
    }
    // and nillable in the array case applies to the elements.
    if (nillable && !array) {
        startIf(jsVar + " == null");
        appendString("<" + elementInfo.getXmlName() + " " + XmlSchemaUtils.XSI_NIL + "/>");
        appendElse();
    }
    if (array) {
        // protected against null in arrays.
        startIf(jsVar + " != null");
        startFor("var ax = 0", "ax < " + jsVar + ".length", "ax ++");
        jsVar = jsVar + "[ax]";
        // we need an extra level of 'nil' testing here. Or do we, depending
        // on the type structure?
        // Recode and fiddle appropriately.
        startIf(jsVar + " == null");
        if (nillable) {
            appendString("<" + elementInfo.getXmlName() + " " + XmlSchemaUtils.XSI_NIL + "/>");
        } else {
            appendString("<" + elementInfo.getXmlName() + "/>");
        }
        appendElse();
    }
    if (elementInfo.isAnyType()) {
        serializeAnyTypeElement(elementInfo, jsVar);
    // mtom can be turned on for the special complex type that is really a basic type with
    // a content-type attribute.
    } else if (!mtom && type instanceof XmlSchemaComplexType) {
        // it has a value
        // pass the extra null in the slot for the 'extra namespaces' needed
        // by 'any'.
        appendExpression(jsVar + ".serialize(cxfjsutils, '" + elementInfo.getXmlName() + "', null)");
    } else {
        // simple type
        appendString("<" + elementInfo.getXmlName() + ">");
        if (mtom) {
            appendExpression("cxfjsutils.packageMtom(" + jsVar + ")");
        } else {
            appendExpression("cxfjsutils.escapeXmlEntities(" + jsVar + ")");
        }
        appendString("</" + elementInfo.getXmlName() + ">");
    }
    if (array) {
        // for the extra level of nil checking, which might be
        endBlock();
        // wrong.
        // for the for loop.
        endBlock();
        // the null protection.
        endBlock();
    }
    if (nillable && !array) {
        endBlock();
    }
    if (optional) {
        endBlock();
    }
    // local variables
    endBlock();
}
Also used : XmlSchemaComplexType(org.apache.ws.commons.schema.XmlSchemaComplexType) XmlSchemaType(org.apache.ws.commons.schema.XmlSchemaType)

Example 84 with XmlSchemaComplexType

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

the class CorbaHandlerUtils method getXmlSchemaSequenceElement.

public static XmlSchemaElement getXmlSchemaSequenceElement(XmlSchemaObject schemaType, ServiceInfo serviceInfo) {
    XmlSchemaObject stype = schemaType;
    final XmlSchemaElement el;
    if (schemaType instanceof XmlSchemaElement) {
        stype = ((XmlSchemaElement) schemaType).getSchemaType();
        if (stype == null) {
            stype = CorbaUtils.getXmlSchemaType(serviceInfo, ((XmlSchemaElement) schemaType).getRef().getTargetQName());
        }
    }
    if (stype instanceof XmlSchemaComplexType) {
        // only one element inside the XmlSchemaComplexType
        XmlSchemaComplexType ctype = (XmlSchemaComplexType) stype;
        XmlSchemaParticle group = ctype.getParticle();
        /* This code seems to think that we're guaranteed a sequence here */
        XmlSchemaSequence seq = (XmlSchemaSequence) group;
        /* and an element in it, too */
        el = (XmlSchemaElement) seq.getItems().get(0);
    } else {
        el = (XmlSchemaElement) schemaType;
    }
    return el;
}
Also used : XmlSchemaSequence(org.apache.ws.commons.schema.XmlSchemaSequence) XmlSchemaObject(org.apache.ws.commons.schema.XmlSchemaObject) XmlSchemaElement(org.apache.ws.commons.schema.XmlSchemaElement) XmlSchemaComplexType(org.apache.ws.commons.schema.XmlSchemaComplexType) XmlSchemaParticle(org.apache.ws.commons.schema.XmlSchemaParticle)

Example 85 with XmlSchemaComplexType

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

the class BeanTest method testCharMappings.

@Test
public void testCharMappings() throws Exception {
    defaultContext();
    BeanType type = (BeanType) mapping.getTypeCreator().createType(SimpleBean.class);
    type.setTypeClass(SimpleBean.class);
    type.setTypeMapping(mapping);
    XmlSchema schema = newXmlSchema("urn:Bean");
    type.writeSchema(schema);
    XmlSchemaComplexType btype = (XmlSchemaComplexType) schema.getTypeByName("SimpleBean");
    XmlSchemaSequence seq = (XmlSchemaSequence) btype.getParticle();
    boolean charok = false;
    for (int x = 0; x < seq.getItems().size(); x++) {
        XmlSchemaSequenceMember o = seq.getItems().get(x);
        if (o instanceof XmlSchemaElement) {
            XmlSchemaElement oe = (XmlSchemaElement) o;
            if ("character".equals(oe.getName())) {
                charok = true;
                assertNotNull(oe.getSchemaTypeName());
                assertTrue(oe.isNillable());
                assertEquals(CharacterAsStringType.CHARACTER_AS_STRING_TYPE_QNAME, oe.getSchemaTypeName());
            }
        }
    }
    assertTrue(charok);
}
Also used : XmlSchemaSequence(org.apache.ws.commons.schema.XmlSchemaSequence) XmlSchema(org.apache.ws.commons.schema.XmlSchema) XmlSchemaElement(org.apache.ws.commons.schema.XmlSchemaElement) SimpleBean(org.apache.cxf.aegis.services.SimpleBean) XmlSchemaSequenceMember(org.apache.ws.commons.schema.XmlSchemaSequenceMember) XmlSchemaComplexType(org.apache.ws.commons.schema.XmlSchemaComplexType) AbstractAegisTest(org.apache.cxf.aegis.AbstractAegisTest) Test(org.junit.Test)

Aggregations

XmlSchemaComplexType (org.apache.ws.commons.schema.XmlSchemaComplexType)136 XmlSchemaElement (org.apache.ws.commons.schema.XmlSchemaElement)101 XmlSchemaSequence (org.apache.ws.commons.schema.XmlSchemaSequence)71 QName (javax.xml.namespace.QName)59 XmlSchemaSimpleType (org.apache.ws.commons.schema.XmlSchemaSimpleType)33 XmlSchema (org.apache.ws.commons.schema.XmlSchema)32 XmlSchemaType (org.apache.ws.commons.schema.XmlSchemaType)31 XmlSchemaAttribute (org.apache.ws.commons.schema.XmlSchemaAttribute)23 XmlSchemaObject (org.apache.ws.commons.schema.XmlSchemaObject)20 XmlSchemaObjectCollection (org.apache.ws.commons.schema.XmlSchemaObjectCollection)18 Test (org.junit.Test)18 XmlSchemaParticle (org.apache.ws.commons.schema.XmlSchemaParticle)16 XmlSchemaComplexContentExtension (org.apache.ws.commons.schema.XmlSchemaComplexContentExtension)15 ArrayList (java.util.ArrayList)13 XmlSchemaGroupBase (org.apache.ws.commons.schema.XmlSchemaGroupBase)12 XmlSchemaSequenceMember (org.apache.ws.commons.schema.XmlSchemaSequenceMember)12 XmlSchemaSimpleContentExtension (org.apache.ws.commons.schema.XmlSchemaSimpleContentExtension)12 XmlSchemaComplexContentRestriction (org.apache.ws.commons.schema.XmlSchemaComplexContentRestriction)8 FeatureMetacardType (org.codice.ddf.spatial.ogc.wfs.catalog.common.FeatureMetacardType)8 ParameterInfo (org.talend.designer.webservice.ws.wsdlinfo.ParameterInfo)8