Java XML Element Check isXmlElementRequired(Field f)

Here you can find the source of isXmlElementRequired(Field f)

Description

Checks if the XML element filed is required.

License

Open Source License

Parameter

Parameter Description
Field f

Return

boolean

Declaration

public static boolean isXmlElementRequired(Field f) 

Method Source Code

//package com.java2s;
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell

import java.lang.reflect.Field;

import javax.xml.bind.annotation.XmlElement;

import javax.xml.bind.annotation.XmlElementRefs;
import javax.xml.bind.annotation.XmlElements;

public class Main {
    /** Checks if the XML element filed is required. 
     * /*from  www. j  ava2 s .c o  m*/
     * @param Field f
     * 
     * @return boolean
     * 
     * */
    public static boolean isXmlElementRequired(Field f) {
        boolean ret = false;

        if (null != f) {
            XmlElement xmlElement = getXmlElement(f);
            if (null != xmlElement) {
                ret = xmlElement.required();
            } else {
                XmlElementRefs xmlElementRefs = getXmlElementRefs(f);
                if (null != xmlElementRefs) {
                    // For all "Order" and "Group" indicators (any, all, choice, sequence, group name, and group reference) 
                    // the default value for maxOccurs and minOccurs is 1.
                    ret = true;
                } else {
                    XmlElements xmlElements = getXmlElements(f);
                    if (null != xmlElements) {
                        // For all "Order" and "Group" indicators (any, all, choice, sequence, group name, and group reference) 
                        // the default value for maxOccurs and minOccurs is 1.
                        ret = true;
                    }
                }
            }
        }

        return ret;
    }

    public static XmlElement getXmlElement(Field f) {
        XmlElement ret = null;

        if (null != f) {
            ret = (XmlElement) f.getAnnotation(XmlElement.class);
        }

        return ret;
    }

    public static XmlElementRefs getXmlElementRefs(Field f) {
        XmlElementRefs ret = null;

        if (null != f) {
            ret = (XmlElementRefs) f.getAnnotation(XmlElementRefs.class);
        }

        return ret;
    }

    public static XmlElements getXmlElements(Field f) {
        XmlElements ret = null;

        if (null != f) {
            ret = (XmlElements) f.getAnnotation(XmlElements.class);
        }

        return ret;
    }
}

Related

  1. isTextOnly(final Element element)
  2. isTrue(Element el, String tagName, boolean defaultResult)
  3. isUIParameter(Element ele)
  4. isUnder5_6(Element root)
  5. isXmlElementChoice(Field f, String xmlElementName)
  6. isXULElement(Element elem)