Java XML Namespace getPrefix(final Package targetPackage, String namespaceURI)

Here you can find the source of getPrefix(final Package targetPackage, String namespaceURI)

Description

get Prefix

License

Open Source License

Declaration

private static String getPrefix(final Package targetPackage, String namespaceURI) 

Method Source Code


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

import java.util.HashMap;
import java.util.Map;
import javax.xml.bind.annotation.XmlNs;
import javax.xml.bind.annotation.XmlSchema;

public class Main {
    private static String getPrefix(final Package targetPackage, String namespaceURI) {
        String prefix;/*from   w  ww  . j  av  a  2s .com*/
        final Map<String, String> namespacePrefixes = new HashMap<String, String>();
        if (targetPackage != null) {
            final XmlSchema xmlSchemaAnnotation = targetPackage.getAnnotation(XmlSchema.class);
            if (xmlSchemaAnnotation != null) {
                for (XmlNs xmlns : xmlSchemaAnnotation.xmlns()) {
                    namespacePrefixes.put(xmlns.namespaceURI(), xmlns.prefix());
                }
            }
        }

        prefix = namespacePrefixes.get(namespaceURI);
        return prefix;
    }
}

Related

  1. getNamespaceContext(final String prefix, final String uri)
  2. getNamespaceCtx()
  3. getNamespacesForClass(final Class clazz)
  4. getNamespaceURI(Name name)
  5. getPackageNamespace(Class cls)
  6. getPrefixFromNamespaceDeclaration(String namespace)
  7. getRequestMessageType(String intfNamespace, String op, String prefix)
  8. getSchemaNamespace(Package pkg)
  9. getTEINamespaceContext()