Find the xml element metadata for a specified JAXB property. - Java XML

Java examples for XML:JAXB

Description

Find the xml element metadata for a specified JAXB property.

Demo Code


//package com.java2s;
import javax.xml.bind.annotation.XmlElement;

import java.beans.PropertyDescriptor;

public class Main {
    /**//from   www. j  a  v  a  2 s . c  o m
     * Find the xml element metadata for a specified JAXB property.
     *
     * @param property The JAXB property for which to find the xml element metadata.
     * @return The xml element metadata, or null if none found.
     */
    public static XmlElement findXmlElement(PropertyDescriptor property) {
        XmlElement xmlElement = null;

        if (property.getReadMethod() != null) {
            xmlElement = property.getReadMethod().getAnnotation(
                    XmlElement.class);
        }

        if ((xmlElement == null) && (property.getWriteMethod() != null)) {
            xmlElement = property.getWriteMethod().getAnnotation(
                    XmlElement.class);
        }

        return xmlElement;
    }
}

Related Tutorials