Search in sources :

Example 1 with Attribute

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

the class ObjCXMLClientModule 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 Objective-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 Objective-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 Objective-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 Objective-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 Objective-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 Objective-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 Objective-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 Objective-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 Objective-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 2 with Attribute

use of com.webcohesion.enunciate.modules.jaxb.model.Attribute 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 3 with Attribute

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

the class ComplexTypeExampleImpl method build.

private String build(Element rootElement, ComplexTypeDefinition type, final Document document, Context context) {
    if (context.stack.size() > 2) {
        // don't go deeper than 2 for fear of the OOM (see https://github.com/stoicflame/enunciate/issues/139).
        return rootElement.getNamespaceURI();
    }
    if (context.stack.contains(type.getQualifiedName().toString())) {
        return rootElement.getNamespaceURI();
    }
    String defaultNamespace = rootElement.getNamespaceURI();
    context.stack.push(type.getQualifiedName().toString());
    try {
        FacetFilter facetFilter = registrationContext.getFacetFilter();
        for (Attribute attribute : type.getAttributes()) {
            if (ElementUtils.findDeprecationMessage(attribute, null) != null) {
                continue;
            }
            if (!facetFilter.accept(attribute)) {
                continue;
            }
            String example = "...";
            JavaDoc.JavaDocTagList tags = getDocumentationExampleTags(attribute);
            if (tags != null && tags.size() > 0) {
                String tag = tags.get(0).trim();
                example = tag.isEmpty() ? null : tag;
            }
            DocumentationExample documentationExample = getDocumentationExample(attribute);
            if (documentationExample != null) {
                if (documentationExample.exclude()) {
                    continue;
                } else if (context.currentIndex == 1 && !"##default".equals(documentationExample.value2())) {
                    example = documentationExample.value2();
                } else if (!"##default".equals(documentationExample.value())) {
                    example = documentationExample.value();
                }
            }
            String configuredExample = getConfiguredExample(attribute);
            if (configuredExample != null) {
                example = configuredExample;
            }
            rootElement.setAttributeNS(attribute.getNamespace(), attribute.getName(), example);
            if (attribute.getNamespace() == null) {
                defaultNamespace = null;
            }
        }
        if (type.getValue() != null) {
            String example = "...";
            JavaDoc.JavaDocTagList tags = getDocumentationExampleTags(type.getValue());
            if (tags != null && tags.size() > 0) {
                String tag = tags.get(0).trim();
                example = tag.isEmpty() ? null : tag;
            }
            DocumentationExample documentationExample = getDocumentationExample(type.getValue());
            if (documentationExample != null) {
                if (!"##default".equals(documentationExample.value())) {
                    example = documentationExample.value();
                }
            }
            String configuredExample = getConfiguredExample(type.getValue());
            if (configuredExample != null) {
                example = configuredExample;
            }
            rootElement.setTextContent(example);
        } else {
            for (com.webcohesion.enunciate.modules.jaxb.model.Element element : type.getElements()) {
                if (ElementUtils.findDeprecationMessage(element, null) != null) {
                    continue;
                }
                if (!facetFilter.accept(element)) {
                    continue;
                }
                Element currentElement = rootElement;
                if (element.isWrapped()) {
                    Element wrapper = document.createElementNS(element.getWrapperNamespace(), element.getWrapperName());
                    rootElement.appendChild(wrapper);
                    currentElement = wrapper;
                    if (element.getWrapperNamespace() == null) {
                        defaultNamespace = null;
                    }
                }
                for (com.webcohesion.enunciate.modules.jaxb.model.Element choice : element.getChoices()) {
                    Element childElement = document.createElementNS(choice.getNamespace(), choice.getName());
                    if (choice.getNamespace() == null) {
                        defaultNamespace = null;
                    }
                    XmlType baseType = choice.getXmlType();
                    JavaDoc.JavaDocTagList tags = choice.getJavaDoc().get("documentationType");
                    if (tags != null && tags.size() > 0) {
                        String tag = tags.get(0).trim();
                        if (!tag.isEmpty()) {
                            TypeElement typeElement = type.getContext().getContext().getProcessingEnvironment().getElementUtils().getTypeElement(tag);
                            if (typeElement != null) {
                                baseType = XmlTypeFactory.getXmlType(typeElement.asType(), type.getContext());
                            } else {
                                type.getContext().getContext().getLogger().warn("Invalid documentation type %s.", tag);
                            }
                        }
                    }
                    DocumentationExample documentationExample = getDocumentationExample(choice);
                    if (documentationExample != null) {
                        TypeMirror typeHint = TypeHintUtils.getTypeHint(documentationExample.type(), type.getContext().getContext().getProcessingEnvironment(), null);
                        if (typeHint != null) {
                            baseType = XmlTypeFactory.getXmlType(typeHint, type.getContext());
                        }
                    }
                    if (baseType instanceof XmlClassType && ((XmlClassType) baseType).getTypeDefinition() instanceof ComplexTypeDefinition) {
                        String defaultChildNs = build(childElement, (ComplexTypeDefinition) ((XmlClassType) baseType).getTypeDefinition(), document, context);
                        if (defaultChildNs == null) {
                            defaultNamespace = null;
                        }
                    } else {
                        String example = "...";
                        tags = getDocumentationExampleTags(choice);
                        if (tags != null && tags.size() > 0) {
                            String tag = tags.get(0).trim();
                            example = tag.isEmpty() ? null : tag;
                        }
                        if (documentationExample != null) {
                            if (documentationExample.exclude()) {
                                continue;
                            } else if (context.currentIndex == 1 && !"##default".equals(documentationExample.value2())) {
                                example = documentationExample.value2();
                            } else if (!"##default".equals(documentationExample.value())) {
                                example = documentationExample.value();
                            }
                        }
                        String configuredExample = getConfiguredExample(choice);
                        if (configuredExample != null) {
                            example = configuredExample;
                        }
                        childElement.setTextContent(example);
                    }
                    currentElement.appendChild(childElement);
                }
            }
        }
        XmlType supertype = type.getBaseType();
        if (supertype instanceof XmlClassType && ((XmlClassType) supertype).getTypeDefinition() instanceof ComplexTypeDefinition) {
            String defaultSuperNs = build(rootElement, (ComplexTypeDefinition) ((XmlClassType) supertype).getTypeDefinition(), document, context);
            if (defaultSuperNs == null) {
                defaultNamespace = null;
            }
        }
        if (type.getAnyElement() != null && ElementUtils.findDeprecationMessage(type.getAnyElement(), null) == null) {
            Element extension1 = document.createElementNS(defaultNamespace, "extension1");
            extension1.setTextContent("...");
            rootElement.appendChild(extension1);
            Element extension2 = document.createElementNS(defaultNamespace, "extension2");
            extension2.setTextContent("...");
            rootElement.appendChild(extension2);
        }
    } finally {
        context.stack.pop();
    }
    return defaultNamespace;
}
Also used : FacetFilter(com.webcohesion.enunciate.facets.FacetFilter) Attribute(com.webcohesion.enunciate.modules.jaxb.model.Attribute) TypeElement(javax.lang.model.element.TypeElement) TypeElement(javax.lang.model.element.TypeElement) DecoratedElement(com.webcohesion.enunciate.javac.decorations.element.DecoratedElement) Element(org.w3c.dom.Element) JavaDoc(com.webcohesion.enunciate.javac.javadoc.JavaDoc) DocumentationExample(com.webcohesion.enunciate.metadata.DocumentationExample) XmlType(com.webcohesion.enunciate.modules.jaxb.model.types.XmlType) XmlClassType(com.webcohesion.enunciate.modules.jaxb.model.types.XmlClassType) DecoratedTypeMirror(com.webcohesion.enunciate.javac.decorations.type.DecoratedTypeMirror) TypeMirror(javax.lang.model.type.TypeMirror) ComplexTypeDefinition(com.webcohesion.enunciate.modules.jaxb.model.ComplexTypeDefinition)

