Search in sources :

Example 1 with JavaFieldImpl

use of org.eclipse.persistence.jaxb.javamodel.reflection.JavaFieldImpl in project eclipselink by eclipse-ee4j.

the class AnnotationsProcessor method getFieldPropertiesForClass.

public ArrayList<Property> getFieldPropertiesForClass(JavaClass cls, TypeInfo info, boolean onlyPublic, boolean onlyExplicit) {
    ArrayList<Property> properties = new ArrayList<>();
    if (cls == null) {
        return properties;
    }
    for (JavaField javaField : cls.getDeclaredFields()) {
        Property property = null;
        int modifiers = javaField.getModifiers();
        if (!Modifier.isTransient(modifiers) && ((Modifier.isPublic(javaField.getModifiers()) && onlyPublic) || !onlyPublic || hasJAXBAnnotations(javaField))) {
            if (!Modifier.isStatic(modifiers)) {
                if ((onlyExplicit && hasJAXBAnnotations(javaField)) || !onlyExplicit) {
                    try {
                        property = buildNewProperty(info, cls, javaField, javaField.getName(), javaField.getResolvedType());
                        properties.add(property);
                    } catch (JAXBException ex) {
                        if (ex.getErrorCode() != JAXBException.INVALID_INTERFACE || !helper.isAnnotationPresent(javaField, XmlTransient.class)) {
                            throw ex;
                        }
                    }
                }
            } else {
                try {
                    property = buildNewProperty(info, cls, javaField, javaField.getName(), javaField.getResolvedType());
                    if (helper.isAnnotationPresent(javaField, XmlAttribute.class)) {
                        Object value = ((JavaFieldImpl) javaField).get(null);
                        if (value != null) {
                            String stringValue = XMLConversionManager.getDefaultXMLManager().convertObject(value, String.class, property.getSchemaType());
                            property.setFixedValue(stringValue);
                        }
                    }
                    property.setWriteOnly(true);
                    if (!hasJAXBAnnotations(javaField)) {
                        property.setTransient(true);
                    }
                    properties.add(property);
                } catch (ClassCastException e) {
                // do Nothing
                } catch (IllegalAccessException e) {
                // do Nothing
                } catch (JAXBException ex) {
                    if (ex.getErrorCode() != JAXBException.INVALID_INTERFACE || !helper.isAnnotationPresent(javaField, XmlTransient.class)) {
                        throw ex;
                    }
                }
            }
        }
        if (helper.isAnnotationPresent(javaField, XmlTransient.class)) {
            if (property != null) {
                property.setTransient(true);
            }
        }
    }
    return properties;
}
Also used : JavaField(org.eclipse.persistence.jaxb.javamodel.JavaField) JAXBException(org.eclipse.persistence.exceptions.JAXBException) ArrayList(java.util.ArrayList) JavaFieldImpl(org.eclipse.persistence.jaxb.javamodel.reflection.JavaFieldImpl) XmlProperty(org.eclipse.persistence.oxm.annotations.XmlProperty) XmlTransient(jakarta.xml.bind.annotation.XmlTransient)

Aggregations

XmlTransient (jakarta.xml.bind.annotation.XmlTransient)1 ArrayList (java.util.ArrayList)1 JAXBException (org.eclipse.persistence.exceptions.JAXBException)1 JavaField (org.eclipse.persistence.jaxb.javamodel.JavaField)1 JavaFieldImpl (org.eclipse.persistence.jaxb.javamodel.reflection.JavaFieldImpl)1 XmlProperty (org.eclipse.persistence.oxm.annotations.XmlProperty)1