Java XML Attribute Exist isAttribute(Object obj)

Here you can find the source of isAttribute(Object obj)

Description

Checks if the class field is XML attribute.

License

Open Source License

Parameter

Parameter Description
obj a parameter

Return

boolean

Declaration

public static boolean isAttribute(Object obj) 

Method Source Code


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

import java.lang.annotation.Annotation;
import java.lang.reflect.Field;

import javax.xml.bind.annotation.XmlAnyAttribute;
import javax.xml.bind.annotation.XmlAttribute;

public class Main {
    /** Checks if the class field is XML attribute. 
     * /*from   w  w  w  .  ja  va  2  s  .  co m*/
     * @param obj
     * 
     * @return boolean
     * 
     * */
    public static boolean isAttribute(Object obj) {
        boolean ret = false;

        if (null != obj) {
            Class<?> clazz = obj.getClass();

            Annotation annotation = clazz.getAnnotation(XmlAnyAttribute.class);
            if (null != annotation) {
                ret = true;
            }
        }

        return ret;
    }

    /** Checks if the class filed is XML attribute 
     * 
     * @param f
     * 
     * @return boolean
     * 
     * */
    public static boolean isAttribute(Field f) {
        boolean ret = false;

        if (null != f) {
            Annotation annotation = f.getAnnotation(XmlAttribute.class);
            if (null != annotation) {
                ret = true;
            }
        }

        return ret;
    }
}

Related

  1. hasAttributeValue(final Element element, final String attributeName)
  2. hasAttributeValue(Node node, String attributeName, String attributeValue)
  3. hasAttributeValue(String expected, String attribute, Element element)
  4. hasElementWithAttr(Element modsroot, String nodename, String attrname, String attrvalue)
  5. isAttribute(Node node)
  6. isAttributePresent(XMLStreamReader reader, String name)