Search in sources :

Example 16 with XmlSchemaType

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

the class WSDLToCorbaBinding method addCorbaElements.

private void addCorbaElements(XmlSchema xmlSchemaTypes) throws Exception {
    Map<QName, XmlSchemaElement> elements = xmlSchemaTypes.getElements();
    for (XmlSchemaElement el : elements.values()) {
        QName elName = el.getQName();
        XmlSchemaType schemaType = el.getSchemaType();
        if (elName == null) {
            elName = el.getRef().getTargetQName();
            schemaType = helper.getSchemaType(elName);
        }
        boolean anonymous;
        if (schemaType == null) {
            anonymous = true;
        } else {
            anonymous = WSDLTypes.isAnonymous(schemaType.getName());
        }
        if (schemaType != null) {
            XmlSchemaAnnotation annotation = null;
            if (el.getAnnotation() != null) {
                annotation = el.getAnnotation();
            }
            // this situation won't be handled. REVISIT.
            if (annotation != null) {
                XmlSchemaAppInfo appInfo = null;
                for (XmlSchemaAnnotationItem ann : annotation.getItems()) {
                    if (ann instanceof XmlSchemaAppInfo) {
                        appInfo = (XmlSchemaAppInfo) ann;
                        break;
                    }
                }
                if (appInfo != null) {
                    NodeList nlist = appInfo.getMarkup();
                    Node node = nlist.item(0);
                    String info = node.getNodeValue();
                    info = info.trim();
                    String annotationBindingName = "";
                    if ("corba:binding=".equals(info.substring(0, 14))) {
                        annotationBindingName = info.substring(14);
                    }
                    if (bindingName.equals(annotationBindingName)) {
                        annotation = null;
                    }
                }
            }
            CorbaType corbaTypeImpl = helper.convertSchemaToCorbaType(schemaType, elName, schemaType, annotation, anonymous);
            if (el.isNillable()) {
                QName uname = helper.createQNameCorbaNamespace(corbaTypeImpl.getQName().getLocalPart() + "_nil");
                boolean isQualified = corbaTypeImpl.isSetQualified() && corbaTypeImpl.isQualified();
                corbaTypeImpl = helper.createNillableUnion(uname, helper.checkPrefix(elName), helper.checkPrefix(corbaTypeImpl.getQName()), isQualified);
            }
            if (corbaTypeImpl != null && !helper.isDuplicate(corbaTypeImpl)) {
                typeMappingType.getStructOrExceptionOrUnion().add(corbaTypeImpl);
            }
        }
    }
}
Also used : XmlSchemaAnnotationItem(org.apache.ws.commons.schema.XmlSchemaAnnotationItem) XmlSchemaAnnotation(org.apache.ws.commons.schema.XmlSchemaAnnotation) CorbaType(org.apache.cxf.binding.corba.wsdl.CorbaType) QName(javax.xml.namespace.QName) XmlSchemaElement(org.apache.ws.commons.schema.XmlSchemaElement) NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node) XmlSchemaType(org.apache.ws.commons.schema.XmlSchemaType) XmlSchemaAppInfo(org.apache.ws.commons.schema.XmlSchemaAppInfo)

Example 17 with XmlSchemaType

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

