Search in sources :

Example 1 with CatalogXmlSchemaURIResolver

use of org.apache.cxf.catalog.CatalogXmlSchemaURIResolver in project cxf by apache.

the class SchemaUtil method extractSchema.

private void extractSchema(Definition def, SchemaCollection schemaCol, List<SchemaInfo> schemaInfos) {
    Types typesElement = def.getTypes();
    if (typesElement != null) {
        int schemaCount = 1;
        for (Object obj : typesElement.getExtensibilityElements()) {
            org.w3c.dom.Element schemaElem = null;
            if (obj instanceof Schema) {
                Schema schema = (Schema) obj;
                schemaElem = schema.getElement();
            } else if (obj instanceof UnknownExtensibilityElement) {
                org.w3c.dom.Element elem = ((UnknownExtensibilityElement) obj).getElement();
                if (elem.getLocalName().equals("schema")) {
                    schemaElem = elem;
                }
            }
            if (schemaElem != null) {
                synchronized (schemaElem.getOwnerDocument()) {
                    for (Object prefix : def.getNamespaces().keySet()) {
                        String ns = (String) def.getNamespaces().get(prefix);
                        if ("".equals(prefix)) {
                            if (!schemaElem.hasAttribute("xmlns")) {
                                Attr attr = schemaElem.getOwnerDocument().createAttributeNS(javax.xml.XMLConstants.XMLNS_ATTRIBUTE_NS_URI, "xmlns");
                                attr.setValue(ns);
                                schemaElem.setAttributeNodeNS(attr);
                            }
                        } else if (!schemaElem.hasAttribute("xmlns:" + prefix)) {
                            String namespace = javax.xml.XMLConstants.XMLNS_ATTRIBUTE_NS_URI;
                            Attr attr = schemaElem.getOwnerDocument().createAttributeNS(namespace, "xmlns:" + prefix);
                            attr.setValue(ns);
                            schemaElem.setAttributeNodeNS(attr);
                        }
                    }
                    String systemId = def.getDocumentBaseURI() + "#types" + schemaCount;
                    if (def.getDocumentBaseURI() != null && def.getDocumentBaseURI().toUpperCase().endsWith(".XSD") && def.getTargetNamespace() == null && obj instanceof Schema && ((Schema) obj).getDocumentBaseURI().equals(def.getDocumentBaseURI())) {
                        systemId = def.getDocumentBaseURI();
                    }
                    schemaCol.setBaseUri(def.getDocumentBaseURI());
                    CatalogXmlSchemaURIResolver schemaResolver = new CatalogXmlSchemaURIResolver(bus);
                    schemaCol.setSchemaResolver(schemaResolver);
                    XmlSchema xmlSchema = schemaCol.read(schemaElem, systemId);
                    catalogResolved.putAll(schemaResolver.getResolvedMap());
                    SchemaInfo schemaInfo = new SchemaInfo(xmlSchema.getTargetNamespace());
                    schemaInfo.setSchema(xmlSchema);
                    schemaInfo.setSystemId(systemId);
                    schemaInfo.setElement(schemaElem);
                    schemaInfos.add(schemaInfo);
                    schemaCount++;
                }
            }
        }
    }
}
Also used : Types(javax.wsdl.Types) XmlSchema(org.apache.ws.commons.schema.XmlSchema) Schema(javax.wsdl.extensions.schema.Schema) UnknownExtensibilityElement(javax.wsdl.extensions.UnknownExtensibilityElement) Element(org.w3c.dom.Element) Attr(org.w3c.dom.Attr) Element(org.w3c.dom.Element) XmlSchema(org.apache.ws.commons.schema.XmlSchema) UnknownExtensibilityElement(javax.wsdl.extensions.UnknownExtensibilityElement) CatalogXmlSchemaURIResolver(org.apache.cxf.catalog.CatalogXmlSchemaURIResolver) SchemaInfo(org.apache.cxf.service.model.SchemaInfo)

Example 2 with CatalogXmlSchemaURIResolver

use of org.apache.cxf.catalog.CatalogXmlSchemaURIResolver in project cxf by apache.

the class ReflectionServiceFactoryBean method buildServiceFromClass.

