Search in sources :

Example 6 with SchemaInfo

use of org.apache.cxf.service.model.SchemaInfo in project cxf by apache.

the class ServiceWSDLBuilder method buildTypesWithSchemaImports.

/**
 * @param schemas
 * @param imports
 * @param def
 */
protected void buildTypesWithSchemaImports(final Collection<SchemaInfo> schemas, final Map<String, SchemaInfo> imports, final Definition def) {
    Types types = def.createTypes();
    Map<String, Schema> namespaceToSchemaMap = new HashMap<>();
    Map<String, SchemaInfo> namespaceToSchemaInfo = new HashMap<>();
    for (SchemaInfo schemaInfo : schemas) {
        Schema schema = getSchemaImplementation(def);
        schema.setRequired(true);
        schema.setElementType(WSDLConstants.QNAME_SCHEMA);
        String name = baseFileName + "_schema" + (++xsdCount) + ".xsd";
        schema.setDocumentBaseURI(name);
        schema.setElement(schemaInfo.getElement());
        namespaceToSchemaMap.put(schemaInfo.getNamespaceURI(), schema);
        namespaceToSchemaInfo.put(schemaInfo.getNamespaceURI(), schemaInfo);
        imports.put(name, schemaInfo);
    }
    for (Schema schema : namespaceToSchemaMap.values()) {
        Element docElement = schema.getElement();
        List<Element> elementList = DOMUtils.findAllElementsByTagNameNS(docElement, "http://www.w3.org/2001/XMLSchema", "import");
        for (Element el : elementList) {
            String sn = el.getAttribute("namespace");
            Schema referencedSchema = namespaceToSchemaMap.get(sn);
            if (referencedSchema != null) {
                SchemaInfo schemaInfo = namespaceToSchemaInfo.get(sn);
                el.setAttribute("schemaLocation", referencedSchema.getDocumentBaseURI());
                addSchemaImport(schema, schemaInfo, referencedSchema);
            }
        }
    }
    Document doc = DOMUtils.createDocument();
    Element nd = doc.createElementNS(WSDLConstants.NS_SCHEMA_XSD, "schema");
    nd.setAttribute("xmlns", WSDLConstants.NS_SCHEMA_XSD);
    doc.appendChild(nd);
    Schema schema = getSchemaImplementation(def);
    schema.setRequired(true);
    schema.setElementType(WSDLConstants.QNAME_SCHEMA);
    Collection<String> defNamespaces = CastUtils.cast(def.getNamespaces().values());
    for (SchemaInfo schemaInfo : schemas) {
        Schema referencedSchema = namespaceToSchemaMap.get(schemaInfo.getNamespaceURI());
        // this ensures only the schemas directly referenced by the wsdl are included.
        if (defNamespaces.contains(schemaInfo.getNamespaceURI())) {
            Element impElement = doc.createElementNS(WSDLConstants.NS_SCHEMA_XSD, "import");
            impElement.setAttribute("schemaLocation", referencedSchema.getDocumentBaseURI());
            impElement.setAttribute("namespace", schemaInfo.getNamespaceURI());
            nd.appendChild(impElement);
            addSchemaImport(schema, schemaInfo, referencedSchema);
        }
    }
    schema.setElement(nd);
    types.addExtensibilityElement(schema);
    def.setTypes(types);
}
Also used : Types(javax.wsdl.Types) HashMap(java.util.HashMap) Schema(javax.wsdl.extensions.schema.Schema) WSDLElement(javax.wsdl.WSDLElement) UnknownExtensibilityElement(javax.wsdl.extensions.UnknownExtensibilityElement) ExtensibilityElement(javax.wsdl.extensions.ExtensibilityElement) Element(org.w3c.dom.Element) Document(org.w3c.dom.Document) SchemaInfo(org.apache.cxf.service.model.SchemaInfo)

Example 7 with SchemaInfo

use of org.apache.cxf.service.model.SchemaInfo in project cxf by apache.

the class WSDLServiceBuilderTest method testSchema.

@Test
public void testSchema() throws Exception {
    setUpBasic();
    SchemaCollection schemas = serviceInfo.getXmlSchemaCollection();
    assertNotNull(schemas);
    assertEquals(1, serviceInfo.getSchemas().size());
    SchemaInfo schemaInfo = serviceInfo.getSchemas().iterator().next();
    assertNotNull(schemaInfo);
    assertEquals(schemaInfo.getNamespaceURI(), "http://apache.org/hello_world_soap_http/types");
    assertEquals(schemas.read(schemaInfo.getElement()).getTargetNamespace(), "http://apache.org/hello_world_soap_http/types");
    // add below code to test the creation of javax.xml.validation.Schema
    // with schema in serviceInfo
    Schema schema = EndpointReferenceUtils.getSchema(serviceInfo);
    assertNotNull(schema);
    control.verify();
}
Also used : Schema(javax.xml.validation.Schema) SchemaCollection(org.apache.cxf.common.xmlschema.SchemaCollection) SchemaInfo(org.apache.cxf.service.model.SchemaInfo) Test(org.junit.Test)

Example 8 with SchemaInfo

