Search in sources :

Example 16 with SchemaCollection

use of org.apache.cxf.common.xmlschema.SchemaCollection in project cxf by apache.

the class CorbaUtils method getXmlSchemaType.

public static XmlSchemaType getXmlSchemaType(ServiceInfo serviceInfo, QName name) {
    XmlSchemaType result = null;
    if ((name != null) && (serviceInfo != null)) {
        SchemaCollection col = serviceInfo.getXmlSchemaCollection();
        result = col.getTypeByQName(name);
        if (result == null) {
            // check the name, if it is an element
            XmlSchemaElement el = col.getElementByQName(name);
            if (el != null) {
                result = el.getSchemaType();
            }
        }
    }
    return result;
}
Also used : XmlSchemaElement(org.apache.ws.commons.schema.XmlSchemaElement) XmlSchemaType(org.apache.ws.commons.schema.XmlSchemaType) SchemaCollection(org.apache.cxf.common.xmlschema.SchemaCollection)

Example 17 with SchemaCollection

use of org.apache.cxf.common.xmlschema.SchemaCollection in project cxf by apache.

the class SourceDataBinding method initialize.

public void initialize(Service service) {
    for (ServiceInfo serviceInfo : service.getServiceInfos()) {
        SchemaCollection schemaCollection = serviceInfo.getXmlSchemaCollection();
        if (schemaCollection.getXmlSchemas().length > 1) {
            // Schemas are already populated.
            continue;
        }
        new ServiceModelVisitor(serviceInfo) {

            public void begin(MessagePartInfo part) {
                if (part.getTypeQName() != null || part.getElementQName() != null) {
                    return;
                }
                part.setTypeQName(Constants.XSD_ANYTYPE);
            }
        }.walk();
    }
}
Also used : ServiceInfo(org.apache.cxf.service.model.ServiceInfo) SchemaCollection(org.apache.cxf.common.xmlschema.SchemaCollection) MessagePartInfo(org.apache.cxf.service.model.MessagePartInfo) ServiceModelVisitor(org.apache.cxf.service.ServiceModelVisitor)

Example 18 with SchemaCollection

use of org.apache.cxf.common.xmlschema.SchemaCollection in project cxf by apache.

the class SchemaUtil method getSchemas.

public void getSchemas(final Definition def, final ServiceInfo serviceInfo) {
    SchemaCollection schemaCol = serviceInfo.getXmlSchemaCollection();
    getSchemas(def, schemaCol, serviceInfo);
}
Also used : SchemaCollection(org.apache.cxf.common.xmlschema.SchemaCollection)

Example 19 with SchemaCollection

use of org.apache.cxf.common.xmlschema.SchemaCollection in project cxf by apache.

the class ReflectionServiceFactoryBean method getOrCreateSchema.

private SchemaInfo getOrCreateSchema(ServiceInfo serviceInfo, String namespaceURI, boolean qualified) {
    for (SchemaInfo s : serviceInfo.getSchemas()) {
        if (s.getNamespaceURI().equals(namespaceURI)) {
            return s;
        }
    }
    SchemaInfo schemaInfo = new SchemaInfo(namespaceURI);
    SchemaCollection col = serviceInfo.getXmlSchemaCollection();
    XmlSchema schema = col.getSchemaByTargetNamespace(namespaceURI);
    if (schema != null) {
        schemaInfo.setSchema(schema);
        serviceInfo.addSchema(schemaInfo);
        return schemaInfo;
    }
    schema = col.newXmlSchemaInCollection(namespaceURI);
    if (qualified) {
        schema.setElementFormDefault(XmlSchemaForm.QUALIFIED);
    }
    schemaInfo.setSchema(schema);
    Map<String, String> explicitNamespaceMappings = this.getDataBinding().getDeclaredNamespaceMappings();
    if (explicitNamespaceMappings == null) {
        explicitNamespaceMappings = Collections.emptyMap();
    }
    NamespaceMap nsMap = new NamespaceMap();
    for (Map.Entry<String, String> mapping : explicitNamespaceMappings.entrySet()) {
        nsMap.add(mapping.getValue(), mapping.getKey());
    }
    if (!explicitNamespaceMappings.containsKey(WSDLConstants.NS_SCHEMA_XSD)) {
        nsMap.add(WSDLConstants.NP_SCHEMA_XSD, WSDLConstants.NS_SCHEMA_XSD);
    }
    if (!explicitNamespaceMappings.containsKey(serviceInfo.getTargetNamespace())) {
        nsMap.add(WSDLConstants.CONVENTIONAL_TNS_PREFIX, serviceInfo.getTargetNamespace());
    }
    schema.setNamespaceContext(nsMap);
    serviceInfo.addSchema(schemaInfo);
    return schemaInfo;
}
Also used : XmlSchema(org.apache.ws.commons.schema.XmlSchema) NamespaceMap(org.apache.ws.commons.schema.utils.NamespaceMap) SchemaCollection(org.apache.cxf.common.xmlschema.SchemaCollection) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) NamespaceMap(org.apache.ws.commons.schema.utils.NamespaceMap) SchemaInfo(org.apache.cxf.service.model.SchemaInfo)

