Search in sources :

Example 71 with XmlSchemaElement

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

the class WSDLRefValidator method validatePartType.

private boolean validatePartType(String namespace, String name, boolean isElement) {
    boolean partvalid = false;
    if (namespace.equals(WSDLConstants.NS_SCHEMA_XSD)) {
        if (isElement) {
            XmlSchemaElement schemaEle = schemaCollection.getElementByQName(new QName(WSDLConstants.NS_SCHEMA_XSD, name));
            partvalid = schemaEle != null ? true : false;
        } else {
            if ("anyType".equals(name)) {
                return true;
            }
            XmlSchemaType schemaType = schemaCollection.getTypeByQName(new QName(WSDLConstants.NS_SCHEMA_XSD, name));
            partvalid = schemaType != null ? true : false;
        }
    } else {
        if (isElement) {
            if (schemaCollection.getElementByQName(new QName(namespace, name)) != null) {
                partvalid = true;
            }
        } else {
            if (schemaCollection.getTypeByQName(new QName(namespace, name)) != null) {
                partvalid = true;
            }
        }
    }
    return partvalid;
}
Also used : XmlSchemaElement(org.apache.ws.commons.schema.XmlSchemaElement) QName(javax.xml.namespace.QName) XmlSchemaType(org.apache.ws.commons.schema.XmlSchemaType)

Example 72 with XmlSchemaElement

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

the class WSDLToCorbaHelper method processOMGUnion.

private CorbaType processOMGUnion(XmlSchemaComplexType complex, QName defaultName) throws Exception {
    QName name;
    QName schematypeName = checkPrefix(complex.getQName());
    if (schematypeName == null) {
        schematypeName = defaultName;
        name = createQNameCorbaNamespace(defaultName.getLocalPart() + "Type");
    } else {
        name = createQNameCorbaNamespace(schematypeName.getLocalPart());
    }
    Union corbaUnion = new Union();
    corbaUnion.setName(name.getLocalPart());
    corbaUnion.setQName(name);
    String id = REPO_STRING + name.getLocalPart().replace('.', '/') + IDL_VERSION;
    corbaUnion.setRepositoryID(id);
    corbaUnion.setType(schematypeName);
    XmlSchemaSequence stype = (XmlSchemaSequence) complex.getParticle();
    Iterator<XmlSchemaSequenceMember> it = stype.getItems().iterator();
    XmlSchemaParticle st1 = (XmlSchemaParticle) it.next();
    XmlSchemaParticle st2 = (XmlSchemaParticle) it.next();
    final XmlSchemaElement discEl;
    final XmlSchemaChoice choice;
    if (st1 instanceof XmlSchemaElement) {
        discEl = (XmlSchemaElement) st1;
        choice = (XmlSchemaChoice) st2;
    } else {
        discEl = (XmlSchemaElement) st2;
        choice = (XmlSchemaChoice) st1;
    }
    CorbaType disctype = convertSchemaToCorbaType(discEl.getSchemaType(), discEl.getQName(), discEl.getSchemaType(), null, false);
    corbaUnion.setDiscriminator(disctype.getQName());
    List<MemberType> fields = processContainerAsMembers(choice, defaultName, schematypeName);
    List<String> caselist = new ArrayList<>();
    if (disctype instanceof Enum) {
        Enum corbaenum = (Enum) disctype;
        Iterator<Enumerator> iterator = corbaenum.getEnumerator().iterator();
        while (iterator.hasNext()) {
            Enumerator enumerator = iterator.next();
            caselist.add(enumerator.getValue());
        }
    } else if (SUPPORTEDDISTYPES.contains(disctype.getQName().getLocalPart())) {
        if ("long".equals(disctype.getQName().getLocalPart()) || "short".equals(disctype.getQName().getLocalPart())) {
            for (int i = 0; i < fields.size(); i++) {
                caselist.add(Integer.toString(i));
            }
        } else if ("char".equals(disctype.getQName().getLocalPart())) {
            for (int i = 0; i < fields.size(); i++) {
                caselist.add(Integer.toString(i));
            }
        } else if ("boolean".equals(disctype.getQName().getLocalPart())) {
            if (fields.size() == 2) {
                caselist.add("TRUE");
                caselist.add("FALSE");
            } else if (fields.size() == 1) {
                caselist.add("TRUE");
            } else {
                String msg = "Discriminator Type does not match number of Choices in Union:" + name;
                LOG.log(Level.WARNING, msg);
            }
        }
    }
    WSDLTypes.processUnionBranches(corbaUnion, fields, caselist);
    return corbaUnion;
}
Also used : Enum(org.apache.cxf.binding.corba.wsdl.Enum) QName(javax.xml.namespace.QName) XmlSchemaElement(org.apache.ws.commons.schema.XmlSchemaElement) ArrayList(java.util.ArrayList) XmlSchemaParticle(org.apache.ws.commons.schema.XmlSchemaParticle) Union(org.apache.cxf.binding.corba.wsdl.Union) XmlSchemaSequence(org.apache.ws.commons.schema.XmlSchemaSequence) CorbaType(org.apache.cxf.binding.corba.wsdl.CorbaType) MemberType(org.apache.cxf.binding.corba.wsdl.MemberType) Enumerator(org.apache.cxf.binding.corba.wsdl.Enumerator) XmlSchemaSequenceMember(org.apache.ws.commons.schema.XmlSchemaSequenceMember) XmlSchemaChoice(org.apache.ws.commons.schema.XmlSchemaChoice)

