Search in sources :

Example 1 with PropertyElement

use of com.webcohesion.enunciate.javac.decorations.element.PropertyElement in project enunciate by stoicflame.

the class AccessorFilter method accept.

/**
 * Whether to accept the given member declaration as an accessor.
 *
 * @param element The declaration to filter.
 * @return Whether to accept the given member declaration as an accessor.
 */
public boolean accept(DecoratedElement<?> element) {
    if (context.isIgnored(element)) {
        return false;
    }
    if (element.getAnnotation(com.fasterxml.jackson.annotation.JsonProperty.class) != null) {
        // if there's an explicit json property annotation, we'll include it.
        return true;
    }
    if (this.honorJaxb) {
        if (element.getAnnotation(XmlTransient.class) != null) {
            return false;
        }
        for (String annotationName : element.getAnnotations().keySet()) {
            if (annotationName.startsWith("javax.xml.bind.annotation")) {
                // if the property has an explicit annotation, we'll include it.
                return true;
            }
        }
    }
    String name = element.getSimpleName().toString();
    if ("".equals(name)) {
        return false;
    }
    if (this.propertiesToIgnore.contains(name)) {
        return false;
    }
    if (element instanceof PropertyElement) {
        PropertyElement property = ((PropertyElement) element);
        DecoratedExecutableElement getter = property.getGetter();
        if (getter == null) {
            // needs a getter.
            return false;
        }
        if (!isVisible(findGetterVisibility(getter), getter)) {
            return false;
        }
        DecoratedExecutableElement setter = property.getSetter();
        if (setter != null && !isVisible(findSetterVisibility(), setter)) {
            return false;
        }
        return true;
    } else if (element instanceof DecoratedVariableElement) {
        if (!isVisible(findFieldVisibility(), element)) {
            return false;
        }
        if (element.isStatic() || element.isTransient()) {
            return false;
        }
        return true;
    }
    return false;
}
Also used : DecoratedVariableElement(com.webcohesion.enunciate.javac.decorations.element.DecoratedVariableElement) XmlTransient(javax.xml.bind.annotation.XmlTransient) DecoratedExecutableElement(com.webcohesion.enunciate.javac.decorations.element.DecoratedExecutableElement) PropertyElement(com.webcohesion.enunciate.javac.decorations.element.PropertyElement)

Example 2 with PropertyElement

use of com.webcohesion.enunciate.javac.decorations.element.PropertyElement in project enunciate by stoicflame.

the class Accessor method getXmlIDAccessor.

/**
 * Gets the xml id accessor for the specified class type (recursively through superclasses).
 *
 * @param classType The class type.
 * @return The xml id accessor.
 */
private DecoratedElement getXmlIDAccessor(DecoratedDeclaredType classType) {
    if (classType == null) {
        return null;
    }
    DecoratedTypeElement declaration = (DecoratedTypeElement) classType.asElement();
    if ((declaration == null) || (Object.class.getName().equals(declaration.getQualifiedName().toString()))) {
        return null;
    }
    for (VariableElement field : ElementFilter.fieldsIn(declaration.getEnclosedElements())) {
        if (field.getAnnotation(XmlID.class) != null) {
            return (DecoratedElement) field;
        }
    }
    for (PropertyElement property : declaration.getProperties()) {
        if (property.getAnnotation(XmlID.class) != null) {
            return property;
        }
    }
    TypeMirror superclass = declaration.getSuperclass();
    if (superclass == null || superclass.getKind() == TypeKind.NONE) {
        return null;
    }
    return getXmlIDAccessor((DecoratedDeclaredType) superclass);
}
Also used : DecoratedTypeElement(com.webcohesion.enunciate.javac.decorations.element.DecoratedTypeElement) DecoratedElement(com.webcohesion.enunciate.javac.decorations.element.DecoratedElement) DecoratedTypeMirror(com.webcohesion.enunciate.javac.decorations.type.DecoratedTypeMirror) VariableElement(javax.lang.model.element.VariableElement) PropertyElement(com.webcohesion.enunciate.javac.decorations.element.PropertyElement)

Example 3 with PropertyElement

use of com.webcohesion.enunciate.javac.decorations.element.PropertyElement in project enunciate by stoicflame.

the class WebFault method getChildElements.

/**
 * If this is an implicit fault bean, return the child elements.
 *
 * @return The child elements of the bean, or null if none.
 */
public Collection<ImplicitChildElement> getChildElements() {
    if (!isImplicitSchemaElement()) {
        return Collections.emptyList();
    }
    Set<ImplicitChildElement> childElements = new TreeSet<ImplicitChildElement>(new Comparator<ImplicitChildElement>() {

        public int compare(ImplicitChildElement o1, ImplicitChildElement o2) {
            return o1.getElementName().compareTo(o2.getElementName());
        }
    });
    for (PropertyElement property : getAllFaultProperties(this)) {
        String propertyName = property.getPropertyName();
        if (("cause".equals(propertyName)) || ("localizedMessage".equals(propertyName)) || ("stackTrace".equals(propertyName)) || "suppressed".equals(propertyName)) {
            continue;
        }
        childElements.add(new FaultBeanChildElement(property, this, context.getJaxbContext()));
    }
    return childElements;
}
Also used : ImplicitChildElement(com.webcohesion.enunciate.modules.jaxb.model.ImplicitChildElement) PropertyElement(com.webcohesion.enunciate.javac.decorations.element.PropertyElement)