Example 20 with SchemaCollection

use of org.apache.cxf.common.xmlschema.SchemaCollection in project cxf by apache.

the class ReflectionServiceFactoryBean method fillInSchemaCrossreferences.

/**
 * Code elsewhere in this function will fill in the name of the type of an
 * element but not the reference to the type. This function fills in the
 * type references. This does not set the type reference for elements that
 * are declared as refs to other elements. It is a giant pain to find them,
 * since they are not (generally) root elements and the code would have to
 * traverse all the types to find all of them. Users should look them up
 * through the collection, that's what it is for.
 */
private void fillInSchemaCrossreferences() {
    Service service = getService();
    for (ServiceInfo serviceInfo : service.getServiceInfos()) {
        SchemaCollection schemaCollection = serviceInfo.getXmlSchemaCollection();
        // type.
        for (SchemaInfo schemaInfo : serviceInfo.getSchemas()) {
            Map<QName, XmlSchemaElement> elementsTable = schemaInfo.getSchema().getElements();
            for (XmlSchemaElement element : elementsTable.values()) {
                if (element.getSchemaType() == null) {
                    QName typeName = element.getSchemaTypeName();
                    if (typeName != null) {
                        XmlSchemaType type = schemaCollection.getTypeByQName(typeName);
                        if (type == null) {
                            Message message = new Message("REFERENCE_TO_UNDEFINED_TYPE", LOG, element.getQName(), typeName, service.getName());
                            LOG.severe(message.toString());
                        } else {
                            element.setSchemaType(type);
                        }
                    }
                }
            }
        }
    }
}
Also used : ServiceInfo(org.apache.cxf.service.model.ServiceInfo) Message(org.apache.cxf.common.i18n.Message) QName(javax.xml.namespace.QName) XmlSchemaElement(org.apache.ws.commons.schema.XmlSchemaElement) Service(org.apache.cxf.service.Service) SchemaCollection(org.apache.cxf.common.xmlschema.SchemaCollection) XmlSchemaType(org.apache.ws.commons.schema.XmlSchemaType) SchemaInfo(org.apache.cxf.service.model.SchemaInfo)

Aggregations

SchemaCollection (org.apache.cxf.common.xmlschema.SchemaCollection)23 ServiceInfo (org.apache.cxf.service.model.ServiceInfo)12 QName (javax.xml.namespace.QName)8 ArrayList (java.util.ArrayList)7 IOException (java.io.IOException)6 MessagePartInfo (org.apache.cxf.service.model.MessagePartInfo)6 XmlSchemaElement (org.apache.ws.commons.schema.XmlSchemaElement)5 HashMap (java.util.HashMap)4 LinkedHashMap (java.util.LinkedHashMap)4 Definition (javax.wsdl.Definition)4 Message (org.apache.cxf.common.i18n.Message)4 XmlSchema (org.apache.ws.commons.schema.XmlSchema)4 HashSet (java.util.HashSet)3 List (java.util.List)3 Map (java.util.Map)3 SchemaInfo (org.apache.cxf.service.model.SchemaInfo)3 ToolException (org.apache.cxf.tools.common.ToolException)3 XmlSchemaType (org.apache.ws.commons.schema.XmlSchemaType)3 File (java.io.File)2 URL (java.net.URL)2