Java XML Namespace getNamespace(Class klass)

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

Description

get Namespace

License

Open Source License

Declaration

public static String getNamespace(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;

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

    public static String getNamespace(Class<?> klass) {
        String namespace = null;/*  w w w  . j ava2s. c  om*/
        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. getBuilder(boolean ignoreComments, boolean validating, boolean ignoreContentWhitespace, boolean isNamespaceAware)
  2. getCarbonNamespace()
  3. getDefaultNamespaceURI(final XMLStreamWriter writer)
  4. getFactory(boolean validate, boolean namespaceAware)
  5. getNamespace(Class clazz, String namespace)
  6. getNamespace(final Package targetPackage)
  7. getNamespace(Map namespaces, String str, String defaultNamespace)
  8. getNamespaceContext()
  9. getNamespaceContext(final String prefix, final String uri)