use of org.apache.cxf.service.model.SchemaInfo in project cxf by apache.

the class ReflectionServiceFactoryBean method createWrappedSchema.

protected void createWrappedSchema(ServiceInfo serviceInfo, AbstractMessageContainer wrappedMessage, AbstractMessageContainer unwrappedMessage, QName wrapperBeanName) {
    SchemaInfo schemaInfo = getOrCreateSchema(serviceInfo, wrapperBeanName.getNamespaceURI(), getQualifyWrapperSchema());
    createWrappedMessageSchema(serviceInfo, wrappedMessage, unwrappedMessage, schemaInfo, wrapperBeanName);
}
Also used : SchemaInfo(org.apache.cxf.service.model.SchemaInfo)

Example 9 with SchemaInfo

use of org.apache.cxf.service.model.SchemaInfo in project cxf by apache.

the class WrapperClassGenerator method generatePackageInfo.

private void generatePackageInfo(String className, String ns, Class<?> clz) {
    ClassWriter cw = createClassWriter();
    String classFileName = periodToSlashes(className);
    cw.visit(Opcodes.V1_5, Opcodes.ACC_ABSTRACT + Opcodes.ACC_INTERFACE, classFileName, null, "java/lang/Object", null);
    boolean q = qualified;
    SchemaInfo si = interfaceInfo.getService().getSchema(ns);
    if (si != null) {
        q = si.isElementFormQualified();
    }
    AnnotationVisitor av0 = cw.visitAnnotation("Ljavax/xml/bind/annotation/XmlSchema;", true);
    av0.visit("namespace", ns);
    av0.visitEnum("elementFormDefault", getClassCode(XmlNsForm.class), q ? "QUALIFIED" : "UNQUALIFIED");
    av0.visitEnd();
    if (clz.getPackage() != null && clz.getPackage().getAnnotations() != null) {
        for (Annotation ann : clz.getPackage().getAnnotations()) {
            if (ann instanceof XmlJavaTypeAdapters) {
                av0 = cw.visitAnnotation("Ljavax/xml/bind/annotation/adapters/XmlJavaTypeAdapters;", true);
                generateXmlJavaTypeAdapters(av0, (XmlJavaTypeAdapters) ann);
                av0.visitEnd();
            } else if (ann instanceof XmlJavaTypeAdapter) {
                av0 = cw.visitAnnotation("Ljavax/xml/bind/annotation/adapters/XmlJavaTypeAdapter;", true);
                generateXmlJavaTypeAdapter(av0, (XmlJavaTypeAdapter) ann);
                av0.visitEnd();
            }
        }
    }
    cw.visitEnd();
    loadClass(className, clz, cw.toByteArray());
}
Also used : XmlNsForm(javax.xml.bind.annotation.XmlNsForm) XmlJavaTypeAdapter(javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter) XmlJavaTypeAdapters(javax.xml.bind.annotation.adapters.XmlJavaTypeAdapters) Annotation(java.lang.annotation.Annotation) SchemaInfo(org.apache.cxf.service.model.SchemaInfo)

Example 10 with SchemaInfo

use of org.apache.cxf.service.model.SchemaInfo in project cxf by apache.

the class CorbaUtils method isAttributeFormQualified.

// Change this method to access the XmlSchemaCollection.
public static boolean isAttributeFormQualified(ServiceInfo serviceInfo, String uri) {
    if (uri != null) {
        SchemaInfo schemaInfo = serviceInfo.getSchema(uri);
        if (schemaInfo != null) {
            return schemaInfo.isAttributeFormQualified();
        }
        Iterator<SchemaInfo> it = serviceInfo.getSchemas().iterator();
        while (it.hasNext()) {
            XmlSchema schema = it.next().getSchema();
            return isAttributeFormQualified(schema, uri);
        }
    }
    return false;
}
Also used : XmlSchema(org.apache.ws.commons.schema.XmlSchema) SchemaInfo(org.apache.cxf.service.model.SchemaInfo)

Aggregations

SchemaInfo (org.apache.cxf.service.model.SchemaInfo)42 XmlSchema (org.apache.ws.commons.schema.XmlSchema)17 QName (javax.xml.namespace.QName)11 ServiceInfo (org.apache.cxf.service.model.ServiceInfo)11 Element (org.w3c.dom.Element)10 XmlSchemaElement (org.apache.ws.commons.schema.XmlSchemaElement)9 IOException (java.io.IOException)8 HashMap (java.util.HashMap)7 XMLStreamException (javax.xml.stream.XMLStreamException)7 Message (org.apache.cxf.common.i18n.Message)6 FileNotFoundException (java.io.FileNotFoundException)5 URL (java.net.URL)5 MessagePartInfo (org.apache.cxf.service.model.MessagePartInfo)5 InputSource (org.xml.sax.InputSource)5 SAXException (org.xml.sax.SAXException)5 SAXParseException (org.xml.sax.SAXParseException)5 File (java.io.File)4 Method (java.lang.reflect.Method)4 HashSet (java.util.HashSet)4 SchemaCollection (org.apache.cxf.common.xmlschema.SchemaCollection)4