Search in sources :

Example 1 with XmlAccessType

use of org.eclipse.persistence.jaxb.xmlmodel.XmlAccessType in project eclipselink by eclipse-ee4j.

the class AnnotationsProcessor method preProcessXmlAccessorType.

/**
 * Process @XmlAccessorType annotation on a given JavaClass and update the
 * TypeInfo for pre-processing.
 */
private void preProcessXmlAccessorType(JavaClass javaClass, TypeInfo info, NamespaceInfo packageNamespace) {
    org.eclipse.persistence.jaxb.xmlmodel.XmlAccessType xmlAccessType;
    if (javaClass.getDeclaredAnnotation(helper.getJavaClass(XmlAccessorType.class)) != null) {
        XmlAccessorType accessorType = (XmlAccessorType) helper.getAnnotation(javaClass, XmlAccessorType.class);
        xmlAccessType = org.eclipse.persistence.jaxb.xmlmodel.XmlAccessType.fromValue(accessorType.value().name());
        info.setXmlAccessType(xmlAccessType);
    }
}
Also used : XmlAccessorType(jakarta.xml.bind.annotation.XmlAccessorType) XmlAccessType(org.eclipse.persistence.jaxb.xmlmodel.XmlAccessType)

Example 2 with XmlAccessType

use of org.eclipse.persistence.jaxb.xmlmodel.XmlAccessType in project eclipselink by eclipse-ee4j.

the class XMLProcessor method createProperty.

private Property createProperty(TypeInfo info, JavaAttribute javaAttribute) {
    XmlAccessType xmlAccessorType = javaAttribute.getXmlAccessorType();
    // Property prop = new Property();
    // prop.setPropertyName(javaAttribute.getJavaAttribute());
    String propName = javaAttribute.getJavaAttribute();
    JavaHasAnnotations element = null;
    JavaClass pType = null;
    JavaClass jClass = this.jModelInput.getJavaModel().getClass(info.getJavaClassName());
    if (xmlAccessorType == XmlAccessType.PROPERTY) {
        // set up accessor method names
        String name = Character.toUpperCase(propName.charAt(0)) + propName.substring(1);
        String getMethodName = GET_STR + name;
        String setMethodName = SET_STR + name;
        JavaMethod jMethod = jClass.getDeclaredMethod(getMethodName, new JavaClass[] {});
        if (jMethod == null) {
            getMethodName = IS_STR + name;
            jMethod = jClass.getDeclaredMethod(getMethodName, new JavaClass[] {});
        }
        if (jMethod != null) {
            pType = jMethod.getReturnType();
            element = jMethod;
        } else {
            // look for a set method if type is set on javaAttribute
            for (Object next : jClass.getDeclaredMethods()) {
                JavaMethod nextMethod = (JavaMethod) next;
                if (nextMethod.getName().equals(setMethodName) && nextMethod.getParameterTypes().length == 1) {
                    pType = nextMethod.getParameterTypes()[0];
                    element = nextMethod;
                }
            }
            if (element == null) {
                return null;
            }
        }
    } else {
        JavaField jField = jClass.getDeclaredField(propName);
        if (jField == null) {
            return null;
        }
        pType = jField.getResolvedType();
        element = jField;
    }
    return this.aProcessor.buildNewProperty(info, jClass, element, propName, pType);
}
Also used : JavaField(org.eclipse.persistence.jaxb.javamodel.JavaField) JavaClass(org.eclipse.persistence.jaxb.javamodel.JavaClass) JavaMethod(org.eclipse.persistence.jaxb.javamodel.JavaMethod) XmlAccessType(org.eclipse.persistence.jaxb.xmlmodel.XmlAccessType) JavaHasAnnotations(org.eclipse.persistence.jaxb.javamodel.JavaHasAnnotations)

Aggregations

XmlAccessType (org.eclipse.persistence.jaxb.xmlmodel.XmlAccessType)2 XmlAccessorType (jakarta.xml.bind.annotation.XmlAccessorType)1 JavaClass (org.eclipse.persistence.jaxb.javamodel.JavaClass)1 JavaField (org.eclipse.persistence.jaxb.javamodel.JavaField)1 JavaHasAnnotations (org.eclipse.persistence.jaxb.javamodel.JavaHasAnnotations)1 JavaMethod (org.eclipse.persistence.jaxb.javamodel.JavaMethod)1