Search in sources :

Example 16 with SchemaInfo

use of com.webcohesion.enunciate.modules.jaxb.model.SchemaInfo in project enunciate by stoicflame.

the class CXMLClientModule method usesUnmappableElements.

protected boolean usesUnmappableElements() {
    boolean usesUnmappableElements = false;
    if (this.jaxbModule != null && this.jaxbModule.getJaxbContext() != null && !this.jaxbModule.getJaxbContext().getSchemas().isEmpty()) {
        for (SchemaInfo schemaInfo : this.jaxbModule.getJaxbContext().getSchemas().values()) {
            for (TypeDefinition complexType : schemaInfo.getTypeDefinitions()) {
                for (Attribute attribute : complexType.getAttributes()) {
                    if (attribute.isXmlList()) {
                        info("%s: The C client code won't serialize xml lists as an array, instead passing the list as a string that will need to be parsed. This may cause confusion to C consumers.", positionOf(attribute));
                    }
                    if (attribute.isCollectionType() && attribute.isBinaryData()) {
                        warn("%s: The C client code doesn't support a collection of items that are binary data. You'll have to define separate accessors for each item or disable the C module.", positionOf(attribute));
                        usesUnmappableElements = true;
                    }
                }
                if (complexType.getValue() != null) {
                    if (complexType.getValue().isXmlList()) {
                        info("%s: The C client code won't serialize xml lists as an array, instead passing the list as a string that will need to be parsed. This may cause confusion to C consumers.", positionOf(complexType.getValue()));
                    }
                    if (complexType.getValue().isCollectionType() && complexType.getValue().isBinaryData()) {
                        warn("%s: The C client code doesn't support a collection of items that are binary data.", positionOf(complexType.getValue()));
                        usesUnmappableElements = true;
                    }
                }
                for (Element element : complexType.getElements()) {
                    if (element.isXmlList()) {
                        info("%s: The C client code won't serialize xml lists as an array, instead passing the list as a string that will need to be parsed. This may cause confusion to C consumers.", positionOf(element));
                    }
                    if (element.getAccessorType() instanceof MapType && !element.isAdapted()) {
                        warn("%s: The C client doesn't have a built-in way of serializing a Map. Use @XmlJavaTypeAdapter to supply your own adapter for the Map.", positionOf(element));
                        usesUnmappableElements = true;
                    }
                    if (element.isCollectionType()) {
                        if (element.getChoices().size() > 1) {
                            info("%s: The C client code doesn't fully support multiple choices for a collection. It has to separate each choice into its own array. " + "This makes the C API a bit awkward to use and makes it impossible to preserve the order of the collection. If order is relevant, consider breaking out " + "the choices into their own collection or otherwise refactoring the API.", positionOf(element));
                        }
                        if (element.isBinaryData()) {
                            warn("%s: The C client code doesn't support a collection of items that are binary data.", positionOf(element));
                            usesUnmappableElements = true;
                        }
                        for (Element choice : element.getChoices()) {
                            if (choice.isNillable()) {
                                info("%s: The C client code doesn't support nillable items in a collection (the nil items will be skipped). This may cause confusion to C consumers.", positionOf(choice));
                            }
                        }
                    }
                }
            }
        }
    }
    return usesUnmappableElements;
}
Also used : Attribute(com.webcohesion.enunciate.modules.jaxb.model.Attribute) Element(com.webcohesion.enunciate.modules.jaxb.model.Element) MapType(com.webcohesion.enunciate.modules.jaxb.model.util.MapType) SchemaInfo(com.webcohesion.enunciate.modules.jaxb.model.SchemaInfo) TypeDefinition(com.webcohesion.enunciate.modules.jaxb.model.TypeDefinition)

Example 17 with SchemaInfo

use of com.webcohesion.enunciate.modules.jaxb.model.SchemaInfo in project enunciate by stoicflame.

the class NamespacePropertiesArtifact method exportTo.

@Override
public void exportTo(File fileOrDirectory, Enunciate enunciate) throws IOException {
    Properties properties = new Properties();
    for (Map.Entry<String, String> ns2prefix : this.jaxbContext.getNamespacePrefixes().entrySet()) {
        if (ns2prefix.getKey() != null) {
            properties.put(ns2prefix.getKey(), ns2prefix.getValue());
        }
    }
    String defaultNs = jaxbContext.getContext().getConfiguration().getDefaultNamespace();
    if (defaultNs == null) {
        SchemaInfo schemaWithTheMostTypes = null;
        for (SchemaInfo schemaInfo : this.jaxbContext.getSchemas().values()) {
            if (schemaWithTheMostTypes == null) {
                schemaWithTheMostTypes = schemaInfo;
            } else if (schemaWithTheMostTypes.getTypeDefinitions().size() < schemaInfo.getTypeDefinitions().size()) {
                schemaWithTheMostTypes = schemaInfo;
            }
        }
        if (schemaWithTheMostTypes != null && schemaWithTheMostTypes.getNamespace() != null && !properties.containsValue(schemaWithTheMostTypes.getNamespace())) {
            defaultNs = schemaWithTheMostTypes.getNamespace();
        }
    }
    if (defaultNs != null) {
        properties.put("{default}", defaultNs);
    }
    FileOutputStream out = new FileOutputStream(fileOrDirectory.isDirectory() ? new File(fileOrDirectory, getName()) : fileOrDirectory);
    properties.store(out, "Namespace properties, generated by Enunciate.");
    out.flush();
    out.close();
}
Also used : FileOutputStream(java.io.FileOutputStream) Properties(java.util.Properties) Map(java.util.Map) File(java.io.File) SchemaInfo(com.webcohesion.enunciate.modules.jaxb.model.SchemaInfo)

Aggregations

SchemaInfo (com.webcohesion.enunciate.modules.jaxb.model.SchemaInfo)17 TypeDefinition (com.webcohesion.enunciate.modules.jaxb.model.TypeDefinition)8 EnunciateException (com.webcohesion.enunciate.EnunciateException)5 FacetFilter (com.webcohesion.enunciate.facets.FacetFilter)5 File (java.io.File)5 WsdlInfo (com.webcohesion.enunciate.modules.jaxws.WsdlInfo)4 URL (java.net.URL)4 ClientLibraryArtifact (com.webcohesion.enunciate.artifacts.ClientLibraryArtifact)3 FileArtifact (com.webcohesion.enunciate.artifacts.FileArtifact)3 EnunciateJaxbContext (com.webcohesion.enunciate.modules.jaxb.EnunciateJaxbContext)3 Element (com.webcohesion.enunciate.modules.jaxb.model.Element)3 AccessorOverridesAnotherMethod (com.webcohesion.enunciate.modules.jaxb.util.AccessorOverridesAnotherMethod)3 FindRootElementMethod (com.webcohesion.enunciate.modules.jaxb.util.FindRootElementMethod)3 TemplateException (freemarker.template.TemplateException)3 IOException (java.io.IOException)3 Attribute (com.webcohesion.enunciate.modules.jaxb.model.Attribute)2 Registry (com.webcohesion.enunciate.modules.jaxb.model.Registry)2 MapType (com.webcohesion.enunciate.modules.jaxb.model.util.MapType)2 ReferencedNamespacesMethod (com.webcohesion.enunciate.modules.jaxb.util.ReferencedNamespacesMethod)2 FileDirective (com.webcohesion.enunciate.util.freemarker.FileDirective)2