Example 73 with XmlSchemaElement

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

the class WSDLToCorbaHelper method processContainerAsMembers.

protected List<MemberType> processContainerAsMembers(XmlSchemaParticle particle, QName defaultName, QName schemaTypeName) throws Exception {
    List<MemberType> members = new ArrayList<>();
    final Iterator<? extends XmlSchemaObjectBase> iterL;
    if (particle instanceof XmlSchemaSequence) {
        XmlSchemaSequence scontainer = (XmlSchemaSequence) particle;
        iterL = scontainer.getItems().iterator();
    } else if (particle instanceof XmlSchemaChoice) {
        XmlSchemaChoice scontainer = (XmlSchemaChoice) particle;
        iterL = scontainer.getItems().iterator();
    } else if (particle instanceof XmlSchemaAll) {
        XmlSchemaAll acontainer = (XmlSchemaAll) particle;
        iterL = acontainer.getItems().iterator();
    } else {
        LOG.warning("Unknown particle type " + particle.getClass().getName());
        iterL = new ArrayList<XmlSchemaObjectBase>().iterator();
    }
    while (iterL.hasNext()) {
        XmlSchemaParticle container = (XmlSchemaParticle) iterL.next();
        if (container instanceof XmlSchemaSequence) {
            XmlSchemaSequence sequence = (XmlSchemaSequence) container;
            CorbaType memberType = processSequenceType(sequence, defaultName, schemaTypeName);
            QName typeName = memberType.getQName();
            if (memberType instanceof Struct && !isDuplicate(memberType)) {
                typeMappingType.getStructOrExceptionOrUnion().add(memberType);
            }
            MemberType member = new MemberType();
            member.setName(memberType.getName() + "_f");
            member.setIdltype(typeName);
            member.setAnonschematype(true);
            if (memberType.isSetQualified() && memberType.isQualified()) {
                member.setQualified(true);
            }
            members.add(member);
        } else if (container instanceof XmlSchemaChoice) {
            XmlSchemaChoice choice = (XmlSchemaChoice) container;
            MemberType member = processChoiceMember(choice, defaultName, schemaTypeName);
            member.setAnonschematype(true);
            members.add(member);
        } else if (container instanceof XmlSchemaAll) {
            XmlSchemaAll all = (XmlSchemaAll) container;
            MemberType member = processAllMember(all, defaultName, schemaTypeName);
            member.setAnonschematype(true);
            members.add(member);
        } else if (container instanceof XmlSchemaElement) {
            XmlSchemaElement element = (XmlSchemaElement) container;
            CorbaType corbatype = processLocalElement(defaultName, element, schemaTypeName.getNamespaceURI());
            QName elName = element.getQName();
            if (elName == null) {
                elName = element.getRef().getTargetQName();
            }
            if (corbatype != null) {
                MemberType member;
                String memberName = elName.getLocalPart();
                member = new MemberType();
                member.setName(memberName);
                member.setIdltype(corbatype.getQName());
                if (corbatype.isSetQualified() && corbatype.isQualified()) {
                    member.setQualified(true);
                }
                members.add(member);
            } else {
                LOG.log(Level.WARNING, "Unsupported Element Found in CORBA Binding Generation:" + elName);
            }
        }
    }
    return members;
}
Also used : QName(javax.xml.namespace.QName) XmlSchemaElement(org.apache.ws.commons.schema.XmlSchemaElement) ArrayList(java.util.ArrayList) XmlSchemaParticle(org.apache.ws.commons.schema.XmlSchemaParticle) Struct(org.apache.cxf.binding.corba.wsdl.Struct) XmlSchemaSequence(org.apache.ws.commons.schema.XmlSchemaSequence) CorbaType(org.apache.cxf.binding.corba.wsdl.CorbaType) MemberType(org.apache.cxf.binding.corba.wsdl.MemberType) XmlSchemaAll(org.apache.ws.commons.schema.XmlSchemaAll) XmlSchemaChoice(org.apache.ws.commons.schema.XmlSchemaChoice)

