Search in sources :

Example 1 with Element

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

the class ReferencedNamespacesMethod method addReferencedNamespaces.

/**
 * Adds the referenced namespaces of the given type definition to the given set.
 *
 * @param typeDefinition The type definition.
 * @param referencedNamespaces The set of referenced namespaces.
 */
private void addReferencedNamespaces(TypeDefinition typeDefinition, Set<String> referencedNamespaces) {
    for (Attribute attribute : typeDefinition.getAttributes()) {
        QName ref = attribute.getRef();
        if (ref != null) {
            referencedNamespaces.add(ref.getNamespaceURI());
        } else {
            addReferencedNamespaces(attribute.getBaseType(), referencedNamespaces);
        }
    }
    for (Element element : typeDefinition.getElements()) {
        for (Element choice : element.getChoices()) {
            QName ref = choice.getRef();
            if (ref != null) {
                referencedNamespaces.add(ref.getNamespaceURI());
            } else {
                addReferencedNamespaces(choice.getBaseType(), referencedNamespaces);
            }
        }
    }
    Value value = typeDefinition.getValue();
    if (value != null) {
        addReferencedNamespaces(value.getBaseType(), referencedNamespaces);
    }
    if (typeDefinition instanceof QNameEnumTypeDefinition) {
        for (EnumValue enumValue : ((QNameEnumTypeDefinition) typeDefinition).getEnumValues()) {
            if (enumValue.getValue() != null) {
                referencedNamespaces.add(((QName) enumValue.getValue()).getNamespaceURI());
            }
        }
    }
    addReferencedNamespaces(typeDefinition.getBaseType(), referencedNamespaces);
}
Also used : QName(javax.xml.namespace.QName) Element(com.webcohesion.enunciate.modules.jaxb.model.Element)

Example 2 with Element

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

the class ReferencedNamespacesMethod method exec.

public Object exec(List list) throws TemplateModelException {
    if (list.size() < 1) {
        throw new TemplateModelException("The referencedNamespaces method must have an element as a parameter.");
    }
    TemplateModel from = (TemplateModel) list.get(0);
    Object unwrapped = BeansWrapper.getDefaultInstance().unwrap(from);
    if (!(unwrapped instanceof ElementDeclaration)) {
        throw new TemplateModelException("The referencedNamespaces method must have an element as a parameter.");
    }
    ElementDeclaration elementDeclaration = (ElementDeclaration) unwrapped;
    Set<String> referencedNamespaces = new HashSet<String>();
    referencedNamespaces.add(elementDeclaration.getNamespace());
    if (elementDeclaration instanceof RootElementDeclaration) {
        TypeDefinition typeDef = ((RootElementDeclaration) elementDeclaration).getTypeDefinition();
        addReferencedNamespaces(typeDef, referencedNamespaces);
    } else if (elementDeclaration instanceof LocalElementDeclaration) {
        TypeElement typeElement = null;
        TypeMirror elementType = ((LocalElementDeclaration) elementDeclaration).getElementType();
        if (elementType instanceof DeclaredType) {
            javax.lang.model.element.Element element = ((DeclaredType) elementType).asElement();
            if (element instanceof TypeElement) {
                typeElement = (TypeElement) element;
            }
        }
        TypeDefinition typeDefinition = this.context.findTypeDefinition(typeElement);
        if (typeDefinition != null) {
            addReferencedNamespaces(typeDefinition, referencedNamespaces);
        }
    }
    referencedNamespaces.remove(null);
    referencedNamespaces.remove("");
    referencedNamespaces.remove("http://www.w3.org/2001/XMLSchema");
    return referencedNamespaces;
}
Also used : TemplateModelException(freemarker.template.TemplateModelException) Element(com.webcohesion.enunciate.modules.jaxb.model.Element) TemplateModel(freemarker.template.TemplateModel) TypeMirror(javax.lang.model.type.TypeMirror) com.webcohesion.enunciate.modules.jaxb.model(com.webcohesion.enunciate.modules.jaxb.model) HashSet(java.util.HashSet) DeclaredType(javax.lang.model.type.DeclaredType)

Example 3 with Element

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

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

the class PHPXMLClientModule 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()) {
                if (!Character.isUpperCase(complexType.getClientSimpleName().charAt(0))) {
                    warn("%s: PHP requires your class name to be upper-case. Please rename the class or apply the @org.codehaus.enunciate.ClientName annotation to the class.", positionOf(complexType));
                    usesUnmappableElements = true;
                }
                for (Element element : complexType.getElements()) {
                    if (element instanceof ElementRef && element.isElementRefs()) {
                        info("%s: The PHP client library doesn't fully support the @XmlElementRefs annotation. The items in the collection will be read-only and will only be available to PHP clients in the form of a Hash. Consider redesigning using a collection of a single type.", positionOf(element));
                    } else if (element.getAnnotation(XmlElements.class) != null) {
                        info("%s: The PHP client library doesn't fully support the @XmlElements annotation. The items in the collection will be read-only and will only be available to PHP clients in the form of a Hash. Consider redesigning using a collection of a single type.", positionOf(element));
                    }
                }
            }
        }
    }
    return usesUnmappableElements;
}
Also used : ElementRef(com.webcohesion.enunciate.modules.jaxb.model.ElementRef) TypeElement(javax.lang.model.element.TypeElement) DecoratedTypeElement(com.webcohesion.enunciate.javac.decorations.element.DecoratedTypeElement) Element(com.webcohesion.enunciate.modules.jaxb.model.Element) SchemaInfo(com.webcohesion.enunciate.modules.jaxb.model.SchemaInfo) TypeDefinition(com.webcohesion.enunciate.modules.jaxb.model.TypeDefinition)

Example 5 with Element

use of com.webcohesion.enunciate.modules.jaxb.model.Element 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)

Aggregations

Element (com.webcohesion.enunciate.modules.jaxb.model.Element)6 TypeDefinition (com.webcohesion.enunciate.modules.jaxb.model.TypeDefinition)4 SchemaInfo (com.webcohesion.enunciate.modules.jaxb.model.SchemaInfo)3 Attribute (com.webcohesion.enunciate.modules.jaxb.model.Attribute)2 MapType (com.webcohesion.enunciate.modules.jaxb.model.util.MapType)2 TemplateModel (freemarker.template.TemplateModel)2 TemplateModelException (freemarker.template.TemplateModelException)2 QName (javax.xml.namespace.QName)2 DecoratedTypeElement (com.webcohesion.enunciate.javac.decorations.element.DecoratedTypeElement)1 DecoratedTypeMirror (com.webcohesion.enunciate.javac.decorations.type.DecoratedTypeMirror)1 com.webcohesion.enunciate.modules.jaxb.model (com.webcohesion.enunciate.modules.jaxb.model)1 Accessor (com.webcohesion.enunciate.modules.jaxb.model.Accessor)1 ElementDeclaration (com.webcohesion.enunciate.modules.jaxb.model.ElementDeclaration)1 ElementRef (com.webcohesion.enunciate.modules.jaxb.model.ElementRef)1 HashSet (java.util.HashSet)1 TypeElement (javax.lang.model.element.TypeElement)1 DeclaredType (javax.lang.model.type.DeclaredType)1 TypeMirror (javax.lang.model.type.TypeMirror)1 JAXBElement (javax.xml.bind.JAXBElement)1