Example 4 with PropertyElement

use of com.webcohesion.enunciate.javac.decorations.element.PropertyElement in project enunciate by stoicflame.

the class WebFault method getAllFaultProperties.

/**
 * Gets all properties, including properties from the superclass.
 *
 * @param declaration The declaration from which to get all properties.
 * @return All properties.
 */
protected Collection<PropertyElement> getAllFaultProperties(DecoratedTypeElement declaration) {
    ArrayList<PropertyElement> properties = new ArrayList<PropertyElement>();
    Set<String> excludedProperties = new TreeSet<String>();
    while ((declaration != null) && (!Object.class.getName().equals(declaration.getQualifiedName().toString()))) {
        for (PropertyElement property : declaration.getProperties()) {
            if (property.getGetter() != null && property.getAnnotation(XmlTransient.class) == null && !AnnotationUtils.isIgnored(property) && !excludedProperties.contains(property.getPropertyName())) {
                // only the readable properties that are not marked with @XmlTransient
                properties.add(property);
            } else {
                excludedProperties.add(property.getPropertyName());
            }
        }
        declaration = (DecoratedTypeElement) ((DeclaredType) declaration.getSuperclass()).asElement();
    }
    return properties;
}
Also used : PropertyElement(com.webcohesion.enunciate.javac.decorations.element.PropertyElement) DeclaredType(javax.lang.model.type.DeclaredType)

Example 5 with PropertyElement

use of com.webcohesion.enunciate.javac.decorations.element.PropertyElement in project enunciate by stoicflame.

the class AccessorFilter method accept.

/**
 * Whether to accept the given member declaration as an accessor.
 *
 * @param element The declaration to filter.
 * @return Whether to accept the given member declaration as an accessor.
 */
public boolean accept(DecoratedElement<?> element) {
    if (AnnotationUtils.isIgnored(element)) {
        return false;
    }
    if (element.getAnnotation(XmlTransient.class) != null) {
        return false;
    }
    if (element instanceof PropertyElement) {
        PropertyElement property = ((PropertyElement) element);
        if ("".equals(property.getPropertyName())) {
            return false;
        }
        for (String annotationName : property.getAnnotations().keySet()) {
            if (annotationName.startsWith("javax.xml.bind.annotation")) {
                // if the property has an explicit annotation, we'll include it.
                return true;
            }
        }
        DecoratedExecutableElement getter = property.getGetter();
        if (getter == null) {
            // needs a getter.
            return false;
        }
        DecoratedExecutableElement setter = property.getSetter();
        if (setter == null) {
            // needs a setter.
            return false;
        }
        if (!getter.isPublic()) {
            // we only have to worry about public methods ("properties" are only defined by public accessor methods).
            return false;
        }
        if (!setter.isPublic()) {
            // we only have to worry about public methods ("properties" are only defined by public accessor methods).
            return false;
        }
        return (((accessType != XmlAccessType.NONE) && (accessType != XmlAccessType.FIELD)) || (explicitlyDeclaredAccessor(element)));
    } else if (element instanceof DecoratedVariableElement) {
        if (element.isStatic() || element.isTransient()) {
            return false;
        }
        if ((accessType == XmlAccessType.NONE) || (accessType == XmlAccessType.PROPERTY)) {
            return explicitlyDeclaredAccessor(element);
        }
        if (accessType == XmlAccessType.PUBLIC_MEMBER) {
            return (element.isPublic() || (explicitlyDeclaredAccessor(element)));
        }
        // the accessType is FIELD.  Include it.
        return true;
    }
    return false;
}
Also used : DecoratedVariableElement(com.webcohesion.enunciate.javac.decorations.element.DecoratedVariableElement) XmlTransient(javax.xml.bind.annotation.XmlTransient) DecoratedExecutableElement(com.webcohesion.enunciate.javac.decorations.element.DecoratedExecutableElement) PropertyElement(com.webcohesion.enunciate.javac.decorations.element.PropertyElement)

Aggregations

PropertyElement (com.webcohesion.enunciate.javac.decorations.element.PropertyElement)7 DecoratedVariableElement (com.webcohesion.enunciate.javac.decorations.element.DecoratedVariableElement)4 DecoratedExecutableElement (com.webcohesion.enunciate.javac.decorations.element.DecoratedExecutableElement)3 XmlTransient (javax.xml.bind.annotation.XmlTransient)3 DecoratedTypeElement (com.webcohesion.enunciate.javac.decorations.element.DecoratedTypeElement)2 DeclaredType (javax.lang.model.type.DeclaredType)2 DecoratedElement (com.webcohesion.enunciate.javac.decorations.element.DecoratedElement)1 DecoratedTypeMirror (com.webcohesion.enunciate.javac.decorations.type.DecoratedTypeMirror)1 ImplicitChildElement (com.webcohesion.enunciate.modules.jaxb.model.ImplicitChildElement)1 VariableElement (javax.lang.model.element.VariableElement)1 JsonProperty (org.codehaus.jackson.annotate.JsonProperty)1