Example 74 with XmlSchemaElement

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

the class WSDLToCorbaHelper method processLiteralArray.

private CorbaType processLiteralArray(XmlSchemaComplexType complex, QName defaultName, boolean anonymous) throws Exception {
    // NEED TO DO
    QName name;
    QName typeName = null;
    QName schematypeName = checkPrefix(complex.getQName());
    if (schematypeName == null) {
        schematypeName = defaultName;
        name = createQNameCorbaNamespace(defaultName.getLocalPart() + "Type");
        schematypeName = checkPrefix(schematypeName);
        name = checkPrefix(name);
    } else {
        name = createQNameCorbaNamespace(schematypeName.getLocalPart());
        name = checkPrefix(name);
    }
    CorbaType arrayType = null;
    XmlSchemaElement arrayEl = null;
    QName elName = null;
    if (complex.getParticle() instanceof XmlSchemaSequence) {
        XmlSchemaSequence seq = (XmlSchemaSequence) complex.getParticle();
        Iterator<XmlSchemaSequenceMember> iterator = seq.getItems().iterator();
        Iterator<XmlSchemaSequenceMember> iter = seq.getItems().iterator();
        while (iterator.hasNext()) {
            if (iter.next() instanceof XmlSchemaElement) {
                arrayEl = (XmlSchemaElement) iterator.next();
                elName = arrayEl.getQName();
                XmlSchemaType atype = arrayEl.getSchemaType();
                if (elName == null) {
                    elName = arrayEl.getRef().getTargetQName();
                    /*
                         * TODO: why are we looking up an element name with findSchemaType?
                         */
                    atype = findSchemaType(elName);
                }
                String uri = defaultName.getNamespaceURI();
                if (complex.getQName() != null) {
                    uri = complex.getQName().getNamespaceURI();
                }
                if (elName.getNamespaceURI().isEmpty()) {
                    elName = new QName(uri, elName.getLocalPart());
                }
                QName arrayTypeName = elName;
                if (anonymous) {
                    arrayTypeName = new QName(elName.getNamespaceURI(), defaultName.getLocalPart() + "." + elName.getLocalPart());
                }
                arrayType = convertSchemaToCorbaType(atype, arrayTypeName, atype, null, true);
                boolean isQualified = getElementQualification(arrayEl, uri);
                if (isQualified) {
                    arrayType.setQualified(isQualified);
                } else {
                    elName = new QName("", elName.getLocalPart());
                }
                typeName = arrayType.getQName();
            }
        }
    }
    Long maxOccurs = null;
    Long minOccurs = null;
    if (arrayEl != null) {
        if (arrayEl.isNillable()) {
            QName nilunionname = createQNameTargetNamespace(arrayType.getQName().getLocalPart() + "_nil");
            boolean isQualified = arrayType.isSetQualified() && arrayType.isQualified();
            arrayType = createNillableUnion(nilunionname, elName, arrayType.getQName(), isQualified);
            typeName = createQNameCorbaNamespace(arrayType.getQName().getLocalPart());
            if (arrayType != null && !isDuplicate(arrayType)) {
                typeMappingType.getStructOrExceptionOrUnion().add(arrayType);
            }
        }
        maxOccurs = arrayEl.getMaxOccurs();
        minOccurs = arrayEl.getMinOccurs();
    }
    return createArray(name, schematypeName, checkPrefix(typeName), elName, maxOccurs, minOccurs, anonymous);
}
Also used : XmlSchemaSequence(org.apache.ws.commons.schema.XmlSchemaSequence) CorbaType(org.apache.cxf.binding.corba.wsdl.CorbaType) QName(javax.xml.namespace.QName) XmlSchemaElement(org.apache.ws.commons.schema.XmlSchemaElement) XmlSchemaSequenceMember(org.apache.ws.commons.schema.XmlSchemaSequenceMember) XmlSchemaType(org.apache.ws.commons.schema.XmlSchemaType)