protected void buildServiceFromClass() {
    Object o = getBus().getProperty("requireExplicitContractLocation");
    if (o != null && ("true".equals(o) || Boolean.TRUE.equals(o))) {
        throw new ServiceConstructionException(new Message("NO_WSDL_PROVIDED", LOG, getServiceClass().getName()));
    }
    if (LOG.isLoggable(Level.INFO)) {
        LOG.info("Creating Service " + getServiceQName() + " from class " + getServiceClass().getName());
    }
    populateFromClass = true;
    if (Proxy.isProxyClass(this.getServiceClass())) {
        LOG.log(Level.WARNING, "USING_PROXY_FOR_SERVICE", getServiceClass());
    }
    sendEvent(Event.CREATE_FROM_CLASS, getServiceClass());
    ServiceInfo serviceInfo = new ServiceInfo();
    SchemaCollection col = serviceInfo.getXmlSchemaCollection();
    col.getXmlSchemaCollection().setSchemaResolver(new CatalogXmlSchemaURIResolver(this.getBus()));
    col.getExtReg().registerSerializer(MimeAttribute.class, new MimeSerializer());
    ServiceImpl service = new ServiceImpl(serviceInfo);
    setService(service);
    setServiceProperties();
    serviceInfo.setName(getServiceQName());
    serviceInfo.setTargetNamespace(serviceInfo.getName().getNamespaceURI());
    sendEvent(Event.SERVICE_SET, getService());
    createInterface(serviceInfo);
    Set<?> wrapperClasses = this.getExtraClass();
    for (ServiceInfo si : getService().getServiceInfos()) {
        if (wrapperClasses != null && !wrapperClasses.isEmpty()) {
            si.setProperty(EXTRA_CLASS, wrapperClasses);
        }
    }
    initializeDataBindings();
    boolean isWrapped = isWrapped() || hasWrappedMethods(serviceInfo.getInterface());
    if (isWrapped) {
        initializeWrappedSchema(serviceInfo);
    }
    for (OperationInfo opInfo : serviceInfo.getInterface().getOperations()) {
        Method m = (Method) opInfo.getProperty(METHOD);
        if (!isWrapped(m) && !isRPC(m) && opInfo.getInput() != null) {
            createBareMessage(serviceInfo, opInfo, false);
        }
        if (!isWrapped(m) && !isRPC(m) && opInfo.getOutput() != null) {
            createBareMessage(serviceInfo, opInfo, true);
        }
        if (opInfo.hasFaults()) {
            // check to make sure the faults are elements
            for (FaultInfo fault : opInfo.getFaults()) {
                QName qn = (QName) fault.getProperty("elementName");
                MessagePartInfo part = fault.getFirstMessagePart();
                if (!part.isElement()) {
                    part.setElement(true);
                    part.setElementQName(qn);
                    checkForElement(serviceInfo, part);
                }
            }
        }
    }
    if (LOG.isLoggable(Level.FINE) || isValidate()) {
        ServiceModelSchemaValidator validator = new ServiceModelSchemaValidator(serviceInfo);
        validator.walk();
        String validationComplaints = validator.getComplaints();
        if (!"".equals(validationComplaints)) {
            if (isValidate()) {
                LOG.warning(validationComplaints);
            } else {
                LOG.fine(validationComplaints);
            }
        }
    }
}
Also used : OperationInfo(org.apache.cxf.service.model.OperationInfo) BindingOperationInfo(org.apache.cxf.service.model.BindingOperationInfo) UnwrappedOperationInfo(org.apache.cxf.service.model.UnwrappedOperationInfo) FaultInfo(org.apache.cxf.service.model.FaultInfo) Message(org.apache.cxf.common.i18n.Message) ServiceImpl(org.apache.cxf.service.ServiceImpl) QName(javax.xml.namespace.QName) ServiceModelSchemaValidator(org.apache.cxf.service.ServiceModelSchemaValidator) ServiceConstructionException(org.apache.cxf.service.factory.ServiceConstructionException) Method(java.lang.reflect.Method) MessagePartInfo(org.apache.cxf.service.model.MessagePartInfo) ServiceInfo(org.apache.cxf.service.model.ServiceInfo) MimeSerializer(org.apache.cxf.databinding.source.mime.MimeSerializer) CatalogXmlSchemaURIResolver(org.apache.cxf.catalog.CatalogXmlSchemaURIResolver) SchemaCollection(org.apache.cxf.common.xmlschema.SchemaCollection)

Aggregations

CatalogXmlSchemaURIResolver (org.apache.cxf.catalog.CatalogXmlSchemaURIResolver)2 Method (java.lang.reflect.Method)1 Types (javax.wsdl.Types)1 UnknownExtensibilityElement (javax.wsdl.extensions.UnknownExtensibilityElement)1 Schema (javax.wsdl.extensions.schema.Schema)1 QName (javax.xml.namespace.QName)1 Message (org.apache.cxf.common.i18n.Message)1 SchemaCollection (org.apache.cxf.common.xmlschema.SchemaCollection)1 MimeSerializer (org.apache.cxf.databinding.source.mime.MimeSerializer)1 ServiceImpl (org.apache.cxf.service.ServiceImpl)1 ServiceModelSchemaValidator (org.apache.cxf.service.ServiceModelSchemaValidator)1 ServiceConstructionException (org.apache.cxf.service.factory.ServiceConstructionException)1 BindingOperationInfo (org.apache.cxf.service.model.BindingOperationInfo)1 FaultInfo (org.apache.cxf.service.model.FaultInfo)1 MessagePartInfo (org.apache.cxf.service.model.MessagePartInfo)1 OperationInfo (org.apache.cxf.service.model.OperationInfo)1 SchemaInfo (org.apache.cxf.service.model.SchemaInfo)1 ServiceInfo (org.apache.cxf.service.model.ServiceInfo)1 UnwrappedOperationInfo (org.apache.cxf.service.model.UnwrappedOperationInfo)1 XmlSchema (org.apache.ws.commons.schema.XmlSchema)1