use of org.apache.ws.commons.schema.XmlSchemaType 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: ").append(schema.getTargetNamespace());
    if (schema.getSourceURI() != null) {
        code.append("\n//  ").append(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) ").append(simpleType.getQName()).append('\n');
                code.append("//\n");
                for (String value : values) {
                    code.append("// - ").append(value).append('\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)

Example 19 with XmlSchemaType

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

the class WSDLASTVisitor method setSequenceOctetType.

public void setSequenceOctetType(String type) throws Exception {
    final XmlSchemaType stype;
    if (type.equals(ToolCorbaConstants.CFG_SEQUENCE_OCTET_TYPE_BASE64BINARY)) {
        stype = schemas.getTypeByQName(Constants.XSD_BASE64);
    } else if (type.equals(ToolCorbaConstants.CFG_SEQUENCE_OCTET_TYPE_HEXBINARY)) {
        stype = schemas.getTypeByQName(Constants.XSD_HEXBIN);
    } else {
        throw new ToolException("WSDLASTVisitor: Invalid XmlSchemaType specified " + "for idl:sequence<octet> mapping.");
    }
    sequenceOctetType = stype;
}
Also used : ToolException(org.apache.cxf.tools.common.ToolException) XmlSchemaType(org.apache.ws.commons.schema.XmlSchemaType)

Example 20 with XmlSchemaType

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

the class WSDLParameter method processInputParams.

private void processInputParams(WSDLToCorbaBinding wsdlToCorbaBinding, Operation operation, SchemaCollection xmlSchemaList, List<ParamType> inputs) throws Exception {
    Input input = operation.getInput();
    if (input != null) {
        Message msg = input.getMessage();
        List<Part> parts = CastUtils.cast(msg.getOrderedParts(null));
        for (Part part : parts) {
            XmlSchemaType schemaType = null;
            boolean isObjectRef = isObjectReference(xmlSchemaList, part.getElementName());
            if (part.getElementName() != null && !isObjectRef) {
                XmlSchemaElement el = getElement(part, xmlSchemaList);
                if (el != null) {
                    if (el.getSchemaType() != null) {
                        schemaType = el.getSchemaType();
                    }
                    QName typeName = el.getSchemaTypeName();
                    if (typeName == null) {
                        typeName = el.getQName();
                    }
                    QName idltype = getIdlType(wsdlToCorbaBinding, schemaType, typeName, el.isNillable());
                    ParamType paramtype = createParam(wsdlToCorbaBinding, "in", part.getName(), idltype);
                    if (paramtype != null) {
                        inputs.add(paramtype);
                    }
                }
            } else if (part.getTypeName() != null) {
                schemaType = getType(part, xmlSchemaList);
                QName typeName = part.getTypeName();
                if (isObjectRef) {
                    typeName = part.getElementName();
                }
                QName idltype = getIdlType(wsdlToCorbaBinding, schemaType, typeName, false);
                ParamType paramtype = createParam(wsdlToCorbaBinding, "in", part.getName(), idltype);
                if (paramtype != null) {
                    inputs.add(paramtype);
                }
            }
        }
    }
}
Also used : Input(javax.wsdl.Input) Message(javax.wsdl.Message) Part(javax.wsdl.Part) XmlSchemaElement(org.apache.ws.commons.schema.XmlSchemaElement) QName(javax.xml.namespace.QName) XmlSchemaType(org.apache.ws.commons.schema.XmlSchemaType) ParamType(org.apache.cxf.binding.corba.wsdl.ParamType)

Aggregations

XmlSchemaType (org.apache.ws.commons.schema.XmlSchemaType)81 QName (javax.xml.namespace.QName)47 XmlSchemaElement (org.apache.ws.commons.schema.XmlSchemaElement)37 CorbaType (org.apache.cxf.binding.corba.wsdl.CorbaType)23 XmlSchemaComplexType (org.apache.ws.commons.schema.XmlSchemaComplexType)23 XmlSchema (org.apache.ws.commons.schema.XmlSchema)21 XmlSchemaSimpleType (org.apache.ws.commons.schema.XmlSchemaSimpleType)16 XmlSchemaSequence (org.apache.ws.commons.schema.XmlSchemaSequence)12 AST (antlr.collections.AST)8 XmlSchemaObject (org.apache.ws.commons.schema.XmlSchemaObject)8 XmlSchemaComplexContentExtension (org.apache.ws.commons.schema.XmlSchemaComplexContentExtension)7 XmlSchemaObjectCollection (org.apache.ws.commons.schema.XmlSchemaObjectCollection)6 SchemaInfo (org.apache.cxf.service.model.SchemaInfo)5 XmlSchemaGroupBase (org.apache.ws.commons.schema.XmlSchemaGroupBase)5 XmlSchemaParticle (org.apache.ws.commons.schema.XmlSchemaParticle)5 ArrayList (java.util.ArrayList)4 CorbaTypeImpl (org.apache.cxf.binding.corba.wsdl.CorbaTypeImpl)4 Message (org.apache.cxf.common.i18n.Message)4 ParticleInfo (org.apache.cxf.javascript.ParticleInfo)4 XmlSchemaCollection (org.apache.ws.commons.schema.XmlSchemaCollection)4