Aggregations

Attribute (com.webcohesion.enunciate.modules.jaxb.model.Attribute)3 Element (com.webcohesion.enunciate.modules.jaxb.model.Element)2 SchemaInfo (com.webcohesion.enunciate.modules.jaxb.model.SchemaInfo)2 TypeDefinition (com.webcohesion.enunciate.modules.jaxb.model.TypeDefinition)2 MapType (com.webcohesion.enunciate.modules.jaxb.model.util.MapType)2 FacetFilter (com.webcohesion.enunciate.facets.FacetFilter)1 DecoratedElement (com.webcohesion.enunciate.javac.decorations.element.DecoratedElement)1 DecoratedTypeMirror (com.webcohesion.enunciate.javac.decorations.type.DecoratedTypeMirror)1 JavaDoc (com.webcohesion.enunciate.javac.javadoc.JavaDoc)1 DocumentationExample (com.webcohesion.enunciate.metadata.DocumentationExample)1 ComplexTypeDefinition (com.webcohesion.enunciate.modules.jaxb.model.ComplexTypeDefinition)1 XmlClassType (com.webcohesion.enunciate.modules.jaxb.model.types.XmlClassType)1 XmlType (com.webcohesion.enunciate.modules.jaxb.model.types.XmlType)1 TypeElement (javax.lang.model.element.TypeElement)1 TypeMirror (javax.lang.model.type.TypeMirror)1 Element (org.w3c.dom.Element)1