Java XML QName Get getQName(Class klass)

Here you can find the source of getQName(Class klass)

Description

get Q Name

License

Open Source License

Declaration

public static QName getQName(Class<?> klass) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import javax.xml.bind.annotation.XmlSchema;
import javax.xml.bind.annotation.XmlType;
import javax.xml.namespace.QName;

public class Main {
    public final static String DEFAULT_NAMESPACE_VALUE = "##default";

    public static QName getQName(Class<?> klass) {
        XmlType xmlType = klass.getAnnotation(XmlType.class);
        if (xmlType == null)
            return null;
        String namespace = getNamespace(klass);
        String name = xmlType.name();
        return new QName(namespace, name);
    }/*from   www. j  a v  a  2  s.c o  m*/

    public static String getNamespace(Class<?> klass) {
        String namespace = null;
        XmlType xmlType = klass.getAnnotation(XmlType.class);
        if (xmlType != null) {
            String ns = xmlType.namespace();
            if (!DEFAULT_NAMESPACE_VALUE.equals(ns)) {
                namespace = ns;
            }
        }
        if (namespace == null) {
            namespace = DEFAULT_NAMESPACE_VALUE;
            Package pkg = klass.getPackage();
            XmlSchema xmlSchema = pkg.getAnnotation(XmlSchema.class);
            if (xmlSchema != null) {
                namespace = xmlSchema.namespace();
            }
        }
        return namespace;
    }
}

Related

  1. getElementQName(final Element el)
  2. getElements(Node context, QName qname)
  3. getName(QName qName)
  4. getName(QName qname)
  5. getQName(@Nonnull final Element aElement)
  6. getQName(Element el)
  7. getQName(Element xml)
  8. getQName(final String name)
  9. getQName(Node n)