Search in sources :

Example 1 with Schema

use of com.sun.xml.ws.wsdl.writer.document.xsd.Schema in project metro-jax-ws by eclipse-ee4j.

the class ServiceArtifactSchemaGenerator method initWrappersSchemaWithImports.

// All the imports have to go first ...
private HashMap<String, Schema> initWrappersSchemaWithImports(List<WrapperParameter> wrappers) {
    Object o = model.databindingInfo().properties().get(RuntimeModeler.DocWrappeeNamespapceQualified);
    boolean wrappeeQualified = (o instanceof Boolean) ? ((Boolean) o) : false;
    HashMap<String, Schema> xsds = new HashMap<>();
    HashMap<String, Set<String>> imports = new HashMap<>();
    for (WrapperParameter wp : wrappers) {
        String tns = wp.getName().getNamespaceURI();
        Schema xsd = xsds.get(tns);
        if (xsd == null) {
            xsd = create(tns);
            xsd.targetNamespace(tns);
            if (wrappeeQualified)
                xsd._attribute("elementFormDefault", "qualified");
            xsds.put(tns, xsd);
        }
        for (ParameterImpl p : wp.getWrapperChildren()) {
            String nsToImport = (p.getBinding().isBody()) ? bodyParamNS(p) : null;
            if (nsToImport != null && !nsToImport.equals(tns) && !nsToImport.equals("http://www.w3.org/2001/XMLSchema")) {
                Set<String> importSet = imports.computeIfAbsent(tns, k -> new HashSet<>());
                importSet.add(nsToImport);
            }
        }
    }
    for (Entry<String, Set<String>> entry : imports.entrySet()) {
        String tns = entry.getKey();
        Set<String> importSet = entry.getValue();
        Schema xsd = xsds.get(tns);
        for (String nsToImport : importSet) xsd._namespace(nsToImport, true);
        for (String nsToImport : importSet) {
            com.sun.xml.ws.wsdl.writer.document.xsd.Import imp = xsd._import();
            imp.namespace(nsToImport);
        }
    }
    return xsds;
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) HashMap(java.util.HashMap) Schema(com.sun.xml.ws.wsdl.writer.document.xsd.Schema) WrapperParameter(com.sun.xml.ws.model.WrapperParameter) ParameterImpl(com.sun.xml.ws.model.ParameterImpl)

Example 2 with Schema

use of com.sun.xml.ws.wsdl.writer.document.xsd.Schema in project metro-jax-ws by eclipse-ee4j.

the class ServiceArtifactSchemaGenerator method generate.

public void generate(SchemaOutputResolver resolver) {
    xsdResolver = resolver;
    List<WrapperParameter> wrappers = new ArrayList<>();
    for (JavaMethodImpl method : model.getJavaMethods()) {
        if (method.getBinding().isRpcLit())
            continue;
        for (ParameterImpl p : method.getRequestParameters()) {
            if (p instanceof WrapperParameter) {
                if (WrapperComposite.class.equals((p.getTypeInfo().type))) {
                    wrappers.add((WrapperParameter) p);
                }
            }
        }
        for (ParameterImpl p : method.getResponseParameters()) {
            if (p instanceof WrapperParameter) {
                if (WrapperComposite.class.equals((p.getTypeInfo().type))) {
                    wrappers.add((WrapperParameter) p);
                }
            }
        }
    }
    if (wrappers.isEmpty())
        return;
    HashMap<String, Schema> xsds = initWrappersSchemaWithImports(wrappers);
    postInit(xsds);
    for (WrapperParameter wp : wrappers) {
        String tns = wp.getName().getNamespaceURI();
        Schema xsd = xsds.get(tns);
        Element e = xsd._element(Element.class);
        e._attribute("name", wp.getName().getLocalPart());
        e.type(wp.getName());
        ComplexType ct = xsd._element(ComplexType.class);
        ct._attribute("name", wp.getName().getLocalPart());
        ExplicitGroup sq = ct.sequence();
        for (ParameterImpl p : wp.getWrapperChildren()) if (p.getBinding().isBody())
            addChild(sq, p);
    }
    for (Schema xsd : xsds.values()) xsd.commit();
}
Also used : JavaMethodImpl(com.sun.xml.ws.model.JavaMethodImpl) ParameterImpl(com.sun.xml.ws.model.ParameterImpl) Schema(com.sun.xml.ws.wsdl.writer.document.xsd.Schema) LocalElement(org.glassfish.jaxb.runtime.v2.schemagen.xmlschema.LocalElement) Element(org.glassfish.jaxb.runtime.v2.schemagen.xmlschema.Element) ArrayList(java.util.ArrayList) WrapperParameter(com.sun.xml.ws.model.WrapperParameter) ComplexType(org.glassfish.jaxb.runtime.v2.schemagen.xmlschema.ComplexType) ExplicitGroup(org.glassfish.jaxb.runtime.v2.schemagen.xmlschema.ExplicitGroup)

Aggregations

ParameterImpl (com.sun.xml.ws.model.ParameterImpl)2 WrapperParameter (com.sun.xml.ws.model.WrapperParameter)2 Schema (com.sun.xml.ws.wsdl.writer.document.xsd.Schema)2 JavaMethodImpl (com.sun.xml.ws.model.JavaMethodImpl)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Set (java.util.Set)1 ComplexType (org.glassfish.jaxb.runtime.v2.schemagen.xmlschema.ComplexType)1 Element (org.glassfish.jaxb.runtime.v2.schemagen.xmlschema.Element)1 ExplicitGroup (org.glassfish.jaxb.runtime.v2.schemagen.xmlschema.ExplicitGroup)1 LocalElement (org.glassfish.jaxb.runtime.v2.schemagen.xmlschema.LocalElement)1