Example 75 with XmlSchemaElement

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

the class WSDLToCorbaHelper method findTypeInSchema.

private XmlSchemaType findTypeInSchema(XmlSchema xmlSchema, QName typeName) {
    XmlSchemaType schemaType = null;
    if (xmlSchema.getElementByName(typeName) != null) {
        XmlSchemaElement schemaElement = xmlSchema.getElementByName(typeName);
        schemaType = schemaElement.getSchemaType();
    } else if (xmlSchema.getTypeByName(typeName) != null) {
        schemaType = xmlSchema.getTypeByName(typeName);
    }
    if (schemaType != null) {
        return schemaType;
    }
    for (XmlSchemaExternal extSchema : xmlSchema.getExternals()) {
        if (!(extSchema instanceof XmlSchemaImport)) {
            schemaType = findTypeInSchema(extSchema.getSchema(), typeName);
            if (schemaType != null) {
                return schemaType;
            }
        }
    }
    return null;
}
Also used : XmlSchemaExternal(org.apache.ws.commons.schema.XmlSchemaExternal) XmlSchemaElement(org.apache.ws.commons.schema.XmlSchemaElement) XmlSchemaImport(org.apache.ws.commons.schema.XmlSchemaImport) XmlSchemaType(org.apache.ws.commons.schema.XmlSchemaType)

Aggregations

XmlSchemaElement (org.apache.ws.commons.schema.XmlSchemaElement)164 QName (javax.xml.namespace.QName)100 XmlSchemaComplexType (org.apache.ws.commons.schema.XmlSchemaComplexType)59 XmlSchema (org.apache.ws.commons.schema.XmlSchema)54 XmlSchemaSimpleType (org.apache.ws.commons.schema.XmlSchemaSimpleType)51 XmlSchemaSequence (org.apache.ws.commons.schema.XmlSchemaSequence)42 Test (org.junit.Test)42 XmlSchemaType (org.apache.ws.commons.schema.XmlSchemaType)39 FeatureMetacardType (org.codice.ddf.spatial.ogc.wfs.catalog.common.FeatureMetacardType)32 Message (org.apache.cxf.common.i18n.Message)15 XmlSchemaParticle (org.apache.ws.commons.schema.XmlSchemaParticle)15 XmlSchemaSequenceMember (org.apache.ws.commons.schema.XmlSchemaSequenceMember)14 MessagePartInfo (org.apache.cxf.service.model.MessagePartInfo)13 ArrayList (java.util.ArrayList)12 JAXBBeanInfo (org.apache.cxf.common.jaxb.JAXBBeanInfo)12 XmlSchemaObject (org.apache.ws.commons.schema.XmlSchemaObject)12 Method (java.lang.reflect.Method)11 SchemaInfo (org.apache.cxf.service.model.SchemaInfo)11 XmlSchemaAttribute (org.apache.ws.commons.schema.XmlSchemaAttribute)10 Iterator (java.util.Iterator)9