Java XML Element Get getElementName(Class claz)

Here you can find the source of getElementName(Class claz)

Description

Returns the element name of the specified class.

License

MIT License

Parameter

Parameter Description
claz the class which has XmlType annotation

Return

the element name of the specified class

Declaration

public static String getElementName(Class<?> claz) 

Method Source Code

//package com.java2s;
/*//from ww  w  .ja  va2  s .  co m
 * Copyright (c) 2014 eSOL Co.,Ltd. and Nagoya University
 *
 * This software is released under the MIT License.
 * http://opensource.org/licenses/mit-license.php
 */

import javax.xml.bind.annotation.XmlType;

public class Main {
    /**
     * Returns the element name of the specified class.
     * 
     * @param claz
     *            the class which has XmlType annotation
     * @return the element name of the specified class
     */
    public static String getElementName(Class<?> claz) {
        try {
            XmlType annotation = claz.getAnnotation(XmlType.class);
            if (annotation.name() != null) {
                return annotation.name();
            }
        } catch (Exception e) {
        }
        return claz.getSimpleName();
    }
}

Related

  1. getElementList(Element dataRoot, String name)
  2. getElementList(Element element)
  3. getElementList(Element element, String name)
  4. getElementList(final Element element)
  5. getElementLocalName(Element element)
  6. getElementName(Class clazz)
  7. getElementName(Element element)
  8. getElementName(Element element)
  9. getElementName(Element element)